From MAILER-DAEMON Mon Oct 01 05:00:46 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TIbro-0003Cn-RW
	for mharc-coreutils@gnu.org; Mon, 01 Oct 2012 05:00:44 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58351)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TIbrh-0002rf-62
	for coreutils@gnu.org; Mon, 01 Oct 2012 05:00:42 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TIbrb-0006uI-Hw
	for coreutils@gnu.org; Mon, 01 Oct 2012 05:00:36 -0400
Received: from mx.meyering.net ([88.168.87.75]:59290)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TIbrb-0006tL-BX
	for coreutils@gnu.org; Mon, 01 Oct 2012 05:00:31 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 1045560432
	for <coreutils@gnu.org>; Mon,  1 Oct 2012 11:00:29 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: coreutils@gnu.org
Subject: sha1sum performance anecdote
Date: Mon, 01 Oct 2012 11:00:29 +0200
Message-ID: <87sj9ysh1u.fsf@rho.meyering.net>
Lines: 6
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 01 Oct 2012 09:00:43 -0000

FYI, I noticed this today on the go IRC channel, #go-nuts:

  [05:14-10/01]<LunixA380:#go-nuts> <shanemhansen> when I use this
              https://github.com/shanemhansen/gocryptodev on arm devices with
              crypto hardware, go can beat coreutils sha1sum and openssl. <<<
              Pretty nice


From MAILER-DAEMON Mon Oct 01 07:20:41 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TIe3F-0000zQ-Uj
	for mharc-coreutils@gnu.org; Mon, 01 Oct 2012 07:20:41 -0400
Received: from eggs.gnu.org ([208.118.235.92]:45719)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TIe33-0000wW-9J
	for coreutils@gnu.org; Mon, 01 Oct 2012 07:20:40 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TIe2t-0008Bv-Lc
	for coreutils@gnu.org; Mon, 01 Oct 2012 07:20:29 -0400
Received: from mx1.redhat.com ([209.132.183.28]:23563)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TIe2t-000889-DI
	for coreutils@gnu.org; Mon, 01 Oct 2012 07:20:19 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q91BKE4H019936
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Mon, 1 Oct 2012 07:20:14 -0400
Received: from [10.36.116.84] (ovpn-116-84.ams2.redhat.com [10.36.116.84])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q91BKAfr029665
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Mon, 1 Oct 2012 07:20:13 -0400
Message-ID: <50697C6A.3040500@draigBrady.com>
Date: Mon, 01 Oct 2012 12:20:10 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: Re: df --output
References: <505BD64C.7020801@bernhard-voelker.de>
	<876277akxo.fsf@rho.meyering.net>
	<505C2A06.2080704@bernhard-voelker.de>
	<87pq5f913w.fsf@rho.meyering.net>
	<505C35C9.1090207@bernhard-voelker.de>
	<505F70E2.9030006@bernhard-voelker.de>
	<87fw68x9qc.fsf@rho.meyering.net>
	<5067682C.6020403@bernhard-voelker.de>
	<506876B9.7000600@bernhard-voelker.de>
In-Reply-To: <506876B9.7000600@bernhard-voelker.de>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q91BKE4H019936
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 01 Oct 2012 11:20:40 -0000

On 09/30/2012 05:43 PM, Bernhard Voelker wrote:
> On 09/29/2012 11:29 PM, Bernhard Voelker wrote:
>> Here you are (see attached):
>>
>> [PATCH 20/20] df: print "total" in grand total's target field if no so=
urce
>> [PATCH 19/20] df: cleanup comments regarding double blank after
>> [PATCH 18/20] df: add a test for the --output option
>> [PATCH 17/20] df: document the new --output option
>> [PATCH 16/20] df: plug two minor memory holes detected by valgrind
>> [PATCH 15/20] df: add new --output option
>> [PATCH 14/20] df: enhance comment describing history
>> [PATCH 13/20] df: give posix_format variable a better scope
>> [PATCH 12/20] df: cleanup header_mode handling regarding --inodes
>> [PATCH 11/20] df: minor cleanup to improve readability
>> [PATCH 10/20] df: remove remainder of pre-mixed fields support
>> [PATCH 09/20] df: add basic support for mixed block and inode fields
>> [PATCH 08/20] df: print '-' into the target column of the total line
>> [PATCH 07/20] df: only sum up grand total if required
>> [PATCH 06/20] df: remove now-obsolescent condition
>> [PATCH 05/20] df: use enum value for long option --total
>> [PATCH 04/20] df: apply ambsalign to the last field with
>> [PATCH 03/20] df: rework internal processing of output columns
>> [PATCH 02/20] df: rename some displayable fields
>> [PATCH 01/20] df: move the call of get_header from get_dev to main
>>
>> The bigger/important changes are in the patches 03, 09, and 15.
>>
>> Example:
>>
>>    $ src/df -h --tot --o=3Dtarget,pcent,ipcent / /home
>>    Mounted on Use% IUse%
>>    /           65%   32%
>>    /home       65%    2%
>>    total       65%    5%
>>
>> Have a nice day,
>> Berny
>
> I have added another patch at the end:
>
>    [PATCH 21/21] df: ensure that the mount list contains a valid
>    fstype with --output
>
>    The function read_file_system_list only ensures a valid file
>    system type if the calling parameter is true. With the new
>    option --output, there is an additional condition needed:
>    when the FSTYPE_FIELD is used.
>
> I didn't notice a problem on GNU/Linux, but the documentation of
> read_file_system_list() leads to the conclusion that df needs to
> pass true also for 'df --o=3Dfstype,...'.
>
> The new, additional condition may also have replaced the one before
>      || print_type
> because
>      || field_data[FSTYPE_FIELD].used
> also leads to true with 'df -T'; I just left it there for now.
>
> Have a nice day,
> Berny
>

Thanks for all this Berny.
I've no time to review yet,
but promise to do so next weekend
or early next week.

cheers,
P=E1draig.


From MAILER-DAEMON Wed Oct 03 09:51:40 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TJPMS-0006jy-It
	for mharc-coreutils@gnu.org; Wed, 03 Oct 2012 09:51:40 -0400
Received: from eggs.gnu.org ([208.118.235.92]:48269)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJPML-0006g2-He
	for coreutils@gnu.org; Wed, 03 Oct 2012 09:51:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJPMH-0007aU-FV
	for coreutils@gnu.org; Wed, 03 Oct 2012 09:51:33 -0400
Received: from cantor2.suse.de ([195.135.220.15]:48258 helo=mx2.suse.de)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJPMG-0007aQ-Vh
	for coreutils@gnu.org; Wed, 03 Oct 2012 09:51:29 -0400
Received: from relay2.suse.de (unknown [195.135.220.254])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx2.suse.de (Postfix) with ESMTP id 51222A2FD7
	for <coreutils@gnu.org>; Wed,  3 Oct 2012 15:51:25 +0200 (CEST)
Date: Wed, 3 Oct 2012 15:51:21 +0200
From: Robert Milasan <rmilasan@suse.com>
To: <coreutils@gnu.org>
Subject: Some question regarding tail and option "-c"
Message-ID: <20121003155121.325b3f88@viper.suse.cz>
Organization: SUSE Linux
X-Mailer: Claws Mail 3.7.10 (GTK+ 2.24.7; x86_64-suse-linux-gnu)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6
X-Received-From: 195.135.220.15
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 03 Oct 2012 13:51:39 -0000

Hello, I think I found an issue, but not sure if it's a bug or
feature :)

When using option "-c" from tail there are 3 ways, two working and one
not:

1. cat /etc/passwd|tail -c 10 (doesn't work)
2. cat /etc/passwd|tail -c -10 (works)
3. tail -c 10 /etc/passwd (works)

Why does the option 2 and 3 work, but the first one doesn't?


-- 
Robert Milasan

L3 Support Engineer
SUSE Linux
email: rmilasan@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A


From MAILER-DAEMON Wed Oct 03 13:19:10 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TJSbG-0001Q2-Ph
	for mharc-coreutils@gnu.org; Wed, 03 Oct 2012 13:19:10 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58758)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TJSbB-0001Ou-7Q
	for coreutils@gnu.org; Wed, 03 Oct 2012 13:19:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TJSb9-0003fi-W9
	for coreutils@gnu.org; Wed, 03 Oct 2012 13:19:05 -0400
Received: from joseki.proulx.com ([216.17.153.58]:44267)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TJSb9-0003fZ-BY
	for coreutils@gnu.org; Wed, 03 Oct 2012 13:19:03 -0400
Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119])
	by joseki.proulx.com (Postfix) with ESMTP id 387C4211D6;
	Wed,  3 Oct 2012 11:19:00 -0600 (MDT)
Received: by hysteria.proulx.com (Postfix, from userid 1000)
	id 009962DC77; Wed,  3 Oct 2012 11:18:59 -0600 (MDT)
Date: Wed, 3 Oct 2012 11:18:59 -0600
From: Bob Proulx <bob@proulx.com>
To: Robert Milasan <rmilasan@suse.com>
Subject: Re: Some question regarding tail and option "-c"
Message-ID: <20121003171859.GA18334@hysteria.proulx.com>
Mail-Followup-To: Robert Milasan <rmilasan@suse.com>, coreutils@gnu.org
References: <20121003155121.325b3f88@viper.suse.cz>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20121003155121.325b3f88@viper.suse.cz>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 216.17.153.58
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 03 Oct 2012 17:19:09 -0000

Robert Milasan wrote:
> Hello, I think I found an issue, but not sure if it's a bug or
> feature :)

That is always the hardest question!  :-)

> When using option "-c" from tail there are 3 ways, two working and one
> not:
> 
> 1. cat /etc/passwd|tail -c 10 (doesn't work)
> 2. cat /etc/passwd|tail -c -10 (works)
> 3. tail -c 10 /etc/passwd (works)
> 
> Why does the option 2 and 3 work, but the first one doesn't?

All three work for me.  But I suspect that the compile time choices on
your system are different and the choices on mine and cause the
program to use a different set of system calls.  Someone else may know
the problem off the top of their head.  Such as not being able to seek
when reading from a pipe.  Which is the usual reason.

What version of tail are you using?

  tail --version

I think the easiest way to see what is happening at run time is to use
strace.  Install it if you don't have it.  Then run:

  cat /etc/passwd | strace -v -o tail.strace tail -c 10

That should produce about a 14K output file with all of the system
calls logged.

Warning: This may contain information that you don't want to share and
these mailing lists are public and archived many public places.  You
should pick something you don't mind sharing for your source material.

Mine says:

  ...
  read(0, "root:x:0:0:root:/root:/bin/bash\n"..., 8192) = 2894
  read(0, "", 8192)                       = 0
  fstat(1, {st_dev=makedev(0, 10), st_ino=9, st_mode=S_IFCHR|0620, st_nlink=1, st_uid=1000, st_gid=5, st_blksize=1024, st_blocks=0, st_rdev=makedev(136, 6), st_atime=2012/10/03-11:11:29, st_mtime=2012/10/03-11:11:29, st_ctime=2012/08/24-17:06:52}) = 0
  mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ff0f7061000
  write(1, "bin/false\n", 10)             = 10
  ...

Bob


From MAILER-DAEMON Wed Oct 03 13:31:22 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TJSn4-0006IJ-DR
	for mharc-coreutils@gnu.org; Wed, 03 Oct 2012 13:31:22 -0400
Received: from eggs.gnu.org ([208.118.235.92]:36806)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJSmz-0006Gc-CE
	for coreutils@gnu.org; Wed, 03 Oct 2012 13:31:21 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJSmy-0000Cl-Dx
	for coreutils@gnu.org; Wed, 03 Oct 2012 13:31:17 -0400
Received: from mx.meyering.net ([88.168.87.75]:39512)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJSmy-0000Bl-6q
	for coreutils@gnu.org; Wed, 03 Oct 2012 13:31:16 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id A9F4160098
	for <coreutils@gnu.org>; Wed,  3 Oct 2012 19:31:14 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: coreutils@gnu.org
Subject: [PATCH] build: remove redundant dependency: $(PROGRAMS):
	lib/libcoreutils.a
Date: Wed, 03 Oct 2012 19:31:14 +0200
Message-ID: <87k3v7fonx.fsf@rho.meyering.net>
Lines: 42
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 03 Oct 2012 17:31:21 -0000

FYI,

While it looks small and "easy", this change was a fix to a
decidedly hard-to-diagnose problem that arose only once I tried
to use a compiled-from-C program to generate a file like primes.h.
Such a program must not depend on libcoreutils.a.  Otherwise all
of lib/*.o would also be among the dependents of $(BUILT_SOURCES),
and there is currently no way to stage the building of those
dependents.  Building them out of order is fatal, usually ending
with link failures due to undefined rpl_* symbols.


>From 852930e88a263bb2e6a6e328dfc7af081637e5cc Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Tue, 18 Sep 2012 21:57:38 +0200
Subject: [PATCH] build: remove redundant dependency: $(PROGRAMS):
 lib/libcoreutils.a

* src/local.mk: Remove the above dependency.
A soon-to-be-added new program, make-prime-list, must not depend
on that, since it is used to create a BUILT_SOURCES file.
That dependency is already handled via the ..._LD_ADD variables,
and so that redundant dependency has so far been harmless.
---
 src/local.mk | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/local.mk b/src/local.mk
index 0f9e000..98259fa 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -293,8 +293,6 @@ src_kill_LDADD += $(LIBTHREAD)
 # for pthread
 src_sort_LDADD += $(LIB_PTHREAD)

-$(PROGRAMS): lib/libcoreutils.a
-
 # Get the release year from lib/version-etc.c.
 RELEASE_YEAR = \
   `sed -n '/.*COPYRIGHT_YEAR = \([0-9][0-9][0-9][0-9]\) };/s//\1/p' \
--
1.8.0.rc0.18.gf84667d


From MAILER-DAEMON Wed Oct 03 14:02:27 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TJTH8-0005VP-Vn
	for mharc-coreutils@gnu.org; Wed, 03 Oct 2012 14:02:26 -0400
Received: from eggs.gnu.org ([208.118.235.92]:55000)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJTH2-0005Nl-UC
	for coreutils@gnu.org; Wed, 03 Oct 2012 14:02:24 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJTGv-0003u9-52
	for coreutils@gnu.org; Wed, 03 Oct 2012 14:02:20 -0400
Received: from cantor2.suse.de ([195.135.220.15]:59145 helo=mx2.suse.de)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJTGu-0003oL-Uw
	for coreutils@gnu.org; Wed, 03 Oct 2012 14:02:13 -0400
Received: from relay1.suse.de (unknown [195.135.220.254])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx2.suse.de (Postfix) with ESMTP id BBE01A2111;
	Wed,  3 Oct 2012 20:02:05 +0200 (CEST)
Date: Wed, 3 Oct 2012 20:01:45 +0200
From: Robert Milasan <rmilasan@suse.com>
To: "Bob Proulx" <bob@proulx.com>
Subject: Re: Some question regarding tail and option "-c"
Message-ID: <20121003200145.3d5a4cd8@coolcat.suse.cz>
In-Reply-To: <20121003171859.GA18334@hysteria.proulx.com>
References: <20121003155121.325b3f88@viper.suse.cz>
	<20121003171859.GA18334@hysteria.proulx.com>
Organization: SUSE Linux
X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-suse-linux-gnu)
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6
X-Received-From: 195.135.220.15
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 03 Oct 2012 18:02:25 -0000

On Wed, 3 Oct 2012 11:18:59 -0600
"Bob Proulx" <bob@proulx.com> wrote:

> What version of tail are you using?
>=20
>   tail --version
>=20
> I think the easiest way to see what is happening at run time is to use
> strace.  Install it if you don't have it.  Then run:
>=20
>   cat /etc/passwd | strace -v -o tail.strace tail -c 10
>=20
> That should produce about a 14K output file with all of the system
> calls logged.
>=20

# tail --version
tail (GNU coreutils) 8.16

# cat /etc/passwd | strace -v -o tail.strace tail -c 10
tail: cannot open =E2=80=9810=E2=80=99 for reading: No such file or directo=
ry


--=20
Robert Milasan

L3 Support Engineer
SUSE Linux
email: rmilasan@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A


From MAILER-DAEMON Wed Oct 03 14:09:31 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TJTNz-00005X-Ht
	for mharc-coreutils@gnu.org; Wed, 03 Oct 2012 14:09:31 -0400
Received: from eggs.gnu.org ([208.118.235.92]:50811)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJTNw-000051-Pp
	for coreutils@gnu.org; Wed, 03 Oct 2012 14:09:29 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJTNv-0006gF-L4
	for coreutils@gnu.org; Wed, 03 Oct 2012 14:09:28 -0400
Received: from mx.meyering.net ([88.168.87.75]:39612)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJTNv-0006g7-DT
	for coreutils@gnu.org; Wed, 03 Oct 2012 14:09:27 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id BA3CE60098;
	Wed,  3 Oct 2012 20:09:26 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Robert Milasan <rmilasan@suse.com>
Subject: Re: Some question regarding tail and option "-c"
In-Reply-To: <20121003200145.3d5a4cd8@coolcat.suse.cz> (Robert Milasan's
	message of "Wed, 3 Oct 2012 20:01:45 +0200")
References: <20121003155121.325b3f88@viper.suse.cz>
	<20121003171859.GA18334@hysteria.proulx.com>
	<20121003200145.3d5a4cd8@coolcat.suse.cz>
Date: Wed, 03 Oct 2012 20:09:26 +0200
Message-ID: <877gr7fmw9.fsf@rho.meyering.net>
Lines: 63
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 03 Oct 2012 18:09:30 -0000

Robert Milasan wrote:

> On Wed, 3 Oct 2012 11:18:59 -0600
> "Bob Proulx" <bob@proulx.com> wrote:
>
>> What version of tail are you using?
>>
>>   tail --version
>>
>> I think the easiest way to see what is happening at run time is to use
>> strace.  Install it if you don't have it.  Then run:
>>
>>   cat /etc/passwd | strace -v -o tail.strace tail -c 10
>>
>> That should produce about a 14K output file with all of the system
>> calls logged.
>>
>
> # tail --version
> tail (GNU coreutils) 8.16
>
> # cat /etc/passwd | strace -v -o tail.strace tail -c 10
> tail: cannot open =E2=80=9810=E2=80=99 for reading: No such file or direc=
tory

I can reproduce that by specifying an older version of POSIX:

    $ : | _POSIX2_VERSION=3D0 tail -c 10
    tail: cannot open '10' for reading: No such file or directory

Depending on how your version of tail was compiled,
that may be the default behavior, or it may be due
to however your _POSIX2_VERSION envvar is set.

There is some documentation on the effects of that variable
in "info coreutils":

    2.13 Standards conformance
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D

    In a few cases, the GNU utilities' default behavior is incompatible
    with the POSIX standard.  To suppress these incompatibilities, define
    the `POSIXLY_CORRECT' environment variable.  Unless you are checking
    for POSIX conformance, you probably do not need to define
    `POSIXLY_CORRECT'.

       Newer versions of POSIX are occasionally incompatible with older
    versions.  For example, older versions of POSIX required the command
    `sort +1' to sort based on the second and succeeding fields in each
    input line, but starting with POSIX 1003.1-2001 the same command is
    required to sort the file named `+1', and you must instead use the
    command `sort -k 2' to get the field-based sort.

       The GNU utilities normally conform to the version of POSIX that is
    standard for your system.  To cause them to conform to a different
    version of POSIX, define the `_POSIX2_VERSION' environment variable to
    a value of the form YYYYMM specifying the year and month the standard
    was adopted.  Three values are currently supported for
    `_POSIX2_VERSION': `199209' stands for POSIX 1003.2-1992, `200112'
    stands for POSIX 1003.1-2001, and `200809' stands for POSIX 1003.1-2008.
    For example, if you have a newer system but are running software that
    assumes an older version of POSIX and uses `sort +1' or `tail +10', you
    can work around any compatibility problems by setting
    `_POSIX2_VERSION=3D199209' in your environment.


From MAILER-DAEMON Thu Oct 04 03:32:58 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TJfvW-00042r-Kb
	for mharc-coreutils@gnu.org; Thu, 04 Oct 2012 03:32:58 -0400
Received: from eggs.gnu.org ([208.118.235.92]:52035)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJfvT-0003zX-Jb
	for coreutils@gnu.org; Thu, 04 Oct 2012 03:32:56 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJfvN-0002TF-Ov
	for coreutils@gnu.org; Thu, 04 Oct 2012 03:32:55 -0400
Received: from cantor2.suse.de ([195.135.220.15]:49194 helo=mx2.suse.de)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJfvN-0002T2-FR
	for coreutils@gnu.org; Thu, 04 Oct 2012 03:32:49 -0400
Received: from relay1.suse.de (unknown [195.135.220.254])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx2.suse.de (Postfix) with ESMTP id 4CDBA9FB23;
	Thu,  4 Oct 2012 09:32:48 +0200 (CEST)
Date: Thu, 4 Oct 2012 09:32:47 +0200
From: Robert Milasan <rmilasan@suse.com>
To: "Jim Meyering" <jim@meyering.net>
Subject: Re: Some question regarding tail and option "-c"
Message-ID: <20121004093247.00eb36fc@viper.suse.cz>
In-Reply-To: <877gr7fmw9.fsf@rho.meyering.net>
References: <20121003155121.325b3f88@viper.suse.cz>
	<20121003171859.GA18334@hysteria.proulx.com>
	<20121003200145.3d5a4cd8@coolcat.suse.cz>
	<877gr7fmw9.fsf@rho.meyering.net>
Organization: SUSE Linux
X-Mailer: Claws Mail 3.7.10 (GTK+ 2.24.7; x86_64-suse-linux-gnu)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6
X-Received-From: 195.135.220.15
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 04 Oct 2012 07:32:56 -0000

On Wed, 03 Oct 2012 20:09:26 +0200
"Jim Meyering" <jim@meyering.net> wrote:

> There is some documentation on the effects of that variable
> in "info coreutils":
> 
>     2.13 Standards conformance
>     ==========================
> 
>     In a few cases, the GNU utilities' default behavior is
> incompatible with the POSIX standard.  To suppress these
> incompatibilities, define the `POSIXLY_CORRECT' environment
> variable.  Unless you are checking for POSIX conformance, you
> probably do not need to define `POSIXLY_CORRECT'.
> 
>        Newer versions of POSIX are occasionally incompatible with
> older versions.  For example, older versions of POSIX required the
> command `sort +1' to sort based on the second and succeeding fields
> in each input line, but starting with POSIX 1003.1-2001 the same
> command is required to sort the file named `+1', and you must instead
> use the command `sort -k 2' to get the field-based sort.
> 
>        The GNU utilities normally conform to the version of POSIX
> that is standard for your system.  To cause them to conform to a
> different version of POSIX, define the `_POSIX2_VERSION' environment
> variable to a value of the form YYYYMM specifying the year and month
> the standard was adopted.  Three values are currently supported for
>     `_POSIX2_VERSION': `199209' stands for POSIX 1003.2-1992, `200112'
>     stands for POSIX 1003.1-2001, and `200809' stands for POSIX
> 1003.1-2008. For example, if you have a newer system but are running
> software that assumes an older version of POSIX and uses `sort +1' or
> `tail +10', you can work around any compatibility problems by setting
>     `_POSIX2_VERSION=199209' in your environment.
> 

This doesn't make sense, I can reproduce this on openSUSE 12.1 and 12.2
with coreutils 8.14 and 8.16.
I don't think we are using some old POSIX standard.

-- 
Robert Milasan

L3 Support Engineer
SUSE Linux
email: rmilasan@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A


From MAILER-DAEMON Thu Oct 04 04:14:26 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TJgZe-0001Ji-0t
	for mharc-coreutils@gnu.org; Thu, 04 Oct 2012 04:14:26 -0400
Received: from eggs.gnu.org ([208.118.235.92]:56518)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJgZZ-0001JV-2A
	for coreutils@gnu.org; Thu, 04 Oct 2012 04:14:25 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJgZU-0008Oi-Q2
	for coreutils@gnu.org; Thu, 04 Oct 2012 04:14:20 -0400
Received: from mx.meyering.net ([88.168.87.75]:41655)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJgZU-0008Ny-IL
	for coreutils@gnu.org; Thu, 04 Oct 2012 04:14:16 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id B81F1600A8;
	Thu,  4 Oct 2012 10:14:15 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Robert Milasan <rmilasan@suse.com>
Subject: Re: Some question regarding tail and option "-c"
In-Reply-To: <20121004093247.00eb36fc@viper.suse.cz> (Robert Milasan's message
	of "Thu, 4 Oct 2012 09:32:47 +0200")
References: <20121003155121.325b3f88@viper.suse.cz>
	<20121003171859.GA18334@hysteria.proulx.com>
	<20121003200145.3d5a4cd8@coolcat.suse.cz>
	<877gr7fmw9.fsf@rho.meyering.net>
	<20121004093247.00eb36fc@viper.suse.cz>
Date: Thu, 04 Oct 2012 10:14:15 +0200
Message-ID: <87k3v6d57s.fsf@rho.meyering.net>
Lines: 52
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 04 Oct 2012 08:14:25 -0000

Robert Milasan wrote:

> On Wed, 03 Oct 2012 20:09:26 +0200
> "Jim Meyering" <jim@meyering.net> wrote:
>
>> There is some documentation on the effects of that variable
>> in "info coreutils":
>>
>>     2.13 Standards conformance
>>     ==========================
>>
>>     In a few cases, the GNU utilities' default behavior is
>> incompatible with the POSIX standard.  To suppress these
>> incompatibilities, define the `POSIXLY_CORRECT' environment
>> variable.  Unless you are checking for POSIX conformance, you
>> probably do not need to define `POSIXLY_CORRECT'.
>>
>>        Newer versions of POSIX are occasionally incompatible with
>> older versions.  For example, older versions of POSIX required the
>> command `sort +1' to sort based on the second and succeeding fields
>> in each input line, but starting with POSIX 1003.1-2001 the same
>> command is required to sort the file named `+1', and you must instead
>> use the command `sort -k 2' to get the field-based sort.
>>
>>        The GNU utilities normally conform to the version of POSIX
>> that is standard for your system.  To cause them to conform to a
>> different version of POSIX, define the `_POSIX2_VERSION' environment
>> variable to a value of the form YYYYMM specifying the year and month
>> the standard was adopted.  Three values are currently supported for
>>     `_POSIX2_VERSION': `199209' stands for POSIX 1003.2-1992, `200112'
>>     stands for POSIX 1003.1-2001, and `200809' stands for POSIX
>> 1003.1-2008. For example, if you have a newer system but are running
>> software that assumes an older version of POSIX and uses `sort +1' or
>> `tail +10', you can work around any compatibility problems by setting
>>     `_POSIX2_VERSION=199209' in your environment.
>
> This doesn't make sense, I can reproduce this on openSUSE 12.1 and 12.2
> with coreutils 8.14 and 8.16.
> I don't think we are using some old POSIX standard.

The "standard for your system" mentioned above is set via definitions
in glibc header files.

You can check by seeing how lib/posixver.c is compiled or by running
a command like the following.  Here's what I see on Fedora 17 and newer:

    $ gcc -x c -dD -E -include unistd.h /dev/null \
      |grep -E 'fine _?_POSIX2_(THIS_)?VERS'
    #define __POSIX2_THIS_VERSION 200809L
    #define _POSIX2_VERSION __POSIX2_THIS_VERSION

When in doubt, you can use gdb to trace through the code, too.


From MAILER-DAEMON Thu Oct 04 04:31:23 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TJgq3-0005s8-D5
	for mharc-coreutils@gnu.org; Thu, 04 Oct 2012 04:31:23 -0400
Received: from eggs.gnu.org ([208.118.235.92]:59957)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJgq1-0005rW-Gu
	for coreutils@gnu.org; Thu, 04 Oct 2012 04:31:22 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJgpv-0006Ht-J1
	for coreutils@gnu.org; Thu, 04 Oct 2012 04:31:21 -0400
Received: from cantor2.suse.de ([195.135.220.15]:51043 helo=mx2.suse.de)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TJgpv-0006Hp-D3
	for coreutils@gnu.org; Thu, 04 Oct 2012 04:31:15 -0400
Received: from relay2.suse.de (unknown [195.135.220.254])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx2.suse.de (Postfix) with ESMTP id 3D43A9FB23;
	Thu,  4 Oct 2012 10:31:14 +0200 (CEST)
Date: Thu, 4 Oct 2012 10:31:12 +0200
From: Robert Milasan <rmilasan@suse.com>
To: "Jim Meyering" <jim@meyering.net>
Subject: Re: Some question regarding tail and option "-c"
Message-ID: <20121004103112.32802a64@viper.suse.cz>
In-Reply-To: <87k3v6d57s.fsf@rho.meyering.net>
References: <20121003155121.325b3f88@viper.suse.cz>
	<20121003171859.GA18334@hysteria.proulx.com>
	<20121003200145.3d5a4cd8@coolcat.suse.cz>
	<877gr7fmw9.fsf@rho.meyering.net>
	<20121004093247.00eb36fc@viper.suse.cz>
	<87k3v6d57s.fsf@rho.meyering.net>
Organization: SUSE Linux
X-Mailer: Claws Mail 3.7.10 (GTK+ 2.24.7; x86_64-suse-linux-gnu)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6
X-Received-From: 195.135.220.15
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 04 Oct 2012 08:31:22 -0000

On Thu, 04 Oct 2012 10:14:15 +0200
"Jim Meyering" <jim@meyering.net> wrote:

> You can check by seeing how lib/posixver.c is compiled or by running
> a command like the following.  Here's what I see on Fedora 17 and
> newer:
> 
>     $ gcc -x c -dD -E -include unistd.h /dev/null \
>       |grep -E 'fine _?_POSIX2_(THIS_)?VERS'
>     #define __POSIX2_THIS_VERSION 200809L
>     #define _POSIX2_VERSION __POSIX2_THIS_VERSION
> 
> When in doubt, you can use gdb to trace through the code, too.
> 

This is the output:

gcc -x c -dD -E -include unistd.h /dev/null |grep -E 'fine_?_POSIX2_(THIS_)?VERS' 
#define __POSIX2_THIS_VERSION 200809L
#define _POSIX2_VERSION __POSIX2_THIS_VERSION


-- 
Robert Milasan

L3 Support Engineer
SUSE Linux
email: rmilasan@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A


From MAILER-DAEMON Thu Oct 04 05:38:40 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TJhtA-0004Oq-Qk
	for mharc-coreutils@gnu.org; Thu, 04 Oct 2012 05:38:40 -0400
Received: from eggs.gnu.org ([208.118.235.92]:44180)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJht4-0004Nq-8f
	for coreutils@gnu.org; Thu, 04 Oct 2012 05:38:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJhsx-0003uS-Ff
	for coreutils@gnu.org; Thu, 04 Oct 2012 05:38:34 -0400
Received: from mx.meyering.net ([88.168.87.75]:41861)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TJhsx-0003uL-8l
	for coreutils@gnu.org; Thu, 04 Oct 2012 05:38:27 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 5A1A8603EA;
	Thu,  4 Oct 2012 11:38:26 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Robert Milasan <rmilasan@suse.com>
Subject: Re: Some question regarding tail and option "-c"
In-Reply-To: <20121004103112.32802a64@viper.suse.cz> (Robert Milasan's message
	of "Thu, 4 Oct 2012 10:31:12 +0200")
References: <20121003155121.325b3f88@viper.suse.cz>
	<20121003171859.GA18334@hysteria.proulx.com>
	<20121003200145.3d5a4cd8@coolcat.suse.cz>
	<877gr7fmw9.fsf@rho.meyering.net>
	<20121004093247.00eb36fc@viper.suse.cz>
	<87k3v6d57s.fsf@rho.meyering.net>
	<20121004103112.32802a64@viper.suse.cz>
Date: Thu, 04 Oct 2012 11:38:26 +0200
Message-ID: <87391ud1bh.fsf@rho.meyering.net>
Lines: 27
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 04 Oct 2012 09:38:39 -0000

Robert Milasan wrote:

> On Thu, 04 Oct 2012 10:14:15 +0200
> "Jim Meyering" <jim@meyering.net> wrote:
>
>> You can check by seeing how lib/posixver.c is compiled or by running
>> a command like the following.  Here's what I see on Fedora 17 and
>> newer:
>>
>>     $ gcc -x c -dD -E -include unistd.h /dev/null \
>>       |grep -E 'fine _?_POSIX2_(THIS_)?VERS'
>>     #define __POSIX2_THIS_VERSION 200809L
>>     #define _POSIX2_VERSION __POSIX2_THIS_VERSION
>>
>> When in doubt, you can use gdb to trace through the code, too.
>>
>
> This is the output:
>
> gcc -x c -dD -E -include unistd.h /dev/null |grep -E 'fine_?_POSIX2_(THIS_)?VERS'
> #define __POSIX2_THIS_VERSION 200809L
> #define _POSIX2_VERSION __POSIX2_THIS_VERSION

I suggest you use gdb to see what the posix2_version function
returns, and why.  Suse may have chosen to build coreutils with the
DEFAULT_POSIX2_VERSION envvar set in such a way that tail's obsolete
behavior is the default.


From MAILER-DAEMON Thu Oct 04 14:02:18 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TJpkY-0000oY-1v
	for mharc-coreutils@gnu.org; Thu, 04 Oct 2012 14:02:18 -0400
Received: from eggs.gnu.org ([208.118.235.92]:56346)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TJpkV-0000fm-1t
	for coreutils@gnu.org; Thu, 04 Oct 2012 14:02:16 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TJpkQ-0005Jh-B7
	for coreutils@gnu.org; Thu, 04 Oct 2012 14:02:14 -0400
Received: from mx1.redhat.com ([209.132.183.28]:7065)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TJpkQ-0005JU-1z
	for coreutils@gnu.org; Thu, 04 Oct 2012 14:02:10 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q94HaBCg024714
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Thu, 4 Oct 2012 13:36:11 -0400
Received: from [10.34.4.104] (unused-4-104.brq.redhat.com [10.34.4.104])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q94Ha98U005381
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Thu, 4 Oct 2012 13:36:10 -0400
Message-ID: <506DC909.1090603@redhat.com>
Date: Thu, 04 Oct 2012 19:36:09 +0200
From: Ondrej Oprala <ooprala@redhat.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:15.0) Gecko/20120911 Thunderbird/15.0.1
MIME-Version: 1.0
To: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: Re: df command should suppress duplicates
References: <502BC320.8080106@redhat.com>
	<502C967C.7070009@bernhard-voelker.de>
In-Reply-To: <502C967C.7070009@bernhard-voelker.de>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 04 Oct 2012 18:02:16 -0000

Hi, I haven't heard from this thread in a while, are there still things 
to be done here?


From MAILER-DAEMON Fri Oct 05 07:43:00 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TK6J2-0001C4-FL
	for mharc-coreutils@gnu.org; Fri, 05 Oct 2012 07:43:00 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49973)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TK3kR-0007XQ-7u
	for coreutils@gnu.org; Fri, 05 Oct 2012 04:59:36 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TK3k1-0005J7-MR
	for coreutils@gnu.org; Fri, 05 Oct 2012 04:59:06 -0400
Received: from mx.meyering.net ([88.168.87.75]:45364)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TK3js-0005GD-VY
	for coreutils@gnu.org; Fri, 05 Oct 2012 04:58:41 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id F00066036E;
	Fri,  5 Oct 2012 10:58:31 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: coreutils@gnu.org
Subject: factor improvements by =?iso-8859-1?Q?Torbj=F6rn?= and Niels: final
	warning
Date: Fri, 05 Oct 2012 10:58:31 +0200
Message-ID: <87haq95m88.fsf@rho.meyering.net>
Lines: 54
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
X-Mailman-Approved-At: Fri, 05 Oct 2012 07:42:58 -0400
Cc: Niels =?iso-8859-1?Q?M=F6ller?= <nisse@lysator.liu.se>,
	Torbjorn Granlund <tg@gmplib.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 05 Oct 2012 08:59:36 -0000

--=-=-=
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

The factor series I've posted here so far have not been bisectable,
and that was a problem.  We must really make an effort to ensure
that any multi-commit series is at least compilable after each commit.
Better still, ensure that the code builds and passes "make check"
or even "make syntax-check" or dist-check.

Here I drew the line at "make check", which does pass after each of
these commits.  "make syntax-check" does not pass for the first few,
but does towards the middle, and of course at the end.

To achieve that, I added the new code in factor-ng.c initially, made
improvements to that file in the series, and towards the end, only once
all new rules and tests were in place did I move factor-ng.c to factor.c.
I've also been careful to list both Niels and Torbj=F6rn as Author:
and in "Co-authored-by: ..." (in commit log) for each of the commits
that they contributed.  Torbj=F6rn, Neils, FYI, those log comments are
automatically converted to ChangeLog entries that list both author names.
That's the ChangeLog that appears in each release tarball.

I will push this later today.
Feedback welcome.

 a/src/factor-ng.c       | 2396 -------------------------------------------=
---
 b/.gitignore            |    6
 b/AUTHORS               |    2
 b/NEWS                  |    7
 b/cfg.mk                |   23
 b/src/.gitignore        |    2
 b/src/factor-ng.c       | 2388 +++++++++++++++++++++++++++++++++++++++++++=
++
 b/src/factor.c          | 2497 ++++++++++++++++++++++++++++++++++++++++++-=
-----
 b/src/local.mk          |   31
 b/src/longlong.h        | 2156 +++++++++++++++++++++++++++++++++++++++++
 b/src/make-prime-list.c |  168 +++
 b/tests/factor/run.sh   |   30
 b/tests/local.mk        |   71 +
 src/factor-ng.c         |  124 +-
 src/factor.c            |    6
 src/longlong.h          |    6
 src/make-prime-list.c   |   30
 src/wheel-gen.pl        |  114 --

Summary:

  [1/8] factor: prepare for the new factor program
  [2/8] maint: make-prime-list: avoid -Wsuggest-attribute=3Dconst
  [3/8] maint: make-prime-list: do not ignore write failure
  [4/8] maint: make-prime-list: syntax conventions; be robust
  [5/8] factor: new much-improved implementation; not yet
  [6/8] factor: more improvements
  [7/8] factor: merge with preexisting factor; integrate tests;
  [8/8] factor: 25% speed-up, on output


--=-=-=
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline; filename=factor-ng.patch
Content-Transfer-Encoding: quoted-printable

>From 1fb5db95aaddc8216449052f11c5da05c8571db5 Mon Sep 17 00:00:00 2001
From: =3D?UTF-8?q?Torbj=3DC3=3DB6rn=3D20Granlund?=3D <tg@gmplib.org>
Date: Sun, 16 Sep 2012 21:59:40 +0200
Subject: [PATCH 1/8] factor: prepare for the new factor program
MIME-Version: 1.0
Content-Type: text/plain; charset=3DUTF-8
Content-Transfer-Encoding: 8bit

* src/make-prime-list.c: New file, from nt-factor.
Co-authored-by: Niels M=F6ller <nisse@lysator.liu.se>
---
 src/make-prime-list.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++=
++++
 1 file changed, 168 insertions(+)
 create mode 100644 src/make-prime-list.c

diff --git a/src/make-prime-list.c b/src/make-prime-list.c
new file mode 100644
index 0000000..1f5b3ce
--- /dev/null
+++ b/src/make-prime-list.c
@@ -0,0 +1,168 @@
+/* Factoring of uintmax_t numbers. Generation of needed tables.
+
+   Contributed to the GNU project by Torbj=F6rn Granlund and Niels M=F6ller
+   Contains code from GNU MP.
+
+Copyright 2012 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify it un=
der
+the terms of the GNU General Public License as published by the Free Softw=
are
+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 WITHOU=
T 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 wi=
th
+this program.  If not, see http://www.gnu.org/licenses/.  */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct prime
+{
+  unsigned p;
+  uintmax_t pinv; /* Inverse mod b =3D 2^{bitsize of uintmax_t} */
+  uintmax_t lim; /* floor(UINTMAX_MAX / p) */
+};
+
+static uintmax_t
+binvert (uintmax_t a)
+{
+  uintmax_t x =3D 0xf5397db1 >> (4*((a/2) & 0x7));
+  for (;;)
+    {
+      uintmax_t y =3D 2*x - x*x*a;
+      if (y =3D=3D x)
+        return x;
+      x =3D y;
+    }
+}
+
+static void
+process_prime (struct prime *info, unsigned p)
+{
+  info->p =3D p;
+  info->pinv =3D binvert (p);
+  info->lim =3D UINTMAX_MAX / (uintmax_t) p;
+}
+
+static void
+output_primes (const struct prime *primes, unsigned nprimes)
+{
+  unsigned i;
+  unsigned p;
+  int is_prime;
+  const char *suffix;
+
+  puts ("/* Generated file -- DO NOT EDIT */\n");
+
+  if (sizeof(uintmax_t) <=3D sizeof(unsigned long))
+    suffix =3D "UL";
+  else if (sizeof(uintmax_t) <=3D sizeof(unsigned long long))
+    suffix =3D "ULL";
+  else
+    {
+      fprintf (stderr, "Don't know how to write uintmax_t constants.\n");
+      exit (EXIT_FAILURE);
+    }
+
+#define SZ (int)(2*sizeof(uintmax_t))
+
+  for (i =3D 0, p =3D 2; i < nprimes; i++)
+    {
+      printf ("P(%2u, %3u, 0x%0*jx%s, 0x%0*jx%s) /* %d */\n",
+              primes[i].p - p,
+              (i + 8 < nprimes) ? primes[i + 8].p - primes[i].p : 0xff,
+              SZ, primes[i].pinv, suffix,
+              SZ, primes[i].lim, suffix, primes[i].p);
+      p =3D primes[i].p;
+    }
+
+  printf ("\n#undef FIRST_OMITTED_PRIME\n");
+
+  /* Find next prime */
+  do
+    {
+      p +=3D 2;
+      for (i =3D 0, is_prime =3D 1; is_prime; i++)
+        {
+          if (primes[i].p * primes[i].p > p)
+            break;
+          if ( (uintmax_t) p * primes[i].pinv <=3D primes[i].lim)
+            {
+              is_prime =3D 0;
+              break;
+            }
+        }
+    }
+  while (!is_prime);
+
+  printf ("#define FIRST_OMITTED_PRIME %d\n", p);
+}
+
+static void *
+xalloc (size_t s)
+{
+  void *p =3D malloc(s);
+  if (p)
+    return p;
+
+  fprintf (stderr, "Virtual memory exhausted.\n");
+  exit (EXIT_FAILURE);
+}
+
+int
+main (int argc, char **argv)
+{
+  int limit;
+
+  char *sieve;
+  size_t size, i;
+
+  struct prime *prime_list;
+  unsigned nprimes;
+
+  if (argc !=3D 2)
+    {
+      fprintf (stderr, "Usage: %s LIMIT\n"
+               "Produces a list of odd primes <=3D LIMIT\n", argv[0]);
+      return EXIT_FAILURE;
+    }
+  limit =3D atoi(argv[1]);
+  if (limit < 3)
+    exit (EXIT_SUCCESS);
+
+  /* Make limit odd */
+  if ( !(limit & 1))
+    limit--;
+
+  size =3D (limit-1)/2;
+  /* sieve[i] represents 3+2*i */
+  sieve =3D xalloc (size);
+  memset (sieve, 1, size);
+
+  prime_list =3D xalloc (size * sizeof (*prime_list));
+  nprimes =3D 0;
+
+  for (i =3D 0; i < size;)
+    {
+      unsigned p =3D 3+2*i;
+      unsigned j;
+
+      process_prime (&prime_list[nprimes++], p);
+
+      for (j =3D (p*p - 3)/2; j < size; j+=3D p)
+        sieve[j] =3D 0;
+
+      while (i < size && sieve[++i] =3D=3D 0)
+        ;
+    }
+
+  output_primes (prime_list, nprimes);
+
+  return EXIT_SUCCESS;
+}
--=20
1.8.0.rc0.18.gf84667d


>From cf67e4cc9025ce921230b821cb7e75bce06876cd Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Wed, 19 Sep 2012 11:07:41 +0200
Subject: [PATCH 2/8] maint: make-prime-list: avoid -Wsuggest-attribute=3Dco=
nst
 warning

* src/make-prime-list.c: Include <config.h>.
(binvert): Add _GL_ATTRIBUTE_CONST.
---
 src/make-prime-list.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/make-prime-list.c b/src/make-prime-list.c
index 1f5b3ce..724924b 100644
--- a/src/make-prime-list.c
+++ b/src/make-prime-list.c
@@ -17,6 +17,8 @@ PARTICULAR PURPOSE.  See the GNU General Public License f=
or more details.
 You should have received a copy of the GNU General Public License along wi=
th
 this program.  If not, see http://www.gnu.org/licenses/.  */

+#include <config.h>
+
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
@@ -29,7 +31,7 @@ struct prime
   uintmax_t lim; /* floor(UINTMAX_MAX / p) */
 };

-static uintmax_t
+static uintmax_t _GL_ATTRIBUTE_CONST
 binvert (uintmax_t a)
 {
   uintmax_t x =3D 0xf5397db1 >> (4*((a/2) & 0x7));
--=20
1.8.0.rc0.18.gf84667d


>From c6369e9004be56d427f0cc0d51d7009d727e061c Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Sun, 23 Sep 2012 11:33:01 +0200
Subject: [PATCH 3/8] maint: make-prime-list: do not ignore write failure

Even though this is just a helper program that is run solely to create
primes.h, it should not ignore a write failure.  Normally we would
simply call atexit (close_stdout), but we cannot do that from this
helper program, since it must be built before the generated header,
primes.h.  If we were to make the linking of make-prime-list depend
on libcoreutils.a, that would add all lib/*.o files to the list
of dependents of $(BUILT_HEADERS).  Then, since there is currently no
provision to ensure that a file like lib/stdio.h (another built header)
is built before the first lib/*.o file that also includes <stdio.h>,
some lib/*.o files would be built before lib/stdio.h and some after.
The former would provoke link failures due to undefined rpl_* functions.
* src/make-prime-list.c: Include <errno.h>.
(fclose): Undef, so that a definition to rpl_fclose does not
cause a link failure.
(main): Per the above, in this exceptional case, we check for fclose
and ferror failure manually, and don't worry about the ferror-only
failure case in which errno may not be relevant.
---
 src/make-prime-list.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/make-prime-list.c b/src/make-prime-list.c
index 724924b..b18b0e5 100644
--- a/src/make-prime-list.c
+++ b/src/make-prime-list.c
@@ -23,6 +23,8 @@ this program.  If not, see http://www.gnu.org/licenses/. =
 */
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <errno.h>
+#undef fclose

 struct prime
 {
@@ -166,5 +168,11 @@ main (int argc, char **argv)

   output_primes (prime_list, nprimes);

+  if (ferror (stdout) + fclose (stdout))
+    {
+      fprintf (stderr, "write error: %s\n", strerror (errno));
+      return EXIT_FAILURE;
+    }
+
   return EXIT_SUCCESS;
 }
--=20
1.8.0.rc0.18.gf84667d


>From d836ea73400d66ecfa5ecf1287b983976342c4c4 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Thu, 4 Oct 2012 20:27:31 +0200
Subject: [PATCH 4/8] maint: make-prime-list: syntax conventions; be robust
 for large N

* src/make-prime-list.c: Insert spaces before parens.
(main): Abort if the 8-delta value ever exceeds 255.
---
 src/make-prime-list.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/make-prime-list.c b/src/make-prime-list.c
index b18b0e5..49db2ba 100644
--- a/src/make-prime-list.c
+++ b/src/make-prime-list.c
@@ -64,9 +64,9 @@ output_primes (const struct prime *primes, unsigned nprim=
es)

   puts ("/* Generated file -- DO NOT EDIT */\n");

-  if (sizeof(uintmax_t) <=3D sizeof(unsigned long))
+  if (sizeof (uintmax_t) <=3D sizeof (unsigned long))
     suffix =3D "UL";
-  else if (sizeof(uintmax_t) <=3D sizeof(unsigned long long))
+  else if (sizeof (uintmax_t) <=3D sizeof (unsigned long long))
     suffix =3D "ULL";
   else
     {
@@ -74,13 +74,15 @@ output_primes (const struct prime *primes, unsigned npr=
imes)
       exit (EXIT_FAILURE);
     }

-#define SZ (int)(2*sizeof(uintmax_t))
+#define SZ (int)(2*sizeof (uintmax_t))

   for (i =3D 0, p =3D 2; i < nprimes; i++)
     {
-      printf ("P(%2u, %3u, 0x%0*jx%s, 0x%0*jx%s) /* %d */\n",
-              primes[i].p - p,
-              (i + 8 < nprimes) ? primes[i + 8].p - primes[i].p : 0xff,
+      unsigned int d8 =3D i + 8 < nprimes ? primes[i + 8].p - primes[i].p =
: 0xff;
+      if (255 < d8) /* this happens at 668221 */
+        abort ();
+      printf ("P (%2u, %3u, 0x%0*jx%s, 0x%0*jx%s) /* %d */\n",
+              primes[i].p - p, d8,
               SZ, primes[i].pinv, suffix,
               SZ, primes[i].lim, suffix, primes[i].p);
       p =3D primes[i].p;
@@ -111,7 +113,7 @@ output_primes (const struct prime *primes, unsigned npr=
imes)
 static void *
 xalloc (size_t s)
 {
-  void *p =3D malloc(s);
+  void *p =3D malloc (s);
   if (p)
     return p;

@@ -136,7 +138,7 @@ main (int argc, char **argv)
                "Produces a list of odd primes <=3D LIMIT\n", argv[0]);
       return EXIT_FAILURE;
     }
-  limit =3D atoi(argv[1]);
+  limit =3D atoi (argv[1]);
   if (limit < 3)
     exit (EXIT_SUCCESS);

--=20
1.8.0.rc0.18.gf84667d


>From a38890b27fe296c582d1266cb5b3b02f186132dc Mon Sep 17 00:00:00 2001
From: =3D?UTF-8?q?Torbj=3DC3=3DB6rn=3D20Granlund?=3D <tg@gmplib.org>
Date: Sun, 16 Sep 2012 22:27:20 +0200
Subject: [PATCH 5/8] factor: new much-improved implementation; not yet
 integrated
MIME-Version: 1.0
Content-Type: text/plain; charset=3DUTF-8
Content-Transfer-Encoding: 8bit

* src/factor-ng.c: New file, from nt-factor.
* src/longlong.h: New file.
* NEWS (Improvements): Mention the upcoming improvements.
Co-authored-by: Niels M=F6ller
---
 NEWS            |    7 +
 src/factor-ng.c | 2388 +++++++++++++++++++++++++++++++++++++++++++++++++++=
++++
 src/longlong.h  | 2156 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 4551 insertions(+)
 create mode 100644 src/factor-ng.c
 create mode 100644 src/longlong.h

diff --git a/NEWS b/NEWS
index 25f1a27..aff5bf1 100644
--- a/NEWS
+++ b/NEWS
@@ -50,6 +50,13 @@ GNU coreutils NEWS                                    -*=
- outline -*-

 ** Improvements

+  factor's core has been rewritten for speed and increased range.
+  It can now factor numbers up to 2^128, even without GMP support.
+  Its speed is from a few times better (for small numbers) to over
+  10,000 times better (just below 2^64).  The new code also runs a
+  deterministic primality test for each prime factor, not just a
+  probabilistic test.
+
   seq is now up to 70 times faster than it was in coreutils-8.19 and prior,
   but only with non-negative whole numbers, an increment of 1, and no
   format-changing options.
diff --git a/src/factor-ng.c b/src/factor-ng.c
new file mode 100644
index 0000000..776aaa6
--- /dev/null
+++ b/src/factor-ng.c
@@ -0,0 +1,2388 @@
+/* Factoring of uintmax_t numbers.
+
+   Contributed to the GNU project by Torbj=F6rn Granlund and Niels M=F6ller
+   Contains code from GNU MP.
+
+Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2009, 2012
+Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify it un=
der
+the terms of the GNU General Public License as published by the Free Softw=
are
+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 WITHOU=
T 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 wi=
th
+this program.  If not, see http://www.gnu.org/licenses/.  */
+
+/* Efficiently factor numbers that fit in one or two words (word =3D uintm=
ax_t),
+   or, with GMP, numbers of any size.
+
+  Code organisation:
+
+    There are several variants of many functions, for handling one word, t=
wo
+    words, and GMP's mpz_t type.  If the one-word variant is called foo, t=
he
+    two-word variant will be foo2, and the one for mpz_t will be mp_foo.  =
In
+    some cases, the plain function variants will handle both one-word and
+    two-word numbers, evidenced by function arguments.
+
+    The factoring code for two words will fall into the code for one word =
when
+    progress allows that.
+
+    Using GMP is optional.  Define HAVE_GMP to make this code include GMP
+    factoring code.  The GMP factoring code is based on GMP's demos/factor=
ize.c
+    (last synched 2012-09-07).  The GMP-based factoring code will stay in =
GMP
+    factoring code even if numbers get small enough for using the two-word
+    code.
+
+  Algorithm:
+
+    (1) Perform trial division using a small primes table, but without har=
dware
+        division since the primes table store inverses modulo the word bas=
e.
+        (The GMP variant of this code doesn't make use of the precomputed
+        inverses, but instead relies on GMP for fast divisibility testing.)
+    (2) Check the nature of any non-factored part using Miller-Rabin for
+        detecting composites, and Lucas for detecting primes.
+    (3) Factor any remaining composite part using the Pollard-Brent rho
+        algorithm or the SQUFOF algorithm, checking status of found factors
+        again using Miller-Rabin and Lucas.
+
+    We prefer using Hensel norm in the divisions, not the more familiar
+    Euclidian norm, since the former leads to much faster code.  In the
+    Pollard-Brent rho code and the the prime testing code, we use Montgome=
ry's
+    trick of multiplying all n-residues by the word base, allowing cheap H=
ensel
+    reductions mod n.
+
+  Improvements:
+
+    * Use modular inverses also for exact division in the Lucas code, and
+      elsewhere.  A problem is to locate the inverses not from an index, b=
ut
+      from a prime.  We might instead compute the inverse on-the-fly.
+
+    * Tune trial division table size (not forgetting that this is a standa=
lone
+      program where the table will be read from disk for each invocation).
+
+    * Implement less naive powm, using k-ary exponentiation for k =3D 3 or
+      perhaps k =3D 4.
+
+    * Try to speed trial division code for single uintmax_t numbers, i.e.,=
 the
+      code using DIVBLOCK.  It currently runs at 2 cycles per prime (Intel=
 SBR,
+      IBR), 3 cycles per prime (AMD Stars) and 5 cycles per prime (AMD BD)=
 when
+      using gcc 4.6 and 4.7.  Some software pipelining should help; 1, 2, =
and 4
+      respectively cycles ought to be possible.
+
+    * The redcify function could be vastly improved by using (plain Euclid=
ian)
+      pre-inversion (such as GMP's invert_limb) and udiv_qrnnd_preinv (from
+      GMP's gmp-impl.h).  The redcify2 function could be vastly improved u=
sing
+      similar methoods.  These functions currently dominate run time when =
using
+      the -w option.
+*/
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <assert.h>
+#include <ctype.h>
+#include <string.h>             /* for memmove */
+#include <unistd.h>             /* for getopt */
+#include <stdbool.h>
+
+#include "system.h"
+
+#if HAVE_GMP
+# include <gmp.h>
+#endif
+
+#ifndef STAT_SQUFOF
+# define STAT_SQUFOF 0
+#endif
+
+#ifndef USE_LONGLONG_H
+# define USE_LONGLONG_H 1
+#endif
+
+#if USE_LONGLONG_H
+
+/* Make definitions for longlong.h to make it do what it can do for us */
+# define W_TYPE_SIZE 64          /* bitcount for uintmax_t */
+# define UWtype  uintmax_t
+# define UHWtype unsigned long int
+# undef UDWtype
+# if HAVE_ATTRIBUTE_MODE
+typedef unsigned int UQItype    __attribute__ ((mode (QI)));
+typedef          int SItype     __attribute__ ((mode (SI)));
+typedef unsigned int USItype    __attribute__ ((mode (SI)));
+typedef          int DItype     __attribute__ ((mode (DI)));
+typedef unsigned int UDItype    __attribute__ ((mode (DI)));
+# else
+typedef unsigned char UQItype;
+typedef          long SItype;
+typedef unsigned long int USItype;
+#  if HAVE_LONG_LONG
+typedef long long int DItype;
+typedef unsigned long long int UDItype;
+#  else /* Assume `long' gives us a wide enough type.  Needed for hppa2.0w=
.  */
+typedef long int DItype;
+typedef unsigned long int UDItype;
+#  endif
+# endif
+# define LONGLONG_STANDALONE     /* Don't require GMP's longlong.h mdep fi=
les */
+# define ASSERT(x)               /* FIXME make longlong.h really standalon=
e */
+# define __GMP_DECLSPEC          /* FIXME make longlong.h really standalon=
e */
+# define __clz_tab factor_clz_tab /* Rename to avoid glibc collision */
+# ifndef __GMP_GNUC_PREREQ
+#  define __GMP_GNUC_PREREQ(a,b) 1
+# endif
+# if _ARCH_PPC
+#  define HAVE_HOST_CPU_FAMILY_powerpc 1
+# endif
+# include "longlong.h"
+# ifdef COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+const unsigned char factor_clz_tab[129] =3D
+{
+  1,2,3,3,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+  9
+};
+# endif
+
+#else /* not USE_LONGLONG_H */
+
+# define W_TYPE_SIZE (8 * sizeof (uintmax_t))
+# define __ll_B ((uintmax_t) 1 << (W_TYPE_SIZE / 2))
+# define __ll_lowpart(t)  ((uintmax_t) (t) & (__ll_B - 1))
+# define __ll_highpart(t) ((uintmax_t) (t) >> (W_TYPE_SIZE / 2))
+
+#endif
+
+enum alg_type { ALG_POLLARD_RHO =3D 1, ALG_SQUFOF =3D 2 };
+
+static enum alg_type alg;
+
+/* 2*3*5*7*11...*101 is 128 bits, and has 26 prime factors */
+#define MAX_NFACTS 26
+
+struct factors
+{
+  uintmax_t     plarge[2]; /* Can have a single large factor */
+  uintmax_t     p[MAX_NFACTS];
+  unsigned char e[MAX_NFACTS];
+  unsigned char nfactors;
+};
+
+#if HAVE_GMP
+struct mp_factors
+{
+  mpz_t         *p;
+  unsigned long int *e;
+  unsigned long int nfactors;
+};
+#endif
+
+static void factor (uintmax_t, uintmax_t, struct factors *);
+
+#ifndef umul_ppmm
+# define umul_ppmm(w1, w0, u, v)                                         \
+  do {                                                                  \
+    uintmax_t __x0, __x1, __x2, __x3;                                   \
+    unsigned long int __ul, __vl, __uh, __vh;                           \
+    uintmax_t __u =3D (u), __v =3D (v);                                   =
  \
+                                                                        \
+    __ul =3D __ll_lowpart (__u);                                          \
+    __uh =3D __ll_highpart (__u);                                         \
+    __vl =3D __ll_lowpart (__v);                                          \
+    __vh =3D __ll_highpart (__v);                                         \
+                                                                        \
+    __x0 =3D (uintmax_t) __ul * __vl;                                     \
+    __x1 =3D (uintmax_t) __ul * __vh;                                     \
+    __x2 =3D (uintmax_t) __uh * __vl;                                     \
+    __x3 =3D (uintmax_t) __uh * __vh;                                     \
+                                                                        \
+    __x1 +=3D __ll_highpart (__x0);/* this can't give carry */            \
+    __x1 +=3D __x2;               /* but this indeed can */               \
+    if (__x1 < __x2)            /* did we get it? */                    \
+      __x3 +=3D __ll_B;           /* yes, add it in the proper pos. */    \
+                                                                        \
+    (w1) =3D __x3 + __ll_highpart (__x1);                                 \
+    (w0) =3D (__x1 << W_TYPE_SIZE / 2) + __ll_lowpart (__x0);             \
+  } while (0)
+#endif
+
+#if !defined(udiv_qrnnd) || defined(UDIV_NEEDS_NORMALIZATION)
+/* Define our own, not needing normalization. This function is
+   currently not performance critical, so keep it simple. Similar to
+   the mod macro below. */
+# undef udiv_qrnnd
+# define udiv_qrnnd(q, r, n1, n0, d)                                     \
+  do {                                                                  \
+    uintmax_t __d1, __d0, __q, __r1, __r0;                              \
+                                                                        \
+    assert ((n1) < (d));                                                \
+    __d1 =3D (d); __d0 =3D 0;                                             =
  \
+    __r1 =3D (n1); __r0 =3D (n0);                                         =
  \
+    __q =3D 0;                                                            \
+    for (unsigned int __i =3D W_TYPE_SIZE; __i > 0; __i--)                \
+      {                                                                 \
+        rsh2 (__d1, __d0, __d1, __d0, 1);                               \
+        __q <<=3D 1;                                                      \
+        if (ge2 (__r1, __r0, __d1, __d0))                               \
+          {                                                             \
+            __q++;                                                      \
+            sub_ddmmss (__r1, __r0, __r1, __r0, __d1, __d0);            \
+          }                                                             \
+      }                                                                 \
+    (r) =3D __r0;                                                         \
+    (q) =3D __q;                                                          \
+  } while (0)
+#endif
+
+#if !defined (add_ssaaaa)
+# define add_ssaaaa(sh, sl, ah, al, bh, bl)                              \
+  do {                                                                  \
+    uintmax_t _add_x;                                                   \
+    _add_x =3D (al) + (bl);                                               \
+    (sh) =3D (ah) + (bh) + (_add_x < (al));                               \
+    (sl) =3D _add_x;                                                      \
+  } while (0)
+#endif
+
+#define rsh2(rh, rl, ah, al, cnt)                                       \
+  do {                                                                  \
+    (rl) =3D ((ah) << (W_TYPE_SIZE - (cnt))) | ((al) >> (cnt));           \
+    (rh) =3D (ah) >> (cnt);                                               \
+  } while (0)
+
+#define lsh2(rh, rl, ah, al, cnt)                                       \
+  do {                                                                  \
+    (rh) =3D ((ah) << cnt) | ((al) >> (W_TYPE_SIZE - (cnt)));             \
+    (rl) =3D (al) << (cnt);                                               \
+  } while (0)
+
+#define ge2(ah, al, bh, bl)                                             \
+  ((ah) > (bh) || ((ah) =3D=3D (bh) && (al) >=3D (bl)))
+
+#define gt2(ah, al, bh, bl)                                             \
+  ((ah) > (bh) || ((ah) =3D=3D (bh) && (al) > (bl)))
+
+#ifndef sub_ddmmss
+# define sub_ddmmss(rh, rl, ah, al, bh, bl)                              \
+  do {                                                                  \
+    uintmax_t _cy;                                                      \
+    _cy =3D (al) < (bl);                                                  \
+    (rl) =3D (al) - (bl);                                                 \
+    (rh) =3D (ah) - (bh) - _cy;                                           \
+  } while (0)
+#endif
+
+#ifndef count_leading_zeros
+# define count_leading_zeros(count, x) do {                              \
+    uintmax_t __clz_x =3D (x);                                            \
+    unsigned int __clz_c;                                               \
+    for (__clz_c =3D 0;                                                   \
+         (__clz_x & ((uintmax_t) 0xff << (W_TYPE_SIZE - 8))) =3D=3D 0;    =
  \
+         __clz_c +=3D 8)                                                  \
+      __clz_x <<=3D 8;                                                    \
+    for (; (intmax_t)__clz_x >=3D 0; __clz_c++)                           \
+      __clz_x <<=3D 1;                                                    \
+    (count) =3D __clz_c;                                                  \
+  } while (0)
+#endif
+
+#ifndef count_trailing_zeros
+# define count_trailing_zeros(count, x) do {                             \
+    uintmax_t __ctz_x =3D (x);                                            \
+    unsigned int __ctz_c =3D 0;                                           \
+    while ((__ctz_x & 1) =3D=3D 0)                                        =
  \
+      {                                                                 \
+        __ctz_x >>=3D 1;                                                  \
+        __ctz_c++;                                                      \
+      }                                                                 \
+    (count) =3D __ctz_c;                                                  \
+  } while (0)
+#endif
+
+/* Requires that a < n and b <=3D n */
+#define submod(r,a,b,n)                                                 \
+  do {                                                                  \
+    uintmax_t _t =3D - (uintmax_t) (a < b);                               \
+    (r) =3D ((n) & _t) + (a) - (b);                                       \
+  } while (0)
+
+#define addmod(r,a,b,n)                                                 \
+  submod((r), (a), ((n) - (b)), (n))
+
+/* Modular two-word addition and subtraction.  For performance reasons, the
+   most significant bit of n1 must be clear.  The destination variables mu=
st be
+   distinct from the mod operand.  */
+#define addmod2(r1, r0, a1, a0, b1, b0, n1, n0)                         \
+  do {                                                                  \
+    add_ssaaaa ((r1), (r0), (a1), (a0), (b1), (b0));                    \
+    if (ge2 ((r1), (r0), (n1), (n0)))                                   \
+      sub_ddmmss ((r1), (r0), (r1), (r0), (n1), (n0));                  \
+  } while (0)
+#define submod2(r1, r0, a1, a0, b1, b0, n1, n0)                         \
+  do {                                                                  \
+    sub_ddmmss ((r1), (r0), (a1), (a0), (b1), (b0));                    \
+    if ((intmax_t) (r1) < 0)                                            \
+      add_ssaaaa ((r1), (r0), (r1), (r0), (n1), (n0));                  \
+  } while (0)
+
+#define HIGHBIT_TO_MASK(x)                                              \
+  (((intmax_t)-1 >> 1) < 0                                              \
+   ? (uintmax_t)((intmax_t)(x) >> (W_TYPE_SIZE - 1))                    \
+   : ((x) & ((uintmax_t) 1 << (W_TYPE_SIZE - 1))                        \
+      ? UINTMAX_MAX : (uintmax_t) 0))
+
+/* Compute r =3D a mod d, where r =3D <*t1,retval>, a =3D <a1,a0>, d =3D <=
d1,d0>.
+   Requires that d1 !=3D 0.  */
+static uintmax_t
+mod2 (uintmax_t *r1, uintmax_t a1, uintmax_t a0, uintmax_t d1, uintmax_t d=
0)
+{
+  int cntd, cnta;
+
+  assert (d1 !=3D 0);
+
+  if (a1 =3D=3D 0)
+    {
+      *r1 =3D 0;
+      return a0;
+    }
+
+  count_leading_zeros (cntd, d1);
+  count_leading_zeros (cnta, a1);
+  int cnt =3D cntd - cnta;
+  lsh2 (d1, d0, d1, d0, cnt);
+  for (int i =3D 0; i < cnt; i++)
+    {
+      if (ge2 (a1, a0, d1, d0))
+        sub_ddmmss (a1, a0, a1, a0, d1, d0);
+      rsh2 (d1, d0, d1, d0, 1);
+    }
+
+  *r1 =3D a1;
+  return a0;
+}
+
+static uintmax_t _GL_ATTRIBUTE_CONST
+gcd_odd (uintmax_t a, uintmax_t b)
+{
+  if ( (b & 1) =3D=3D 0)
+    {
+      uintmax_t t =3D b;
+      b =3D a;
+      a =3D t;
+    }
+  if (a =3D=3D 0)
+    return b;
+
+  /* Take out least significant one bit, to make room for sign */
+  b >>=3D 1;
+
+  for (;;)
+    {
+      uintmax_t t;
+      uintmax_t bgta;
+
+      while ((a & 1) =3D=3D 0)
+        a >>=3D 1;
+      a >>=3D 1;
+
+      t =3D a - b;
+      if (t =3D=3D 0)
+        return (a << 1) + 1;
+
+      bgta =3D HIGHBIT_TO_MASK (t);
+
+      /* b <-- min (a, b) */
+      b +=3D (bgta & t);
+
+      /* a <-- |a - b| */
+      a =3D (t ^ bgta) - bgta;
+    }
+}
+
+static uintmax_t
+gcd2_odd (uintmax_t *r1, uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax=
_t b0)
+{
+  while ((a0 & 1) =3D=3D 0)
+    rsh2 (a1, a0, a1, a0, 1);
+  while ((b0 & 1) =3D=3D 0)
+    rsh2 (b1, b0, b1, b0, 1);
+
+  for (;;)
+    {
+      if ((b1 | a1) =3D=3D 0)
+        {
+          *r1 =3D 0;
+          return gcd_odd (b0, a0);
+        }
+
+      if (gt2 (a1, a0, b1, b0))
+        {
+          sub_ddmmss (a1, a0, a1, a0, b1, b0);
+          do
+            rsh2 (a1, a0, a1, a0, 1);
+          while ((a0 & 1) =3D=3D 0);
+        }
+      else if (gt2 (b1, b0, a1, a0))
+        {
+          sub_ddmmss (b1, b0, b1, b0, a1, a0);
+          do
+            rsh2 (b1, b0, b1, b0, 1);
+          while ((b0 & 1) =3D=3D 0);
+        }
+      else
+        break;
+    }
+
+  *r1 =3D a1;
+  return a0;
+}
+
+static void
+factor_insert_multiplicity (struct factors *factors,
+                            uintmax_t prime, unsigned int m)
+{
+  unsigned int nfactors =3D factors->nfactors;
+  uintmax_t *p =3D factors->p;
+  unsigned char *e =3D factors->e;
+
+  /* Locate position for insert new or increment e.  */
+  int i;
+  for (i =3D nfactors - 1; i >=3D 0; i--)
+    {
+      if (p[i] <=3D prime)
+        break;
+    }
+
+  if (i < 0 || p[i] !=3D prime)
+    {
+      for (int j =3D nfactors - 1; j > i; j--)
+        {
+          p[j + 1] =3D p[j];
+          e[j + 1] =3D e[j];
+        }
+      p[i + 1] =3D prime;
+      e[i + 1] =3D m;
+      factors->nfactors =3D nfactors + 1;
+    }
+  else
+    {
+      e[i] +=3D m;
+    }
+}
+
+#define factor_insert(f, p) factor_insert_multiplicity(f, p, 1)
+
+static void
+factor_insert_large (struct factors *factors,
+                     uintmax_t p1, uintmax_t p0)
+{
+  if (p1 > 0)
+    {
+      assert (factors->plarge[1] =3D=3D 0);
+      factors->plarge[0] =3D p0;
+      factors->plarge[1] =3D p1;
+    }
+  else
+    factor_insert (factors, p0);
+}
+
+#if HAVE_GMP
+static void mp_factor (mpz_t, struct mp_factors *);
+
+static void
+mp_factor_init (struct mp_factors *factors)
+{
+  factors->p =3D malloc (1);
+  factors->e =3D malloc (1);
+  factors->nfactors =3D 0;
+}
+
+static void
+mp_factor_clear (struct mp_factors *factors)
+{
+  for (unsigned int i =3D 0; i < factors->nfactors; i++)
+    mpz_clear (factors->p[i]);
+
+  free (factors->p);
+  free (factors->e);
+}
+
+static void
+mp_factor_insert (struct mp_factors *factors, mpz_t prime)
+{
+  unsigned long int nfactors =3D factors->nfactors;
+  mpz_t         *p  =3D factors->p;
+  unsigned long int *e  =3D factors->e;
+  long i;
+
+  /* Locate position for insert new or increment e.  */
+  for (i =3D nfactors - 1; i >=3D 0; i--)
+    {
+      if (mpz_cmp (p[i], prime) <=3D 0)
+        break;
+    }
+
+  if (i < 0 || mpz_cmp (p[i], prime) !=3D 0)
+    {
+      p =3D realloc (p, (nfactors + 1) * sizeof p[0]);
+      e =3D realloc (e, (nfactors + 1) * sizeof e[0]);
+
+      mpz_init (p[nfactors]);
+      for (long j =3D nfactors - 1; j > i; j--)
+        {
+          mpz_set (p[j + 1], p[j]);
+          e[j + 1] =3D e[j];
+        }
+      mpz_set (p[i + 1], prime);
+      e[i + 1] =3D 1;
+
+      factors->p =3D p;
+      factors->e =3D e;
+      factors->nfactors =3D nfactors + 1;
+    }
+  else
+    {
+      e[i] +=3D 1;
+    }
+}
+
+static void
+mp_factor_insert_ui (struct mp_factors *factors, unsigned long int prime)
+{
+  mpz_t pz;
+
+  mpz_init_set_ui (pz, prime);
+  mp_factor_insert (factors, pz);
+  mpz_clear (pz);
+}
+#endif /* HAVE_GMP */
+
+
+#define P(a,b,c,d) a,
+static const unsigned char primes_diff[] =3D {
+#include "primes.h"
+0,0,0,0,0,0,0                           /* 7 sentinels for 8-way loop */
+};
+#undef P
+
+#define PRIMES_PTAB_ENTRIES (sizeof(primes_diff) / sizeof(primes_diff[0]) =
- 8 + 1)
+
+#define P(a,b,c,d) b,
+static const unsigned char primes_diff8[] =3D {
+#include "primes.h"
+0,0,0,0,0,0,0                           /* 7 sentinels for 8-way loop */
+};
+#undef P
+
+struct primes_dtab
+{
+  uintmax_t binv, lim;
+};
+
+#define P(a,b,c,d) {c,d},
+static const struct primes_dtab primes_dtab[] =3D {
+#include "primes.h"
+{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0} /* 7 sentinels for 8-way loop */
+};
+#undef P
+
+/* This flag is honoured just in the GMP code. */
+static int flag_verbose =3D 0;
+
+/* Prove primality or run probabilistic tests.  */
+static int flag_prove_primality =3D 1;
+
+/* Number of Miller-Rabin tests to run when not proving primality. */
+#define MR_REPS 25
+
+#define LIKELY(cond)    __builtin_expect ((cond) !=3D 0, 1)
+#define UNLIKELY(cond)  __builtin_expect ((cond) !=3D 0, 0)
+
+static void
+factor_insert_refind (struct factors *factors, uintmax_t p, unsigned int i,
+                      unsigned int off)
+{
+  for (unsigned int j =3D 0; j < off; j++)
+    p +=3D primes_diff[i + j];
+  factor_insert (factors, p);
+}
+
+/* Trial division with odd primes uses the following trick.
+
+   Let p be an odd prime, and B =3D 2^{W_TYPE_SIZE}. For simplicity,
+   consider the case t < B (this is the second loop below).
+
+   From our tables we get
+
+     binv =3D p^{-1} (mod B)
+     lim =3D floor ( (B-1) / p ).
+
+   First assume that t is a multiple of p, t =3D q * p. Then 0 <=3D q <=3D
+   lim (and all quotients in this range occur for some t).
+
+   Then t =3D q * p is true also (mod B), and p is invertible we get
+
+     q =3D t * binv (mod B).
+
+   Next, assume that t is *not* divisible by p. Since multiplication
+   by binv (mod B) is a one-to-one mapping,
+
+     t * binv (mod B) > lim,
+
+   because all the smaller values are already taken.
+
+   This can be summed up by saying that the function
+
+     q(t) =3D binv * t (mod B)
+
+   is a permutation of the range 0 <=3D t < B, with the curious property
+   that it maps the multiples of p onto the range 0 <=3D q <=3D lim, in
+   order, and the non-multiples of p onto the range lim < q < B.
+ */
+
+static uintmax_t
+factor_using_division (uintmax_t *t1p, uintmax_t t1, uintmax_t t0,
+                       struct factors *factors)
+{
+  if (t0 % 2 =3D=3D 0)
+    {
+      unsigned int cnt;
+
+      if (t0 =3D=3D 0)
+        {
+          count_trailing_zeros (cnt, t1);
+          t0 =3D t1 >> cnt;
+          t1 =3D 0;
+          cnt +=3D W_TYPE_SIZE;
+        }
+      else
+        {
+          count_trailing_zeros (cnt, t0);
+          rsh2 (t1, t0, t1, t0, cnt);
+        }
+
+      factor_insert_multiplicity (factors, 2, cnt);
+    }
+
+  uintmax_t p =3D 3;
+  unsigned int i;
+  for (i =3D 0; t1 > 0 && i < PRIMES_PTAB_ENTRIES; i++)
+    {
+      for (;;)
+        {
+          uintmax_t q1, q0, hi, lo;
+
+          q0 =3D t0 * primes_dtab[i].binv;
+          umul_ppmm (hi, lo, q0, p);
+          if (hi > t1)
+            break;
+          hi =3D t1 - hi;
+          q1 =3D hi * primes_dtab[i].binv;
+          if (LIKELY (q1 > primes_dtab[i].lim))
+            break;
+          t1 =3D q1; t0 =3D q0;
+          factor_insert (factors, p);
+        }
+      p +=3D primes_diff[i + 1];
+    }
+  if (t1p)
+    *t1p =3D t1;
+
+#define DIVBLOCK(I)                                                     \
+  do {                                                                  \
+    for (;;)                                                            \
+      {                                                                 \
+        q =3D t0 * pd[I].binv;                                            \
+        if (LIKELY (q > pd[I].lim))                                     \
+          break;                                                        \
+        t0 =3D q;                                                         \
+        factor_insert_refind (factors, p, i + 1, I);                    \
+      }                                                                 \
+  } while (0)
+
+  for (; i < PRIMES_PTAB_ENTRIES; i +=3D 8)
+    {
+      uintmax_t q;
+      const struct primes_dtab *pd =3D &primes_dtab[i];
+      DIVBLOCK (0);
+      DIVBLOCK (1);
+      DIVBLOCK (2);
+      DIVBLOCK (3);
+      DIVBLOCK (4);
+      DIVBLOCK (5);
+      DIVBLOCK (6);
+      DIVBLOCK (7);
+
+      p +=3D primes_diff8[i];
+      if (p * p > t0)
+        break;
+    }
+
+  return t0;
+}
+
+#if HAVE_GMP
+static void
+mp_factor_using_division (mpz_t t, struct mp_factors *factors)
+{
+  mpz_t q;
+  unsigned long int p;
+
+  if (flag_verbose > 0)
+    {
+      printf ("[trial division] ");
+    }
+
+  mpz_init (q);
+
+  p =3D mpz_scan1 (t, 0);
+  mpz_div_2exp (t, t, p);
+  while (p)
+    {
+      mp_factor_insert_ui (factors, 2);
+      --p;
+    }
+
+  p =3D 3;
+  for (unsigned int i =3D 1; i <=3D PRIMES_PTAB_ENTRIES;)
+    {
+      if (! mpz_divisible_ui_p (t, p))
+        {
+          p +=3D primes_diff[i++];
+          if (mpz_cmp_ui (t, p * p) < 0)
+            break;
+        }
+      else
+        {
+          mpz_tdiv_q_ui (t, t, p);
+          mp_factor_insert_ui (factors, p);
+        }
+    }
+
+  mpz_clear (q);
+}
+#endif
+
+/* Entry i contains (2i+1)^(-1) mod 2^8.  */
+static const unsigned char  binvert_table[128] =3D
+{
+  0x01, 0xAB, 0xCD, 0xB7, 0x39, 0xA3, 0xC5, 0xEF,
+  0xF1, 0x1B, 0x3D, 0xA7, 0x29, 0x13, 0x35, 0xDF,
+  0xE1, 0x8B, 0xAD, 0x97, 0x19, 0x83, 0xA5, 0xCF,
+  0xD1, 0xFB, 0x1D, 0x87, 0x09, 0xF3, 0x15, 0xBF,
+  0xC1, 0x6B, 0x8D, 0x77, 0xF9, 0x63, 0x85, 0xAF,
+  0xB1, 0xDB, 0xFD, 0x67, 0xE9, 0xD3, 0xF5, 0x9F,
+  0xA1, 0x4B, 0x6D, 0x57, 0xD9, 0x43, 0x65, 0x8F,
+  0x91, 0xBB, 0xDD, 0x47, 0xC9, 0xB3, 0xD5, 0x7F,
+  0x81, 0x2B, 0x4D, 0x37, 0xB9, 0x23, 0x45, 0x6F,
+  0x71, 0x9B, 0xBD, 0x27, 0xA9, 0x93, 0xB5, 0x5F,
+  0x61, 0x0B, 0x2D, 0x17, 0x99, 0x03, 0x25, 0x4F,
+  0x51, 0x7B, 0x9D, 0x07, 0x89, 0x73, 0x95, 0x3F,
+  0x41, 0xEB, 0x0D, 0xF7, 0x79, 0xE3, 0x05, 0x2F,
+  0x31, 0x5B, 0x7D, 0xE7, 0x69, 0x53, 0x75, 0x1F,
+  0x21, 0xCB, 0xED, 0xD7, 0x59, 0xC3, 0xE5, 0x0F,
+  0x11, 0x3B, 0x5D, 0xC7, 0x49, 0x33, 0x55, 0xFF
+};
+
+/* Compute n^(-1) mod B, using a Newton iteration.  */
+#define binv(inv,n)                                                     \
+  do {                                                                  \
+    uintmax_t  __n =3D (n);                                               \
+    uintmax_t  __inv;                                                   \
+                                                                        \
+    __inv =3D binvert_table[(__n / 2) & 0x7F]; /*  8 */                   \
+    if (W_TYPE_SIZE > 8)   __inv =3D 2 * __inv - __inv * __inv * __n;     \
+    if (W_TYPE_SIZE > 16)  __inv =3D 2 * __inv - __inv * __inv * __n;     \
+    if (W_TYPE_SIZE > 32)  __inv =3D 2 * __inv - __inv * __inv * __n;     \
+                                                                        \
+    if (W_TYPE_SIZE > 64)                                               \
+      {                                                                 \
+        int  __invbits =3D 64;                                            \
+        do {                                                            \
+          __inv =3D 2 * __inv - __inv * __inv * __n;                      \
+          __invbits *=3D 2;                                               \
+        } while (__invbits < W_TYPE_SIZE);                              \
+      }                                                                 \
+                                                                        \
+    (inv) =3D __inv;                                                      \
+  } while (0)
+
+/* q =3D u / d, assuming d|u.  */
+#define divexact_21(q1, q0, u1, u0, d)                                  \
+  do {                                                                  \
+    uintmax_t _di, _q0;                                                 \
+    binv (_di, (d));                                                    \
+    _q0 =3D (u0) * _di;                                                   \
+    if ((u1) >=3D (d))                                                    \
+      {                                                                 \
+        uintmax_t _p1, _p0;                                             \
+        umul_ppmm (_p1, _p0, _q0, d);                                   \
+        (q1) =3D ((u1) - _p1) * _di;                                      \
+        (q0) =3D _q0;                                                     \
+      }                                                                 \
+    else                                                                \
+      {                                                                 \
+        (q0) =3D _q0;                                                     \
+        (q1) =3D 0;                                                       \
+      }                                                                 \
+  } while(0)
+
+/* x B (mod n). */
+#define redcify(r_prim, r, n)                                           \
+  do {                                                                  \
+    uintmax_t _redcify_q;                                               \
+    udiv_qrnnd (_redcify_q, r_prim, r, 0, n);                           \
+  } while (0)
+
+/* x B^2 (mod n). Requires x > 0, n1 < B/2 */
+#define redcify2(r1, r0, x, n1, n0)                                     \
+  do {                                                                  \
+    uintmax_t _r1, _r0, _i;                                             \
+    if ((x) < (n1))                                                     \
+      {                                                                 \
+        _r1 =3D (x); _r0 =3D 0;                                           =
  \
+        _i =3D W_TYPE_SIZE;                                               \
+      }                                                                 \
+    else                                                                \
+      {                                                                 \
+        _r1 =3D 0; _r0 =3D (x);                                           =
  \
+        _i =3D 2*W_TYPE_SIZE;                                             \
+      }                                                                 \
+    while (_i-- > 0)                                                    \
+      {                                                                 \
+        lsh2 (_r1, _r0, _r1, _r0, 1);                                   \
+        if (ge2 (_r1, _r0, (n1), (n0)))                                 \
+          sub_ddmmss (_r1, _r0, _r1, _r0, (n1), (n0));                  \
+      }                                                                 \
+    (r1) =3D _r1;                                                         \
+    (r0) =3D _r0;                                                         \
+  } while (0)
+
+/* Modular two-word multiplication, r =3D a * b mod m, with mi =3D m^(-1) =
mod B.
+   Both a and b must be in redc form, the result will be in redc form too.=
 */
+static inline uintmax_t
+mulredc (uintmax_t a, uintmax_t b, uintmax_t m, uintmax_t mi)
+{
+  uintmax_t rh, rl, q, th, tl, xh;
+
+  umul_ppmm (rh, rl, a, b);
+  q =3D rl * mi;
+  umul_ppmm (th, tl, q, m);
+  xh =3D rh - th;
+  if (rh < th)
+    xh +=3D m;
+
+  return xh;
+}
+
+/* Modular two-word multiplication, r =3D a * b mod m, with mi =3D m^(-1) =
mod B.
+   Both a and b must be in redc form, the result will be in redc form too.
+   For performance reasons, the most significant bit of m must be clear. */
+static uintmax_t
+mulredc2 (uintmax_t *r1p,
+          uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax_t b0,
+          uintmax_t m1, uintmax_t m0, uintmax_t mi)
+{
+  uintmax_t r1, r0, q, p1, p0, t1, t0, s1, s0;
+  mi =3D -mi;
+  assert ( (a1 >> (W_TYPE_SIZE - 1)) =3D=3D 0);
+  assert ( (b1 >> (W_TYPE_SIZE - 1)) =3D=3D 0);
+  assert ( (m1 >> (W_TYPE_SIZE - 1)) =3D=3D 0);
+
+  /* First compute a0 * <b1, b0> B^{-1}
+        +-----+
+        |a0 b0|
+     +--+--+--+
+     |a0 b1|
+     +--+--+--+
+        |q0 m0|
+     +--+--+--+
+     |q0 m1|
+    -+--+--+--+
+     |r1|r0| 0|
+     +--+--+--+
+  */
+  umul_ppmm (t1, t0, a0, b0);
+  umul_ppmm (r1, r0, a0, b1);
+  q =3D mi * t0;
+  umul_ppmm (p1, p0, q, m0);
+  umul_ppmm (s1, s0, q, m1);
+  r0 +=3D (t0 !=3D 0); /* Carry */
+  add_ssaaaa (r1, r0, r1, r0, 0, p1);
+  add_ssaaaa (r1, r0, r1, r0, 0, t1);
+  add_ssaaaa (r1, r0, r1, r0, s1, s0);
+
+  /* Next, (a1 * <b1, b0> + <r1, r0> B^{-1}
+        +-----+
+        |a1 b0|
+        +--+--+
+        |r1|r0|
+     +--+--+--+
+     |a1 b1|
+     +--+--+--+
+        |q1 m0|
+     +--+--+--+
+     |q1 m1|
+    -+--+--+--+
+     |r1|r0| 0|
+     +--+--+--+
+  */
+  umul_ppmm (t1, t0, a1, b0);
+  umul_ppmm (s1, s0, a1, b1);
+  add_ssaaaa (t1, t0, t1, t0, 0, r0);
+  q =3D mi * t0;
+  add_ssaaaa (r1, r0, s1, s0, 0, r1);
+  umul_ppmm (p1, p0, q, m0);
+  umul_ppmm (s1, s0, q, m1);
+  r0 +=3D (t0 !=3D 0); /* Carry */
+  add_ssaaaa (r1, r0, r1, r0, 0, p1);
+  add_ssaaaa (r1, r0, r1, r0, 0, t1);
+  add_ssaaaa (r1, r0, r1, r0, s1, s0);
+
+  if (ge2 (r1, r0, m1, m0))
+    sub_ddmmss (r1, r0, r1, r0, m1, m0);
+
+  *r1p =3D r1;
+  return r0;
+}
+
+static uintmax_t _GL_ATTRIBUTE_CONST
+powm (uintmax_t b, uintmax_t e, uintmax_t n, uintmax_t ni, uintmax_t one)
+{
+  uintmax_t y =3D one;
+
+  if (e & 1)
+    y =3D b;
+
+  while (e !=3D 0)
+    {
+      b =3D mulredc (b, b, n, ni);
+      e >>=3D 1;
+
+      if (e & 1)
+        y =3D mulredc (y, b, n, ni);
+    }
+
+  return y;
+}
+
+static uintmax_t
+powm2 (uintmax_t *r1m,
+       const uintmax_t *bp, const uintmax_t *ep, const uintmax_t *np,
+       uintmax_t ni, const uintmax_t *one)
+{
+  uintmax_t r1, r0, b1, b0, n1, n0;
+  unsigned int i;
+  uintmax_t e;
+
+  b0 =3D bp[0];
+  b1 =3D bp[1];
+  n0 =3D np[0];
+  n1 =3D np[1];
+
+  r0 =3D one[0];
+  r1 =3D one[1];
+
+  for (e =3D ep[0], i =3D W_TYPE_SIZE; i > 0; i--, e >>=3D 1)
+    {
+      if (e & 1)
+        {
+          r0 =3D mulredc2 (r1m, r1, r0, b1, b0, n1, n0, ni);
+          r1 =3D *r1m;
+        }
+      b0 =3D mulredc2 (r1m, b1, b0, b1, b0, n1, n0, ni);
+      b1 =3D *r1m;
+    }
+  for (e =3D ep[1]; e > 0; e >>=3D 1)
+    {
+      if (e & 1)
+        {
+          r0 =3D mulredc2 (r1m, r1, r0, b1, b0, n1, n0, ni);
+          r1 =3D *r1m;
+        }
+      b0 =3D mulredc2 (r1m, b1, b0, b1, b0, n1, n0, ni);
+      b1 =3D *r1m;
+    }
+  *r1m =3D r1;
+  return r0;
+}
+
+static bool _GL_ATTRIBUTE_CONST
+millerrabin (uintmax_t n, uintmax_t ni, uintmax_t b, uintmax_t q,
+             unsigned int k, uintmax_t one)
+{
+  uintmax_t y =3D powm (b, q, n, ni, one);
+
+  uintmax_t nm1 =3D n - one;      /* -1, but in redc representation. */
+
+  if (y =3D=3D one || y =3D=3D nm1)
+    return true;
+
+  for (unsigned int i =3D 1; i < k; i++)
+    {
+      y =3D mulredc (y, y, n, ni);
+
+      if (y =3D=3D nm1)
+        return true;
+      if (y =3D=3D one)
+        return false;
+    }
+  return false;
+}
+
+static bool
+millerrabin2 (const uintmax_t *np, uintmax_t ni, const uintmax_t *bp,
+              const uintmax_t *qp, unsigned int k, const uintmax_t *one)
+{
+  uintmax_t y1, y0, nm1_1, nm1_0, r1m;
+
+  y0 =3D powm2 (&r1m, bp, qp, np, ni, one);
+  y1 =3D r1m;
+
+  if (y0 =3D=3D one[0] && y1 =3D=3D one[1])
+    return true;
+
+  sub_ddmmss (nm1_1, nm1_0, np[1], np[0], one[1], one[0]);
+
+  if (y0 =3D=3D nm1_0 && y1 =3D=3D nm1_1)
+    return true;
+
+  for (unsigned int i =3D 1; i < k; i++)
+    {
+      y0 =3D mulredc2 (&r1m, y1, y0, y1, y0, np[1], np[0], ni);
+      y1 =3D r1m;
+
+      if (y0 =3D=3D nm1_0 && y1 =3D=3D nm1_1)
+        return true;
+      if (y0 =3D=3D one[0] && y1 =3D=3D one[1])
+        return false;
+    }
+  return false;
+}
+
+#if HAVE_GMP
+static bool
+mp_millerrabin (mpz_srcptr n, mpz_srcptr nm1, mpz_ptr x, mpz_ptr y,
+                mpz_srcptr q, unsigned long int k)
+{
+  mpz_powm (y, x, q, n);
+
+  if (mpz_cmp_ui (y, 1) =3D=3D 0 || mpz_cmp (y, nm1) =3D=3D 0)
+    return true;
+
+  for (unsigned long int i =3D 1; i < k; i++)
+    {
+      mpz_powm_ui (y, y, 2, n);
+      if (mpz_cmp (y, nm1) =3D=3D 0)
+        return true;
+      if (mpz_cmp_ui (y, 1) =3D=3D 0)
+        return false;
+    }
+  return false;
+}
+#endif
+
+/* Lucas' prime test.  The number of iterations vary greatly, up to a few =
dozen
+   have been observed.  The average seem to be about 2.  */
+static bool
+prime_p (uintmax_t n)
+{
+  int k;
+  bool is_prime;
+  uintmax_t a_prim, one, ni;
+  struct factors factors;
+
+  if (n <=3D 1)
+    return false;
+
+  /* We have already casted out small primes. */
+  if (n < (uintmax_t) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME)
+    return true;
+
+  /* Precomputation for Miller-Rabin.  */
+  uintmax_t q =3D n - 1;
+  for (k =3D 0; (q & 1) =3D=3D 0; k++)
+    q >>=3D 1;
+
+  uintmax_t a =3D 2;
+  binv (ni, n);                 /* ni <- 1/n mod B */
+  redcify (one, 1, n);
+  addmod (a_prim, one, one, n); /* i.e., redcify a =3D 2 */
+
+  /* Perform a Miller-Rabin test, finds most composites quickly.  */
+  if (!millerrabin (n, ni, a_prim, q, k, one))
+    return false;
+
+  if (flag_prove_primality)
+    {
+      /* Factor n-1 for Lucas.  */
+      factor (0, n - 1, &factors);
+    }
+
+  /* Loop until Lucas proves our number prime, or Miller-Rabin proves our
+     number composite.  */
+  for (unsigned int r =3D 0; r < PRIMES_PTAB_ENTRIES; r++)
+    {
+      if (flag_prove_primality)
+        {
+          is_prime =3D true;
+          for (unsigned int i =3D 0; i < factors.nfactors && is_prime; i++)
+            {
+              is_prime =3D powm (a_prim, (n - 1) / factors.p[i], n, ni, on=
e) !=3D one;
+            }
+        }
+      else
+        {
+          /* After enough Miller-Rabin runs, be content. */
+          is_prime =3D (r =3D=3D MR_REPS - 1);
+        }
+
+      if (is_prime)
+        return true;
+
+      a +=3D primes_diff[r];      /* Establish new base.  */
+
+      /* The following is equivalent to redcify (a_prim, a, n).  It runs f=
aster
+         on most processors, since it avoids udiv_qrnnd.  If we go down the
+         udiv_qrnnd_preinv path, this code should be replaced.  */
+      {
+        uintmax_t dummy, s1, s0;
+        umul_ppmm (s1, s0, one, a);
+        if (LIKELY (s1 =3D=3D 0))
+          a_prim =3D s0 % n;
+        else
+          udiv_qrnnd (dummy, a_prim, s1, s0, n);
+      }
+
+      if (!millerrabin (n, ni, a_prim, q, k, one))
+        return false;
+    }
+
+  fprintf (stderr, "Lucas prime test failure.  This should not happen\n");
+  abort ();
+}
+
+static bool
+prime2_p (uintmax_t n1, uintmax_t n0)
+{
+  uintmax_t q[2], nm1[2];
+  uintmax_t a_prim[2];
+  uintmax_t one[2];
+  uintmax_t na[2];
+  uintmax_t ni;
+  unsigned int k;
+  struct factors factors;
+
+  if (n1 =3D=3D 0)
+    return prime_p (n0);
+
+  nm1[1] =3D n1 - (n0 =3D=3D 0);
+  nm1[0] =3D n0 - 1;
+  if (nm1[0] =3D=3D 0)
+    {
+      count_trailing_zeros (k, nm1[1]);
+
+      q[0] =3D nm1[1] >> k;
+      q[1] =3D 0;
+      k +=3D W_TYPE_SIZE;
+    }
+  else
+    {
+      count_trailing_zeros (k, nm1[0]);
+      rsh2 (q[1], q[0], nm1[1], nm1[0], k);
+    }
+
+  uintmax_t a =3D 2;
+  binv (ni, n0);
+  redcify2 (one[1], one[0], 1, n1, n0);
+  addmod2 (a_prim[1], a_prim[0], one[1], one[0], one[1], one[0], n1, n0);
+
+  /* FIXME: Use scalars or pointers in arguments? Some consistency needed.=
 */
+  na[0] =3D n0;
+  na[1] =3D n1;
+
+  if (!millerrabin2 (na, ni, a_prim, q, k, one))
+    return false;
+
+  if (flag_prove_primality)
+    {
+      /* Factor n-1 for Lucas.  */
+      factor (nm1[1], nm1[0], &factors);
+    }
+
+  /* Loop until Lucas proves our number prime, or Miller-Rabin proves our
+     number composite.  */
+  for (unsigned int r =3D 0; r < PRIMES_PTAB_ENTRIES; r++)
+    {
+      bool is_prime;
+      uintmax_t e[2], y[2];
+
+      if (flag_prove_primality)
+        {
+          is_prime =3D true;
+          if (factors.plarge[1])
+            {
+              uintmax_t pi;
+              binv (pi, factors.plarge[0]);
+              e[0] =3D pi * nm1[0];
+              e[1] =3D 0;
+              y[0] =3D powm2 (&y[1], a_prim, e, na, ni, one);
+              is_prime =3D (y[0] !=3D one[0] || y[1] !=3D one[1]);
+            }
+          for (unsigned int i =3D 0; i < factors.nfactors && is_prime; i++)
+            {
+              /* FIXME: We always have the factor 2. Do we really need to =
handle it
+                 here? We have done the same powering as part of millerrab=
in. */
+              if (factors.p[i] =3D=3D 2)
+                rsh2 (e[1], e[0], nm1[1], nm1[0], 1);
+              else
+                divexact_21 (e[1], e[0], nm1[1], nm1[0], factors.p[i]);
+              y[0] =3D powm2 (&y[1], a_prim, e, na, ni, one);
+              is_prime =3D (y[0] !=3D one[0] || y[1] !=3D one[1]);
+            }
+        }
+      else
+        {
+          /* After enough Miller-Rabin runs, be content. */
+          is_prime =3D (r =3D=3D MR_REPS - 1);
+        }
+
+      if (is_prime)
+        return true;
+
+      a +=3D primes_diff[r];      /* Establish new base.  */
+      redcify2 (a_prim[1], a_prim[0], a, n1, n0);
+
+      if (!millerrabin2 (na, ni, a_prim, q, k, one))
+        return false;
+    }
+
+  fprintf (stderr, "Lucas prime test failure.  This should not happen\n");
+  abort ();
+}
+
+#if HAVE_GMP
+static bool
+mp_prime_p (mpz_t n)
+{
+  bool is_prime;
+  mpz_t q, a, nm1, tmp;
+  struct mp_factors factors;
+
+  if (mpz_cmp_ui (n, 1) <=3D 0)
+    return false;
+
+  /* We have already casted out small primes. */
+  if (mpz_cmp_ui (n, (long) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME) < 0)
+    return true;
+
+  mpz_inits (q, a, nm1, tmp, NULL);
+
+  /* Precomputation for Miller-Rabin.  */
+  mpz_sub_ui (nm1, n, 1);
+
+  /* Find q and k, where q is odd and n =3D 1 + 2**k * q.  */
+  unsigned long int k =3D mpz_scan1 (nm1, 0);
+  mpz_tdiv_q_2exp (q, nm1, k);
+
+  mpz_set_ui (a, 2);
+
+  /* Perform a Miller-Rabin test, finds most composites quickly.  */
+  if (!mp_millerrabin (n, nm1, a, tmp, q, k))
+    {
+      is_prime =3D false;
+      goto ret2;
+    }
+
+  if (flag_prove_primality)
+    {
+      /* Factor n-1 for Lucas.  */
+      mpz_set (tmp, nm1);
+      mp_factor (tmp, &factors);
+    }
+
+  /* Loop until Lucas proves our number prime, or Miller-Rabin proves our
+     number composite.  */
+  for (unsigned int r =3D 0; r < PRIMES_PTAB_ENTRIES; r++)
+    {
+      if (flag_prove_primality)
+        {
+          is_prime =3D true;
+          for (unsigned long int i =3D 0; i < factors.nfactors && is_prime=
; i++)
+            {
+              mpz_divexact (tmp, nm1, factors.p[i]);
+              mpz_powm (tmp, a, tmp, n);
+              is_prime =3D mpz_cmp_ui (tmp, 1) !=3D 0;
+            }
+        }
+      else
+        {
+          /* After enough Miller-Rabin runs, be content. */
+          is_prime =3D (r =3D=3D MR_REPS - 1);
+        }
+
+      if (is_prime)
+        goto ret1;
+
+      mpz_add_ui (a, a, primes_diff[r]);        /* Establish new base.  */
+
+      if (!mp_millerrabin (n, nm1, a, tmp, q, k))
+        {
+          is_prime =3D false;
+          goto ret1;
+        }
+    }
+
+  fprintf (stderr, "Lucas prime test failure.  This should not happen\n");
+  abort ();
+
+ ret1:
+  if (flag_prove_primality)
+    mp_factor_clear (&factors);
+ ret2:
+  mpz_clears (q, a, nm1, tmp, NULL);
+
+  return is_prime;
+}
+#endif
+
+static void
+factor_using_pollard_rho (uintmax_t n, unsigned long int a,
+                          struct factors *factors)
+{
+  uintmax_t x, z, y, P, t, ni, g;
+
+  unsigned long int k =3D 1;
+  unsigned long int l =3D 1;
+
+  redcify (P, 1, n);
+  addmod (x, P, P, n);          /* i.e., redcify(2) */
+  y =3D z =3D x;
+
+  while (n !=3D 1)
+    {
+      assert (a < n);
+
+      binv (ni, n);             /* FIXME: when could we use old 'ni' value=
? */
+
+      for (;;)
+        {
+          do
+            {
+              x =3D mulredc (x, x, n, ni);
+              addmod (x, x, a, n);
+
+              submod (t, z, x, n);
+              P =3D mulredc (P, t, n, ni);
+
+              if (k % 32 =3D=3D 1)
+                {
+                  if (gcd_odd (P, n) !=3D 1)
+                    goto factor_found;
+                  y =3D x;
+                }
+            }
+          while (--k !=3D 0);
+
+          z =3D x;
+          k =3D l;
+          l =3D 2 * l;
+          for (unsigned long int i =3D 0; i < k; i++)
+            {
+              x =3D mulredc (x, x, n, ni);
+              addmod (x, x, a, n);
+            }
+          y =3D x;
+        }
+
+    factor_found:
+      do
+        {
+          y =3D mulredc (y, y, n, ni);
+          addmod (y, y, a, n);
+
+          submod (t, z, y, n);
+          g =3D gcd_odd (t, n);
+        }
+      while (g =3D=3D 1);
+
+      n =3D n / g;
+
+      if (!prime_p (g))
+        factor_using_pollard_rho (g, a + 1, factors);
+      else
+        factor_insert (factors, g);
+
+      if (prime_p (n))
+        {
+          factor_insert (factors, n);
+          break;
+        }
+
+      x =3D x % n;
+      z =3D z % n;
+      y =3D y % n;
+    }
+}
+
+static void
+factor_using_pollard_rho2 (uintmax_t n1, uintmax_t n0, unsigned long int a,
+                           struct factors *factors)
+{
+  uintmax_t x1, x0, z1, z0, y1, y0, P1, P0, t1, t0, ni, g1, g0, r1m;
+
+  unsigned long int k =3D 1;
+  unsigned long int l =3D 1;
+
+  redcify2 (P1, P0, 1, n1, n0);
+  addmod2 (x1, x0, P1, P0, P1, P0, n1, n0); /* i.e., redcify(2) */
+  y1 =3D z1 =3D x1;
+  y0 =3D z0 =3D x0;
+
+  while (n1 !=3D 0 || n0 !=3D 1)
+    {
+      binv (ni, n0);
+
+      for (;;)
+        {
+          do
+            {
+              x0 =3D mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
+              x1 =3D r1m;
+              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
+
+              submod2 (t1, t0, z1, z0, x1, x0, n1, n0);
+              P0 =3D mulredc2 (&r1m, P1, P0, t1, t0, n1, n0, ni);
+              P1 =3D r1m;
+
+              if (k % 32 =3D=3D 1)
+                {
+                  g0 =3D gcd2_odd (&g1, P1, P0, n1, n0);
+                  if (g1 !=3D 0 || g0 !=3D 1)
+                    goto factor_found;
+                  y1 =3D x1; y0 =3D x0;
+                }
+            }
+          while (--k !=3D 0);
+
+          z1 =3D x1; z0 =3D x0;
+          k =3D l;
+          l =3D 2 * l;
+          for (unsigned long int i =3D 0; i < k; i++)
+            {
+              x0 =3D mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
+              x1 =3D r1m;
+              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
+            }
+          y1 =3D x1; y0 =3D x0;
+        }
+
+    factor_found:
+      do
+        {
+          y0 =3D mulredc2 (&r1m, y1, y0, y1, y0, n1, n0, ni);
+          y1 =3D r1m;
+          addmod2 (y1, y0, y1, y0, 0, a, n1, n0);
+
+          submod2 (t1, t0, z1, z0, y1, y0, n1, n0);
+          g0 =3D gcd2_odd (&g1, t1, t0, n1, n0);
+        }
+      while (g1 =3D=3D 0 && g0 =3D=3D 1);
+
+      if (g1 =3D=3D 0)
+        {
+          /* The found factor is one word. */
+          divexact_21 (n1, n0, n1, n0, g0);     /* n =3D n / g */
+
+          if (!prime_p (g0))
+            factor_using_pollard_rho (g0, a + 1, factors);
+          else
+            factor_insert (factors, g0);
+        }
+      else
+        {
+          /* The found factor is two words.  This is highly unlikely, thus=
 hard
+             to trigger.  Please be careful before you change this code!  =
*/
+          uintmax_t ginv;
+
+          binv (ginv, g0);      /* Compute n =3D n / g.  Since the result =
will */
+          n0 =3D ginv * n0;       /* fit one word, we can compute the quot=
ient */
+          n1 =3D 0;               /* modulo B, ignoring the high divisor w=
ord. */
+
+          if (!prime2_p (g1, g0))
+            factor_using_pollard_rho2 (g1, g0, a + 1, factors);
+          else
+            factor_insert_large (factors, g1, g0);
+        }
+
+      if (n1 =3D=3D 0)
+        {
+          if (prime_p (n0))
+            {
+              factor_insert (factors, n0);
+              break;
+            }
+
+          factor_using_pollard_rho (n0, a, factors);
+          return;
+        }
+
+      if (prime2_p (n1, n0))
+        {
+          factor_insert_large (factors, n1, n0);
+          break;
+        }
+
+      x0 =3D mod2 (&x1, x1, x0, n1, n0);
+      z0 =3D mod2 (&z1, z1, z0, n1, n0);
+      y0 =3D mod2 (&y1, y1, y0, n1, n0);
+    }
+}
+
+#if HAVE_GMP
+static void
+mp_factor_using_pollard_rho (mpz_t n, unsigned long int a,
+                             struct mp_factors *factors)
+{
+  mpz_t x, z, y, P;
+  mpz_t t, t2;
+  unsigned long long int k, l;
+
+  if (flag_verbose > 0)
+    {
+      printf ("[pollard-rho (%lu)] ", a);
+    }
+
+  mpz_inits (t, t2, NULL);
+  mpz_init_set_si (y, 2);
+  mpz_init_set_si (x, 2);
+  mpz_init_set_si (z, 2);
+  mpz_init_set_ui (P, 1);
+  k =3D 1;
+  l =3D 1;
+
+  while (mpz_cmp_ui (n, 1) !=3D 0)
+    {
+      for (;;)
+        {
+          do
+            {
+              mpz_mul (t, x, x);
+              mpz_mod (x, t, n);
+              mpz_add_ui (x, x, a);
+
+              mpz_sub (t, z, x);
+              mpz_mul (t2, P, t);
+              mpz_mod (P, t2, n);
+
+              if (k % 32 =3D=3D 1)
+                {
+                  mpz_gcd (t, P, n);
+                  if (mpz_cmp_ui (t, 1) !=3D 0)
+                    goto factor_found;
+                  mpz_set (y, x);
+                }
+            }
+          while (--k !=3D 0);
+
+          mpz_set (z, x);
+          k =3D l;
+          l =3D 2 * l;
+          for (unsigned long long int i =3D 0; i < k; i++)
+            {
+              mpz_mul (t, x, x);
+              mpz_mod (x, t, n);
+              mpz_add_ui (x, x, a);
+            }
+          mpz_set (y, x);
+        }
+
+    factor_found:
+      do
+        {
+          mpz_mul (t, y, y);
+          mpz_mod (y, t, n);
+          mpz_add_ui (y, y, a);
+
+          mpz_sub (t, z, y);
+          mpz_gcd (t, t, n);
+        }
+      while (mpz_cmp_ui (t, 1) =3D=3D 0);
+
+      mpz_divexact (n, n, t);   /* divide by t, before t is overwritten */
+
+      if (!mp_prime_p (t))
+        {
+          if (flag_verbose > 0)
+            {
+              printf ("[composite factor--restarting pollard-rho] ");
+            }
+          mp_factor_using_pollard_rho (t, a + 1, factors);
+        }
+      else
+        {
+          mp_factor_insert (factors, t);
+        }
+
+      if (mp_prime_p (n))
+        {
+          mp_factor_insert (factors, n);
+          break;
+        }
+
+      mpz_mod (x, x, n);
+      mpz_mod (z, z, n);
+      mpz_mod (y, y, n);
+    }
+
+  mpz_clears (P, t2, t, z, x, y, NULL);
+}
+#endif
+
+/* FIXME: Maybe better to use an iteration converging to 1/sqrt(n)?  If
+   algorithm is replaced, consider also returning the remainder. */
+static uintmax_t _GL_ATTRIBUTE_CONST
+isqrt (uintmax_t n)
+{
+  uintmax_t x;
+  unsigned c;
+  if (n =3D=3D 0)
+    return 0;
+
+  count_leading_zeros (c, n);
+
+  /* Make x > sqrt(n). This will be invariant through the loop. */
+  x =3D (uintmax_t) 1 << ((W_TYPE_SIZE + 1 - c) / 2);
+
+  for (;;)
+    {
+      uintmax_t y =3D (x + n/x) / 2;
+      if (y >=3D x)
+        return x;
+
+      x =3D y;
+    }
+}
+
+static uintmax_t _GL_ATTRIBUTE_CONST
+isqrt2 (uintmax_t nh, uintmax_t nl)
+{
+  unsigned int shift;
+  uintmax_t x;
+
+  /* Ensures the remainder fits in an uintmax_t. */
+  assert (nh < ((uintmax_t) 1 << (W_TYPE_SIZE - 2)));
+
+  if (nh =3D=3D 0)
+    return isqrt (nl);
+
+  count_leading_zeros (shift, nh);
+  shift &=3D ~1;
+
+  /* Make x > sqrt(n) */
+  x =3D isqrt ( (nh << shift) + (nl >> (W_TYPE_SIZE - shift))) + 1;
+  x <<=3D (W_TYPE_SIZE - shift) / 2;
+
+  /* Do we need more than one iteration? */
+  for (;;)
+    {
+      uintmax_t q, r, y;
+      udiv_qrnnd (q, r, nh, nl, x);
+      y =3D (x + q) / 2;
+
+      if (y >=3D x)
+        {
+          uintmax_t hi, lo;
+          umul_ppmm (hi, lo, x + 1, x + 1);
+          assert (gt2 (hi, lo, nh, nl));
+
+          umul_ppmm (hi, lo, x, x);
+          assert (ge2 (nh, nl, hi, lo));
+          sub_ddmmss (hi, lo, nh, nl, hi, lo);
+          assert (hi =3D=3D 0);
+
+          return x;
+        }
+
+      x =3D y;
+    }
+}
+
+/* MAGIC[N] has a bit i set iff i is a quadratic residue mod N. */
+#define MAGIC64 ((uint64_t) 0x0202021202030213ULL)
+#define MAGIC63 ((uint64_t) 0x0402483012450293ULL)
+#define MAGIC65 ((uint64_t) 0x218a019866014613ULL)
+#define MAGIC11 0x23b
+
+/* Returns the square root if the input is a square, otherwise 0. */
+static uintmax_t _GL_ATTRIBUTE_CONST
+is_square (uintmax_t x)
+{
+  /* Uses the tests suggested by Cohen. Excludes 99% of the non-squares be=
fore
+     computing the square root. */
+  if (((MAGIC64 >> (x & 63)) & 1)
+      && ((MAGIC63 >> (x % 63)) & 1)
+      /* Both 0 and 64 are squares mod (65) */
+      && ((MAGIC65 >> ((x % 65) & 63)) & 1)
+      && ((MAGIC11 >> (x % 11) & 1)))
+    {
+      uintmax_t r =3D isqrt (x);
+      if (r*r =3D=3D x)
+        return r;
+    }
+  return 0;
+}
+
+static const unsigned short invtab[] =3D
+  {
+    0x1fc, 0x1f8, 0x1f4, 0x1f0, 0x1ec, 0x1e9, 0x1e5, 0x1e1,
+    0x1de, 0x1da, 0x1d7, 0x1d4, 0x1d0, 0x1cd, 0x1ca, 0x1c7,
+    0x1c3, 0x1c0, 0x1bd, 0x1ba, 0x1b7, 0x1b4, 0x1b2, 0x1af,
+    0x1ac, 0x1a9, 0x1a6, 0x1a4, 0x1a1, 0x19e, 0x19c, 0x199,
+    0x197, 0x194, 0x192, 0x18f, 0x18d, 0x18a, 0x188, 0x186,
+    0x183, 0x181, 0x17f, 0x17d, 0x17a, 0x178, 0x176, 0x174,
+    0x172, 0x170, 0x16e, 0x16c, 0x16a, 0x168, 0x166, 0x164,
+    0x162, 0x160, 0x15e, 0x15c, 0x15a, 0x158, 0x157, 0x155,
+    0x153, 0x151, 0x150, 0x14e, 0x14c, 0x14a, 0x149, 0x147,
+    0x146, 0x144, 0x142, 0x141, 0x13f, 0x13e, 0x13c, 0x13b,
+    0x139, 0x138, 0x136, 0x135, 0x133, 0x132, 0x130, 0x12f,
+    0x12e, 0x12c, 0x12b, 0x129, 0x128, 0x127, 0x125, 0x124,
+    0x123, 0x121, 0x120, 0x11f, 0x11e, 0x11c, 0x11b, 0x11a,
+    0x119, 0x118, 0x116, 0x115, 0x114, 0x113, 0x112, 0x111,
+    0x10f, 0x10e, 0x10d, 0x10c, 0x10b, 0x10a, 0x109, 0x108,
+    0x107, 0x106, 0x105, 0x104, 0x103, 0x102, 0x101, 0x100,
+  };
+
+/* Compute q =3D [u/d], r =3D u mod d.  Avoids slow hardware division for =
the case
+   that q < 0x40; here it instead uses a table of (Euclidian) inverses.  */
+#define div_smallq(q, r, u, d)                                          \
+  do {                                                                  \
+    if (0 && (u) / 0x40 < (d))                                          \
+      {                                                                 \
+        int _cnt;                                                       \
+        uintmax_t _dinv, _mask, _q, _r;                                 \
+        count_leading_zeros (_cnt, (d));                                \
+                                                                        \
+        _dinv =3D invtab[((d) >> (W_TYPE_SIZE - 8 - _cnt))                \
+                       - (1 << (8 - 1))];                               \
+                                                                        \
+        _r =3D (u);                                                       \
+        _q =3D _r * _dinv >> (W_TYPE_SIZE + 8 - _cnt);                    \
+        _r -=3D _q*(d);                                                   \
+                                                                        \
+        _mask =3D -(uintmax_t) (_r >=3D (d));                             =
  \
+        (r) =3D _r - (_mask & (d));                                       \
+        (q) =3D _q - _mask;                                               \
+        assert ( (q) * (d) + (r) =3D=3D u);                               =
  \
+      }                                                                 \
+    else                                                                \
+      {                                                                 \
+        uintmax_t _q =3D (u) / (d);                                       \
+        (r) =3D (u) - _q * (d);                                           \
+        (q) =3D _q;                                                       \
+      }                                                                 \
+  } while (0)
+
+/* Notes: Example N =3D 22117019. After first phase we find Q1 =3D 6314, Q
+   =3D 3025, P =3D 1737, representing F_{18} =3D (-6314, 2* 1737, 3025),
+   with 3025 =3D 55^2.
+
+   Constructing the square root, we get Q1 =3D 55, Q =3D 8653, P =3D 4652,
+   representing G_0 =3D (-55, 2*4652, 8653).
+
+   In the notation of the paper:
+
+   S_{-1} =3D 55, S_0 =3D 8653, R_0 =3D 4652
+
+   Put
+
+     t_0 =3D floor([q_0 + R_0] / S0) =3D 1
+     R_1 =3D t_0 * S_0 - R_0 =3D 4001
+     S_1 =3D S_{-1} +t_0 (R_0 - R_1) =3D 706
+*/
+
+/* Multipliers, in order of efficiency:
+   0.7268  3*5*7*11 =3D 1155 =3D 3 (mod 4)
+   0.7317  3*5*7    =3D  105 =3D 1
+   0.7820  3*5*11   =3D  165 =3D 1
+   0.7872  3*5      =3D   15 =3D 3
+   0.8101  3*7*11   =3D  231 =3D 3
+   0.8155  3*7      =3D   21 =3D 1
+   0.8284  5*7*11   =3D  385 =3D 1
+   0.8339  5*7      =3D   35 =3D 3
+   0.8716  3*11     =3D   33 =3D 1
+   0.8774  3        =3D    3 =3D 3
+   0.8913  5*11     =3D   55 =3D 3
+   0.8972  5        =3D    5 =3D 1
+   0.9233  7*11     =3D   77 =3D 1
+   0.9295  7        =3D    7 =3D 3
+   0.9934  11       =3D   11 =3D 3
+*/
+#define QUEUE_SIZE 50
+
+#if STAT_SQUFOF
+# define Q_FREQ_SIZE 50
+/* Element 0 keeps the total */
+static unsigned int q_freq[Q_FREQ_SIZE + 1];
+# define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+
+
+static void
+factor_using_squfof (uintmax_t n1, uintmax_t n0, struct factors *factors)
+{
+  /* Uses algorithm and notation from
+
+     SQUARE FORM FACTORIZATION
+     JASON E. GOWER AND SAMUEL S. WAGSTAFF, JR.
+
+     http://homes.cerias.purdue.edu/~ssw/squfof.pdf
+   */
+
+  static const unsigned int multipliers_1[] =3D
+    { /* =3D 1 (mod 4) */
+      105, 165, 21, 385, 33, 5, 77, 1, 0
+    };
+  static const unsigned int multipliers_3[] =3D
+    { /* =3D 3 (mod 4) */
+      1155, 15, 231, 35, 3, 55, 7, 11, 0
+    };
+
+  uintmax_t S;
+  const unsigned int *m;
+
+  struct { uintmax_t Q; uintmax_t P; } queue[QUEUE_SIZE];
+
+  S =3D isqrt2 (n1, n0);
+
+  if (n0 =3D=3D S * S)
+    {
+      uintmax_t p1, p0;
+
+      umul_ppmm (p1, p0, S, S);
+      assert (p0 =3D=3D n0);
+
+      if (n1 =3D=3D p1)
+        {
+          if (prime_p (S))
+            factor_insert_multiplicity (factors, S, 2);
+          else
+            {
+              struct factors f;
+
+              f.nfactors =3D 0;
+              factor_using_squfof (0, S, &f);
+              /* Duplicate the new factors */
+              for (unsigned int i =3D 0; i < f.nfactors; i++)
+                factor_insert_multiplicity (factors, f.p[i], 2*f.e[i]);
+            }
+          return;
+        }
+    }
+
+  /* Select multipliers so we always get n * mu =3D 3 (mod 4) */
+  for (m =3D (n0 % 4 =3D=3D 1) ? multipliers_3 : multipliers_1;
+       *m; m++)
+    {
+      uintmax_t S, Dh, Dl, Q1, Q, P, L, L1, B;
+      unsigned int i;
+      unsigned int mu =3D *m;
+      unsigned int qpos =3D 0;
+
+      assert (mu * n0 % 4 =3D=3D 3);
+
+      /* In the notation of the paper, with mu * n =3D=3D 3 (mod 4), we
+         get \Delta =3D 4 mu * n, and the paper's \mu is 2 mu. As far as
+         I understand it, the necessary bound is 4 \mu^3 < n, or 32
+         mu^3 < n.
+
+         However, this seems insufficient: With n =3D 37243139 and mu =3D
+         105, we get a trivial factor, from the square 38809 =3D 197^2,
+         without any corresponding Q earlier in the iteration.
+
+         Requiring 64 mu^3 < n seems sufficient. */
+      if (n1 =3D=3D 0)
+        {
+          if ((uintmax_t) mu*mu*mu >=3D n0 / 64)
+            continue;
+        }
+      else
+        {
+          if (n1 > ((uintmax_t) 1 << (W_TYPE_SIZE - 2)) / mu)
+            continue;
+        }
+      umul_ppmm (Dh, Dl, n0, mu);
+      Dh +=3D n1 * mu;
+
+      assert (Dl % 4 !=3D 1);
+
+      S =3D isqrt2 (Dh, Dl);
+
+      Q1 =3D 1;
+      P =3D S;
+
+      /* Square root remainder fits in one word, so ignore high part. */
+      Q =3D Dl - P*P;
+      /* FIXME: When can this differ from floor(sqrt(2 sqrt(D)))? */
+      L =3D isqrt (2*S);
+      B =3D 2*L;
+      L1 =3D mu * 2 * L;
+
+      /* The form is (+/- Q1, 2P, -/+ Q), of discriminant 4 (P^2 + Q Q1) =
=3D
+         4 D. */
+
+      for (i =3D 0; i <=3D B; i++)
+        {
+          uintmax_t q, P1, t, r;
+
+          div_smallq (q, r, S+P, Q);
+          P1 =3D S - r;   /* P1 =3D q*Q - P */
+
+#if STAT_SQUFOF
+          assert (q > 0);
+          q_freq[0]++;
+          q_freq[MIN(q, Q_FREQ_SIZE)]++;
+#endif
+
+          if (Q <=3D L1)
+            {
+              uintmax_t g =3D Q;
+
+              if ( (Q & 1) =3D=3D 0)
+                g /=3D 2;
+
+              g /=3D gcd_odd (g, mu);
+
+              if (g <=3D L)
+                {
+                  if (qpos >=3D QUEUE_SIZE)
+                    {
+                      fprintf (stderr, "squfof queue overflow.\n");
+                      exit (EXIT_FAILURE);
+                    }
+                  queue[qpos].Q =3D g;
+                  queue[qpos].P =3D P % g;
+                  qpos++;
+                }
+            }
+
+          /* I think the difference can be either sign, but mod
+             2^W_TYPE_SIZE arithmetic should be fine. */
+          t =3D Q1 + q * (P - P1);
+          Q1 =3D Q;
+          Q =3D t;
+          P =3D P1;
+
+          if ( (i & 1) =3D=3D 0)
+            {
+              uintmax_t r =3D is_square (Q);
+              if (r)
+                {
+                  unsigned int j;
+
+                  for (j =3D 0; j < qpos; j++)
+                    {
+                      if (queue[j].Q =3D=3D r)
+                        {
+                          if (r =3D=3D 1)
+                            /* Traversed entire cycle. */
+                            goto next_multiplier;
+
+                          /* Need the absolute value for divisibility test=
. */
+                          if (P >=3D queue[j].P)
+                            t =3D P - queue[j].P;
+                          else
+                            t =3D queue[j].P - P;
+                          if (t % r =3D=3D 0)
+                            {
+                              /* Delete entries up to and including entry
+                                 j, which matched. */
+                              memmove (queue, queue + j + 1,
+                                       (qpos - j - 1) * sizeof (queue[0]));
+                              qpos -=3D (j + 1);
+                            }
+                          goto next_i;
+                        }
+                    }
+
+                  /* We have found a square form, which should give a
+                     factor. */
+                  Q1 =3D r;
+                  assert (S >=3D P); /* What signs are possible? */
+                  P +=3D r * ((S - P) / r);
+
+                  /* Note: Paper says (N - P*P) / Q1, that seems incorrect
+                     for the case D =3D 2N. */
+                  /* Compute Q =3D (D - P*P) / Q1, but we need double
+                     precision. */
+                  {
+                    uintmax_t hi, lo, rem;
+                    umul_ppmm (hi, lo, P, P);
+                    sub_ddmmss (hi, lo, Dh, Dl, hi, lo);
+                    udiv_qrnnd (Q, rem, hi, lo, Q1);
+                    assert (rem =3D=3D 0);
+                  }
+
+                  for (;;)
+                    {
+                      uintmax_t r;
+
+                      /* Note: There appears to by a typo in the paper,
+                         Step 4a in the algorithm description says q <--
+                         floor([S+P]/\hat Q), but looking at the equations
+                         in Sec. 3.1, it should be q <-- floor([S+P] / Q).
+                         (In this code, \hat Q is Q1). */
+                      div_smallq (q, r, S+P, Q);
+                      P1 =3D S - r;       /* P1 =3D q*Q - P */
+
+#if STAT_SQUFOF
+                      q_freq[0]++;
+                      q_freq[MIN(q, Q_FREQ_SIZE)]++;
+#endif
+                      if (P =3D=3D P1)
+                        break;
+                      t =3D Q1 + q * (P - P1);
+                      Q1 =3D Q;
+                      Q =3D t;
+                      P =3D P1;
+                    }
+
+                  if ( (Q & 1) =3D=3D 0)
+                    Q /=3D 2;
+                  Q /=3D gcd_odd (Q, mu);
+
+                  assert (Q > 1 && (n1 || Q < n0));
+
+                  if (prime_p (Q))
+                    factor_insert (factors, Q);
+                  else
+                    factor_using_squfof (0, Q, factors);
+
+                  divexact_21 (n1, n0, n1, n0, Q);
+
+                  if (prime2_p (n1, n0))
+                    factor_insert_large (factors, n1, n0);
+                  else
+                    {
+                      if (n1 =3D=3D 0)
+                        factor_using_pollard_rho (n0, 1, factors);
+                      else
+                        factor_using_squfof (n1, n0, factors);
+                    }
+
+                  return;
+                }
+            }
+        next_i:
+          ;
+        }
+    next_multiplier:
+      ;
+    }
+  fprintf (stderr, "squfof failed.\n");
+  exit (EXIT_FAILURE);
+}
+
+static void
+factor (uintmax_t t1, uintmax_t t0, struct factors *factors)
+{
+  factors->nfactors =3D 0;
+  factors->plarge[1] =3D 0;
+
+  if (t1 =3D=3D 0 && t0 < 2)
+    return;
+
+  t0 =3D factor_using_division (&t1, t1, t0, factors);
+
+  if (t1 =3D=3D 0)
+    {
+      if (t0 !=3D 1)
+        {
+          if (prime_p (t0))
+            factor_insert (factors, t0);
+          else if (alg =3D=3D ALG_POLLARD_RHO)
+            factor_using_pollard_rho (t0, 1, factors);
+          else
+            factor_using_squfof (0, t0, factors);
+        }
+    }
+  else
+    {
+      if (prime2_p (t1, t0))
+        factor_insert_large (factors, t1, t0);
+      else if (alg =3D=3D ALG_POLLARD_RHO)
+        factor_using_pollard_rho2 (t1, t0, 1, factors);
+      else
+        factor_using_squfof (t1, t0, factors);
+    }
+}
+
+#if HAVE_GMP
+static void
+mp_factor (mpz_t t, struct mp_factors *factors)
+{
+  mp_factor_init (factors);
+
+  if (mpz_sgn (t) !=3D 0)
+    {
+      mp_factor_using_division (t, factors);
+
+      if (mpz_cmp_ui (t, 1) !=3D 0)
+        {
+          if (flag_verbose > 0)
+            {
+              printf ("[is number prime?] ");
+            }
+          if (mp_prime_p (t))
+            mp_factor_insert (factors, t);
+          else
+            mp_factor_using_pollard_rho (t, 1, factors);
+        }
+    }
+}
+#endif
+
+static int
+strto2uintmax (uintmax_t *hip, uintmax_t *lop, const char *s)
+{
+  int errcode;
+  unsigned int lo_carry;
+  uintmax_t hi, lo;
+
+  errcode =3D -1;
+
+  hi =3D lo =3D 0;
+  for (;;)
+    {
+      unsigned int c =3D *s++;
+      if (c =3D=3D 0)
+        break;
+
+      if (UNLIKELY (c < '0' || c > '9'))
+        {
+          errcode =3D -1;
+          break;
+        }
+      c -=3D '0';
+
+      errcode =3D 0;              /* we've seen at least one valid digit */
+
+      if (UNLIKELY (hi > ~(uintmax_t)0 / 10))
+        {
+          errcode =3D -1; /* overflow */
+          break;
+        }
+      hi =3D 10 * hi;
+
+      lo_carry =3D (lo >> (W_TYPE_SIZE - 3)) + (lo >> (W_TYPE_SIZE - 1));
+      lo_carry +=3D 10 * lo < 2 * lo;
+
+      lo =3D 10 * lo;
+      lo +=3D c;
+
+      lo_carry +=3D lo < c;
+      hi +=3D lo_carry;
+      if (UNLIKELY (hi < lo_carry))
+        {
+          errcode =3D -1; /* overflow */
+          break;
+        }
+    }
+
+  *hip =3D hi;
+  *lop =3D lo;
+
+  return errcode;
+}
+
+static void
+print_uintmaxes (uintmax_t t1, uintmax_t t0)
+{
+  uintmax_t q, r;
+
+  if (t1 =3D=3D 0)
+    printf ("%ju", t0);
+  else
+    {
+      /* Use very plain code here since it seems hard to write fast code
+         without assuming a specific word size.  */
+      q =3D t1 / 1000000000;
+      r =3D t1 % 1000000000;
+      udiv_qrnnd (t0, r, r, t0, 1000000000);
+      print_uintmaxes (q, t0);
+      printf ("%09u", (int) r);
+    }
+}
+
+static void
+factor_one (const char *input)
+{
+  uintmax_t t1, t0;
+  int errcode;
+
+  /* Try converting the number to one or two words.  If it fails, use GMP =
or
+     print an error message.  The 2nd condition checks that the most
+     significant bit of the two-word number is clear, in a typesize neutral
+     way.  */
+  errcode =3D strto2uintmax (&t1, &t0, input);
+  if (errcode =3D=3D 0 && ((t1 << 1) >> 1) =3D=3D t1)
+    {
+      struct factors factors;
+
+      print_uintmaxes (t1, t0);
+      printf (":");
+
+      factor (t1, t0, &factors);
+
+      for (unsigned int j =3D 0; j < factors.nfactors; j++)
+        for (unsigned int k =3D 0; k < factors.e[j]; k++)
+          printf (" %ju", factors.p[j]);
+
+      if (factors.plarge[1])
+        {
+          printf (" ");
+          print_uintmaxes (factors.plarge[1], factors.plarge[0]);
+        }
+      puts ("");
+    }
+  else
+    {
+#if HAVE_GMP
+      mpz_t t;
+      struct mp_factors factors;
+
+      mpz_init_set_str (t, input, 10);
+
+      gmp_printf ("%Zd:", t);
+      mp_factor (t, &factors);
+
+      for (unsigned int j =3D 0; j < factors.nfactors; j++)
+        for (unsigned int k =3D 0; k < factors.e[j]; k++)
+          gmp_printf (" %Zd", factors.p[j]);
+
+      mp_factor_clear (&factors);
+      mpz_clear (t);
+      puts ("");
+#else
+      fprintf (stderr, "error: number %s not parsable or too large\n", inp=
ut);
+      exit (EXIT_FAILURE);
+#endif
+    }
+}
+
+struct inbuf
+{
+  char *buf;
+  size_t alloc;
+};
+
+/* Read white-space delimited items. Return 1 on success, 0 on EOF.
+   Exit on I/O errors. */
+int
+read_item (struct inbuf *bufstruct)
+{
+  int c;
+  size_t i;
+  char *buf =3D bufstruct->buf;
+
+  do
+    c =3D getchar_unlocked ();
+  while (isspace (c));
+
+  for (i =3D 0; !isspace(c); i++)
+    {
+      if (c < 0)
+        {
+          if (ferror (stdin))
+            {
+              fprintf (stderr, "read error on stdin: %s\n", strerror(errno=
));
+              exit (EXIT_FAILURE);
+            }
+          if (i =3D=3D 0)
+            return 0;
+          else
+            break;
+        }
+
+      if (UNLIKELY (bufstruct->alloc <=3D i + 1)) /* +1 byte for terminati=
ng NUL */
+        {
+          bufstruct->alloc =3D bufstruct->alloc * 5 / 4 + 1;
+          bufstruct->buf =3D realloc (bufstruct->buf, bufstruct->alloc);
+          buf =3D bufstruct->buf;
+        }
+
+      buf[i] =3D c;
+      c =3D getchar_unlocked ();
+    }
+
+  buf[i] =3D '\0';
+  return 1;
+}
+
+int
+main (int argc, char *argv[])
+{
+  int c;
+
+  alg =3D ALG_POLLARD_RHO;        /* Default to Pollard rho */
+
+  while ( (c =3D getopt(argc, argv, "svw")) !=3D -1)
+    switch (c)
+      {
+      case 's':
+        alg =3D ALG_SQUFOF;
+        break;
+      case 'v':
+        flag_verbose =3D 1;
+        break;
+      case 'w':
+        flag_prove_primality =3D 0;
+        break;
+      case '?':
+        printf ("Usage: %s [-s] number ...\n", argv[0]);
+        return EXIT_FAILURE;
+      }
+#if STAT_SQUFOF
+  if (alg =3D=3D ALG_SQUFOF)
+    memset (q_freq, 0, sizeof (q_freq));
+#endif
+
+  if (optind < argc)
+    for (int i =3D optind; i < argc; i++)
+      factor_one (argv[i]);
+  else
+    {
+      struct inbuf bufstruct;
+      bufstruct.alloc =3D 50;     /* enough unless HAVE_GMP */
+      bufstruct.buf =3D malloc (bufstruct.alloc);
+      while (read_item (&bufstruct))
+        factor_one (bufstruct.buf);
+    }
+
+#if STAT_SQUFOF
+  if (alg =3D=3D ALG_SQUFOF && q_freq[0] > 0)
+    {
+      double acc_f;
+      printf ("q  freq.  cum. freq.(total: %d)\n", q_freq[0]);
+      for (unsigned int i =3D 1, acc_f =3D 0.0; i <=3D Q_FREQ_SIZE; i++)
+        {
+          double f =3D (double) q_freq[i] / q_freq[0];
+          acc_f +=3D f;
+          printf ("%s%d %.2f%% %.2f%%\n", i =3D=3D Q_FREQ_SIZE ? ">=3D" : =
"", i,
+                  100.0 * f, 100.0 * acc_f);
+        }
+    }
+#endif
+
+  exit (EXIT_SUCCESS);
+}
diff --git a/src/longlong.h b/src/longlong.h
new file mode 100644
index 0000000..84e32ee
--- /dev/null
+++ b/src/longlong.h
@@ -0,0 +1,2156 @@
+/* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
+
+Copyright 1991, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001, 2002, 2003,
+2004, 2005, 2007, 2008, 2009, 2011 Free Software Foundation, Inc.
+
+This file is free software; you can redistribute it and/or modify it under=
 the
+terms of the GNU Lesser General Public License as published by the Free
+Software Foundation; either version 3 of the License, or (at your option) =
any
+later version.
+
+This file is distributed in the hope that it will be useful, but WITHOUT A=
NY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS =
FOR A
+PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this file.  If not, see http://www.gnu.org/licenses/.  */
+
+/* You have to define the following before including this file:
+
+   UWtype -- An unsigned type, default type for operations (typically a "w=
ord")
+   UHWtype -- An unsigned type, at least half the size of UWtype
+   UDWtype -- An unsigned type, at least twice as large a UWtype
+   W_TYPE_SIZE -- size in bits of UWtype
+
+   SItype, USItype -- Signed and unsigned 32 bit types
+   DItype, UDItype -- Signed and unsigned 64 bit types
+
+   On a 32 bit machine UWtype should typically be USItype;
+   on a 64 bit machine, UWtype should typically be UDItype.
+
+   Optionally, define:
+
+   LONGLONG_STANDALONE -- Avoid code that needs machine-dependent support =
files
+   NO_ASM -- Disable inline asm
+
+
+   CAUTION!  Using this version of longlong.h outside of GMP is not safe. =
 You
+   need to include gmp.h and gmp-impl.h, or certain things might not work =
as
+   expected.
+*/
+
+#define __BITS4 (W_TYPE_SIZE / 4)
+#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
+#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
+#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
+
+/* This is used to make sure no undesirable sharing between different libr=
aries
+   that use this file takes place.  */
+#ifndef __MPN
+#define __MPN(x) __##x
+#endif
+
+/* Define auxiliary asm macros.
+
+   1) umul_ppmm(high_prod, low_prod, multiplier, multiplicand) multiplies =
two
+   UWtype integers MULTIPLIER and MULTIPLICAND, and generates a two UWtype
+   word product in HIGH_PROD and LOW_PROD.
+
+   2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns=
 a
+   UDWtype product.  This is just a variant of umul_ppmm.
+
+   3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
+   denominator) divides a UDWtype, composed by the UWtype integers
+   HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
+   in QUOTIENT and the remainder in REMAINDER.  HIGH_NUMERATOR must be less
+   than DENOMINATOR for correct operation.  If, in addition, the most
+   significant bit of DENOMINATOR must be 1, then the pre-processor symbol
+   UDIV_NEEDS_NORMALIZATION is defined to 1.
+
+   4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
+   denominator).  Like udiv_qrnnd but the numbers are signed.  The quotient
+   is rounded towards 0.
+
+   5) count_leading_zeros(count, x) counts the number of zero-bits from the
+   msb to the first non-zero bit in the UWtype X.  This is the number of
+   steps X needs to be shifted left to set the msb.  Undefined for X =3D=
=3D 0,
+   unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
+
+   6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
+   from the least significant end.
+
+   7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
+   high_addend_2, low_addend_2) adds two UWtype integers, composed by
+   HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
+   respectively.  The result is placed in HIGH_SUM and LOW_SUM.  Overflow
+   (i.e. carry out) is not stored anywhere, and is lost.
+
+   8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuen=
d,
+   high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
+   composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
+   LOW_SUBTRAHEND_2 respectively.  The result is placed in HIGH_DIFFERENCE
+   and LOW_DIFFERENCE.  Overflow (i.e. carry out) is not stored anywhere,
+   and is lost.
+
+   If any of these macros are left undefined for a particular CPU,
+   C macros are used.
+
+
+   Notes:
+
+   For add_ssaaaa the two high and two low addends can both commute, but
+   unfortunately gcc only supports one "%" commutative in each asm block.
+   This has always been so but is only documented in recent versions
+   (eg. pre-release 3.3).  Having two or more "%"s can cause an internal
+   compiler error in certain rare circumstances.
+
+   Apparently it was only the last "%" that was ever actually respected, so
+   the code has been updated to leave just that.  Clearly there's a free
+   choice whether high or low should get it, if there's a reason to favour
+   one over the other.  Also obviously when the constraints on the two
+   operands are identical there's no benefit to the reloader in any "%" at
+   all.
+
+   */
+
+/* The CPUs come in alphabetical order below.
+
+   Please add support for more CPUs here, or improve the current support
+   for the CPUs below!  */
+
+
+/* count_leading_zeros_gcc_clz is count_leading_zeros implemented with gcc
+   3.4 __builtin_clzl or __builtin_clzll, according to our limb size.
+   Similarly count_trailing_zeros_gcc_ctz using __builtin_ctzl or
+   __builtin_ctzll.
+
+   These builtins are only used when we check what code comes out, on some
+   chips they're merely libgcc calls, where we will instead want an inline
+   in that case (either asm or generic C).
+
+   These builtins are better than an asm block of the same insn, since an
+   asm block doesn't give gcc any information about scheduling or resource
+   usage.  We keep an asm block for use on prior versions of gcc though.
+
+   For reference, __builtin_ffs existed in gcc prior to __builtin_clz, but
+   it's not used (for count_leading_zeros) because it generally gives extra
+   code to ensure the result is 0 when the input is 0, which we don't need
+   or want.  */
+
+#ifdef _LONG_LONG_LIMB
+#define count_leading_zeros_gcc_clz(count,x)    \
+  do {                                          \
+    ASSERT ((x) !=3D 0);                          \
+    (count) =3D __builtin_clzll (x);              \
+  } while (0)
+#else
+#define count_leading_zeros_gcc_clz(count,x)    \
+  do {                                          \
+    ASSERT ((x) !=3D 0);                          \
+    (count) =3D __builtin_clzl (x);               \
+  } while (0)
+#endif
+
+#ifdef _LONG_LONG_LIMB
+#define count_trailing_zeros_gcc_ctz(count,x)   \
+  do {                                          \
+    ASSERT ((x) !=3D 0);                          \
+    (count) =3D __builtin_ctzll (x);              \
+  } while (0)
+#else
+#define count_trailing_zeros_gcc_ctz(count,x)   \
+  do {                                          \
+    ASSERT ((x) !=3D 0);                          \
+    (count) =3D __builtin_ctzl (x);               \
+  } while (0)
+#endif
+
+
+/* FIXME: The macros using external routines like __MPN(count_leading_zero=
s)
+   don't need to be under !NO_ASM */
+#if ! defined (NO_ASM)
+
+#if defined (__alpha) && W_TYPE_SIZE =3D=3D 64
+/* Most alpha-based machines, except Cray systems. */
+#if defined (__GNUC__)
+#if __GMP_GNUC_PREREQ (3,3)
+#define umul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    UDItype __m0 =3D (m0), __m1 =3D (m1);					\
+    (ph) =3D __builtin_alpha_umulh (__m0, __m1);				\
+    (pl) =3D __m0 * __m1;							\
+  } while (0)
+#else
+#define umul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    UDItype __m0 =3D (m0), __m1 =3D (m1);					\
+    __asm__ ("umulh %r1,%2,%0"						\
+	     : "=3Dr" (ph)						\
+	     : "%rJ" (m0), "rI" (m1));					\
+    (pl) =3D __m0 * __m1;							\
+  } while (0)
+#endif
+#define UMUL_TIME 18
+#else /* ! __GNUC__ */
+#include <machine/builtins.h>
+#define umul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    UDItype __m0 =3D (m0), __m1 =3D (m1);					\
+    (ph) =3D __UMULH (m0, m1);						\
+    (pl) =3D __m0 * __m1;							\
+  } while (0)
+#endif
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  do { UWtype __di;							\
+    __di =3D __MPN(invert_limb) (d);					\
+    udiv_qrnnd_preinv (q, r, n1, n0, d, __di);				\
+  } while (0)
+#define UDIV_PREINV_ALWAYS  1
+#define UDIV_NEEDS_NORMALIZATION 1
+#define UDIV_TIME 220
+#endif /* LONGLONG_STANDALONE */
+
+/* clz_tab is required in all configurations, since mpn/alpha/cntlz.asm
+   always goes into libgmp.so, even when not actually used.  */
+#define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+
+#if defined (__GNUC__) && HAVE_HOST_CPU_alpha_CIX
+#define count_leading_zeros(COUNT,X) \
+  __asm__("ctlz %1,%0" : "=3Dr"(COUNT) : "r"(X))
+#define count_trailing_zeros(COUNT,X) \
+  __asm__("cttz %1,%0" : "=3Dr"(COUNT) : "r"(X))
+#endif /* clz/ctz using cix */
+
+#if ! defined (count_leading_zeros)                             \
+  && defined (__GNUC__) && ! defined (LONGLONG_STANDALONE)
+/* ALPHA_CMPBGE_0 gives "cmpbge $31,src,dst", ie. test src bytes =3D=3D 0.
+   "$31" is written explicitly in the asm, since an "r" constraint won't
+   select reg 31.  There seems no need to worry about "r31" syntax for cra=
y,
+   since gcc itself (pre-release 3.4) emits just $31 in various places.  */
+#define ALPHA_CMPBGE_0(dst, src)                                        \
+  do { asm ("cmpbge $31, %1, %0" : "=3Dr" (dst) : "r" (src)); } while (0)
+/* Zero bytes are turned into bits with cmpbge, a __clz_tab lookup counts
+   them, locating the highest non-zero byte.  A second __clz_tab lookup
+   counts the leading zero bits in that byte, giving the result.  */
+#define count_leading_zeros(count, x)                                   \
+  do {                                                                  \
+    UWtype  __clz__b, __clz__c, __clz__x =3D (x);                         \
+    ALPHA_CMPBGE_0 (__clz__b,  __clz__x);           /* zero bytes */    \
+    __clz__b =3D __clz_tab [(__clz__b >> 1) ^ 0x7F];  /* 8 to 1 byte */   \
+    __clz__b =3D __clz__b * 8 - 7;                    /* 57 to 1 shift */ \
+    __clz__x >>=3D __clz__b;                                              \
+    __clz__c =3D __clz_tab [__clz__x];                /* 8 to 1 bit */    \
+    __clz__b =3D 65 - __clz__b;                                           \
+    (count) =3D __clz__b - __clz__c;                                      \
+  } while (0)
+#define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+#endif /* clz using cmpbge */
+
+#if ! defined (count_leading_zeros) && ! defined (LONGLONG_STANDALONE)
+#if HAVE_ATTRIBUTE_CONST
+long __MPN(count_leading_zeros) (UDItype) __attribute__ ((const));
+#else
+long __MPN(count_leading_zeros) (UDItype);
+#endif
+#define count_leading_zeros(count, x) \
+  ((count) =3D __MPN(count_leading_zeros) (x))
+#endif /* clz using mpn */
+#endif /* __alpha */
+
+#if defined (__AVR) && W_TYPE_SIZE =3D=3D 8
+#define umul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    unsigned short __p =3D (unsigned short) (m0) * (m1);			\
+    (ph) =3D __p >> 8;							\
+    (pl) =3D __p;								\
+  } while (0)
+#endif /* AVR */
+
+#if defined (_CRAY) && W_TYPE_SIZE =3D=3D 64
+#include <intrinsics.h>
+#define UDIV_PREINV_ALWAYS  1
+#define UDIV_NEEDS_NORMALIZATION 1
+#define UDIV_TIME 220
+long __MPN(count_leading_zeros) (UDItype);
+#define count_leading_zeros(count, x) \
+  ((count) =3D _leadz ((UWtype) (x)))
+#if defined (_CRAYIEEE)		/* I.e., Cray T90/ieee, T3D, and T3E */
+#define umul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    UDItype __m0 =3D (m0), __m1 =3D (m1);					\
+    (ph) =3D _int_mult_upper (m0, m1);					\
+    (pl) =3D __m0 * __m1;							\
+  } while (0)
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  do { UWtype __di;							\
+    __di =3D __MPN(invert_limb) (d);					\
+    udiv_qrnnd_preinv (q, r, n1, n0, d, __di);				\
+  } while (0)
+#endif /* LONGLONG_STANDALONE */
+#endif /* _CRAYIEEE */
+#endif /* _CRAY */
+
+#if defined (__ia64) && W_TYPE_SIZE =3D=3D 64
+/* This form encourages gcc (pre-release 3.4 at least) to emit predicated
+   "sub r=3Dr,r" and "sub r=3Dr,r,1", giving a 2 cycle latency.  The gener=
ic
+   code using "al<bl" arithmetically comes out making an actual 0 or 1 in a
+   register, which takes an extra cycle.  */
+#define sub_ddmmss(sh, sl, ah, al, bh, bl)      \
+  do {                                          \
+    UWtype __x;                                 \
+    __x =3D (al) - (bl);                          \
+    if ((al) < (bl))                            \
+      (sh) =3D (ah) - (bh) - 1;                   \
+    else                                        \
+      (sh) =3D (ah) - (bh);                       \
+    (sl) =3D __x;                                 \
+  } while (0)
+#if defined (__GNUC__) && ! defined (__INTEL_COMPILER)
+/* Do both product parts in assembly, since that gives better code with
+   all gcc versions.  Some callers will just use the upper part, and in
+   that situation we waste an instruction, but not any cycles.  */
+#define umul_ppmm(ph, pl, m0, m1) \
+    __asm__ ("xma.hu %0 =3D %2, %3, f0\n\txma.l %1 =3D %2, %3, f0"		\
+	     : "=3D&f" (ph), "=3Df" (pl)					\
+	     : "f" (m0), "f" (m1))
+#define UMUL_TIME 14
+#define count_leading_zeros(count, x) \
+  do {									\
+    UWtype _x =3D (x), _y, _a, _c;					\
+    __asm__ ("mux1 %0 =3D %1, @rev" : "=3Dr" (_y) : "r" (_x));		\
+    __asm__ ("czx1.l %0 =3D %1" : "=3Dr" (_a) : "r" (-_y | _y));		\
+    _c =3D (_a - 1) << 3;							\
+    _x >>=3D _c;								\
+    if (_x >=3D 1 << 4)							\
+      _x >>=3D 4, _c +=3D 4;						\
+    if (_x >=3D 1 << 2)							\
+      _x >>=3D 2, _c +=3D 2;						\
+    _c +=3D _x >> 1;							\
+    (count) =3D  W_TYPE_SIZE - 1 - _c;					\
+  } while (0)
+/* similar to what gcc does for __builtin_ffs, but 0 based rather than 1
+   based, and we don't need a special case for x=3D=3D0 here */
+#define count_trailing_zeros(count, x)					\
+  do {									\
+    UWtype __ctz_x =3D (x);						\
+    __asm__ ("popcnt %0 =3D %1"						\
+	     : "=3Dr" (count)						\
+	     : "r" ((__ctz_x-1) & ~__ctz_x));				\
+  } while (0)
+#endif
+#if defined (__INTEL_COMPILER)
+#include <ia64intrin.h>
+#define umul_ppmm(ph, pl, m0, m1)					\
+  do {									\
+    UWtype _m0 =3D (m0), _m1 =3D (m1);					\
+    ph =3D _m64_xmahu (_m0, _m1, 0);					\
+    pl =3D _m0 * _m1;							\
+  } while (0)
+#endif
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  do { UWtype __di;							\
+    __di =3D __MPN(invert_limb) (d);					\
+    udiv_qrnnd_preinv (q, r, n1, n0, d, __di);				\
+  } while (0)
+#define UDIV_PREINV_ALWAYS  1
+#define UDIV_NEEDS_NORMALIZATION 1
+#endif
+#define UDIV_TIME 220
+#endif
+
+
+#if defined (__GNUC__)
+
+/* We sometimes need to clobber "cc" with gcc2, but that would not be
+   understood by gcc1.  Use cpp to avoid major code duplication.  */
+#if __GNUC__ < 2
+#define __CLOBBER_CC
+#define __AND_CLOBBER_CC
+#else /* __GNUC__ >=3D 2 */
+#define __CLOBBER_CC : "cc"
+#define __AND_CLOBBER_CC , "cc"
+#endif /* __GNUC__ < 2 */
+
+#if (defined (__a29k__) || defined (_AM29K)) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("add %1,%4,%5\n\taddc %0,%2,%3"				\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "r" (ah), "rI" (bh), "%r" (al), "rI" (bl))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("sub %1,%4,%5\n\tsubc %0,%2,%3"				\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "r" (ah), "rI" (bh), "r" (al), "rI" (bl))
+#define umul_ppmm(xh, xl, m0, m1) \
+  do {									\
+    USItype __m0 =3D (m0), __m1 =3D (m1);					\
+    __asm__ ("multiplu %0,%1,%2"					\
+	     : "=3Dr" (xl)						\
+	     : "r" (__m0), "r" (__m1));					\
+    __asm__ ("multmu %0,%1,%2"						\
+	     : "=3Dr" (xh)						\
+	     : "r" (__m0), "r" (__m1));					\
+  } while (0)
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  __asm__ ("dividu %0,%3,%4"						\
+	   : "=3Dr" (q), "=3Dq" (r)						\
+	   : "1" (n1), "r" (n0), "r" (d))
+#define count_leading_zeros(count, x) \
+    __asm__ ("clz %0,%1"						\
+	     : "=3Dr" (count)						\
+	     : "r" (x))
+#define COUNT_LEADING_ZEROS_0 32
+#endif /* __a29k__ */
+
+#if defined (__arc__)
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("add.f\t%1, %4, %5\n\tadc\t%0, %2, %3"			\
+	   : "=3Dr" (sh),							\
+	     "=3D&r" (sl)							\
+	   : "r"  ((USItype) (ah)),					\
+	     "rIJ" ((USItype) (bh)),					\
+	     "%r" ((USItype) (al)),					\
+	     "rIJ" ((USItype) (bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("sub.f\t%1, %4, %5\n\tsbc\t%0, %2, %3"			\
+	   : "=3Dr" (sh),							\
+	     "=3D&r" (sl)							\
+	   : "r" ((USItype) (ah)),					\
+	     "rIJ" ((USItype) (bh)),					\
+	     "r" ((USItype) (al)),					\
+	     "rIJ" ((USItype) (bl)))
+#endif
+
+#if defined (__arm__) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("adds\t%1, %4, %5\n\tadc\t%0, %2, %3"			\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "r" (ah), "rI" (bh), "%r" (al), "rI" (bl) __CLOBBER_CC)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  do {									\
+    if (__builtin_constant_p (al))					\
+      {									\
+	if (__builtin_constant_p (ah))					\
+	  __asm__ ("rsbs\t%1, %5, %4\n\trsc\t%0, %3, %2"		\
+		   : "=3Dr" (sh), "=3D&r" (sl)				\
+		   : "rI" (ah), "r" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
+	else								\
+	  __asm__ ("rsbs\t%1, %5, %4\n\tsbc\t%0, %2, %3"		\
+		   : "=3Dr" (sh), "=3D&r" (sl)				\
+		   : "r" (ah), "rI" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
+      }									\
+    else if (__builtin_constant_p (ah))					\
+      {									\
+	if (__builtin_constant_p (bl))					\
+	  __asm__ ("subs\t%1, %4, %5\n\trsc\t%0, %3, %2"		\
+		   : "=3Dr" (sh), "=3D&r" (sl)				\
+		   : "rI" (ah), "r" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
+	else								\
+	  __asm__ ("rsbs\t%1, %5, %4\n\trsc\t%0, %3, %2"		\
+		   : "=3Dr" (sh), "=3D&r" (sl)				\
+		   : "rI" (ah), "r" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
+      }									\
+    else if (__builtin_constant_p (bl))					\
+      {									\
+	if (__builtin_constant_p (bh))					\
+	  __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3"		\
+		   : "=3Dr" (sh), "=3D&r" (sl)				\
+		   : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
+	else								\
+	  __asm__ ("subs\t%1, %4, %5\n\trsc\t%0, %3, %2"		\
+		   : "=3Dr" (sh), "=3D&r" (sl)				\
+		   : "rI" (ah), "r" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
+      }									\
+    else /* only bh might be a constant */				\
+      __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3"			\
+	       : "=3Dr" (sh), "=3D&r" (sl)					\
+	       : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC);\
+    } while (0)
+#if 1 || defined (__arm_m__)	/* `M' series has widening multiply support */
+#define umul_ppmm(xh, xl, a, b) \
+  __asm__ ("umull %0,%1,%2,%3" : "=3D&r" (xl), "=3D&r" (xh) : "r" (a), "r"=
 (b))
+#define UMUL_TIME 5
+#define smul_ppmm(xh, xl, a, b) \
+  __asm__ ("smull %0,%1,%2,%3" : "=3D&r" (xl), "=3D&r" (xh) : "r" (a), "r"=
 (b))
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  do { UWtype __di;							\
+    __di =3D __MPN(invert_limb) (d);					\
+    udiv_qrnnd_preinv (q, r, n1, n0, d, __di);				\
+  } while (0)
+#define UDIV_PREINV_ALWAYS  1
+#define UDIV_NEEDS_NORMALIZATION 1
+#define UDIV_TIME 70
+#endif /* LONGLONG_STANDALONE */
+#else
+#define umul_ppmm(xh, xl, a, b) \
+  __asm__ ("%@ Inlined umul_ppmm\n"					\
+"	mov	%|r0, %2, lsr #16\n"					\
+"	mov	%|r2, %3, lsr #16\n"					\
+"	bic	%|r1, %2, %|r0, lsl #16\n"				\
+"	bic	%|r2, %3, %|r2, lsl #16\n"				\
+"	mul	%1, %|r1, %|r2\n"					\
+"	mul	%|r2, %|r0, %|r2\n"					\
+"	mul	%|r1, %0, %|r1\n"					\
+"	mul	%0, %|r0, %0\n"						\
+"	adds	%|r1, %|r2, %|r1\n"					\
+"	addcs	%0, %0, #65536\n"					\
+"	adds	%1, %1, %|r1, lsl #16\n"				\
+"	adc	%0, %0, %|r1, lsr #16"					\
+	   : "=3D&r" (xh), "=3Dr" (xl)					\
+	   : "r" (a), "r" (b)						\
+	   : "r0", "r1", "r2")
+#define UMUL_TIME 20
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  do { UWtype __r;							\
+    (q) =3D __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d));			\
+    (r) =3D __r;								\
+  } while (0)
+extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, UWtype);
+#define UDIV_TIME 200
+#endif /* LONGLONG_STANDALONE */
+#endif
+/* This is a bizarre test, but GCC doesn't define useful common symbol. */
+#if defined (__ARM_ARCH_5__)  || defined (__ARM_ARCH_5T__) || \
+    defined (__ARM_ARCH_5E__) || defined (__ARM_ARCH_5TE__)|| \
+    defined (__ARM_ARCH_6__)  || defined (__ARM_ARCH_6J__) || \
+    defined (__ARM_ARCH_6K__) || defined (__ARM_ARCH_6Z__) || \
+    defined (__ARM_ARCH_6ZK__)|| defined (__ARM_ARCH_6T2__)|| \
+    defined (__ARM_ARCH_6M__) || defined (__ARM_ARCH_7__)  || \
+    defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7R__) || \
+    defined (__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__)
+#define count_leading_zeros(count, x) \
+  __asm__ ("clz\t%0, %1" : "=3Dr" (count) : "r" (x))
+#define COUNT_LEADING_ZEROS_0 32
+#endif
+#endif /* __arm__ */
+
+#if defined (__aarch64__) && W_TYPE_SIZE =3D=3D 64
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("adds\t%1, %4, %5\n\tadc\t%0, %2, %3"			\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "r" (ah), "rZ" (bh), "%r" (al), "rI" (bl) __CLOBBER_CC)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  do {									\
+    if (__builtin_constant_p (bl))					\
+      {									\
+	__asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3"			\
+		 : "=3Dr" (sh), "=3D&r" (sl)				\
+		 : "r" (ah), "r" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
+      }									\
+    else /* only bh might be a constant */				\
+      __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3"			\
+	       : "=3Dr" (sh), "=3D&r" (sl)					\
+	       : "r" (ah), "rZ" (bh), "r" (al), "rI" (bl) __CLOBBER_CC);\
+    } while (0)
+#define umul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    UDItype __m0 =3D (m0), __m1 =3D (m1);					\
+    __asm__ ("umulh\t%0, %1, %2" : "=3Dr" (ph) : "r" (m0), "r" (m1));	\
+    (pl) =3D __m0 * __m1;							\
+  } while (0)
+#define count_leading_zeros(count, x) \
+  __asm__ ("clz\t%0, %1" : "=3Dr" (count) : "r" (x))
+#define COUNT_LEADING_ZEROS_0 64
+#endif /* __aarch64__ */
+
+#if defined (__clipper__) && W_TYPE_SIZE =3D=3D 32
+#define umul_ppmm(w1, w0, u, v) \
+  ({union {UDItype __ll;						\
+	   struct {USItype __l, __h;} __i;				\
+	  } __x;							\
+  __asm__ ("mulwux %2,%0"						\
+	   : "=3Dr" (__x.__ll)						\
+	   : "%0" ((USItype)(u)), "r" ((USItype)(v)));			\
+  (w1) =3D __x.__i.__h; (w0) =3D __x.__i.__l;})
+#define smul_ppmm(w1, w0, u, v) \
+  ({union {DItype __ll;							\
+	   struct {SItype __l, __h;} __i;				\
+	  } __x;							\
+  __asm__ ("mulwx %2,%0"						\
+	   : "=3Dr" (__x.__ll)						\
+	   : "%0" ((SItype)(u)), "r" ((SItype)(v)));			\
+  (w1) =3D __x.__i.__h; (w0) =3D __x.__i.__l;})
+#define __umulsidi3(u, v) \
+  ({UDItype __w;							\
+    __asm__ ("mulwux %2,%0"						\
+	     : "=3Dr" (__w) : "%0" ((USItype)(u)), "r" ((USItype)(v)));	\
+    __w; })
+#endif /* __clipper__ */
+
+/* Fujitsu vector computers.  */
+#if defined (__uxp__) && W_TYPE_SIZE =3D=3D 32
+#define umul_ppmm(ph, pl, u, v) \
+  do {									\
+    union {UDItype __ll;						\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x;							\
+    __asm__ ("mult.lu %1,%2,%0"	: "=3Dr" (__x.__ll) : "%r" (u), "rK" (v));\
+    (ph) =3D __x.__i.__h;							\
+    (pl) =3D __x.__i.__l;							\
+  } while (0)
+#define smul_ppmm(ph, pl, u, v) \
+  do {									\
+    union {UDItype __ll;						\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x;							\
+    __asm__ ("mult.l %1,%2,%0" : "=3Dr" (__x.__ll) : "%r" (u), "rK" (v));	\
+    (ph) =3D __x.__i.__h;							\
+    (pl) =3D __x.__i.__l;							\
+  } while (0)
+#endif
+
+#if defined (__gmicro__) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("add.w %5,%1\n\taddx %3,%0"					\
+	   : "=3Dg" (sh), "=3D&g" (sl)					\
+	   : "0"  ((USItype)(ah)), "g" ((USItype)(bh)),			\
+	     "%1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("sub.w %5,%1\n\tsubx %3,%0"					\
+	   : "=3Dg" (sh), "=3D&g" (sl)					\
+	   : "0" ((USItype)(ah)), "g" ((USItype)(bh)),			\
+	     "1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define umul_ppmm(ph, pl, m0, m1) \
+  __asm__ ("mulx %3,%0,%1"						\
+	   : "=3Dg" (ph), "=3Dr" (pl)					\
+	   : "%0" ((USItype)(m0)), "g" ((USItype)(m1)))
+#define udiv_qrnnd(q, r, nh, nl, d) \
+  __asm__ ("divx %4,%0,%1"						\
+	   : "=3Dg" (q), "=3Dr" (r)						\
+	   : "1" ((USItype)(nh)), "0" ((USItype)(nl)), "g" ((USItype)(d)))
+#define count_leading_zeros(count, x) \
+  __asm__ ("bsch/1 %1,%0"						\
+	   : "=3Dg" (count) : "g" ((USItype)(x)), "0" ((USItype)0))
+#endif
+
+#if defined (__hppa) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("add%I5 %5,%r4,%1\n\taddc %r2,%r3,%0"			\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "rM" (ah), "rM" (bh), "%rM" (al), "rI" (bl))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("sub%I4 %4,%r5,%1\n\tsubb %r2,%r3,%0"			\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "rM" (ah), "rM" (bh), "rI" (al), "rM" (bl))
+#if defined (_PA_RISC1_1)
+#define umul_ppmm(wh, wl, u, v) \
+  do {									\
+    union {UDItype __ll;						\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x;							\
+    __asm__ ("xmpyu %1,%2,%0" : "=3D*f" (__x.__ll) : "*f" (u), "*f" (v));	\
+    (wh) =3D __x.__i.__h;							\
+    (wl) =3D __x.__i.__l;							\
+  } while (0)
+#define UMUL_TIME 8
+#define UDIV_TIME 60
+#else
+#define UMUL_TIME 40
+#define UDIV_TIME 80
+#endif
+#define count_leading_zeros(count, x) \
+  do {									\
+    USItype __tmp;							\
+    __asm__ (								\
+       "ldi		1,%0\n"						\
+"	extru,=3D		%1,15,16,%%r0	; Bits 31..16 zero?\n"		\
+"	extru,tr	%1,15,16,%1	; No.  Shift down, skip add.\n"	\
+"	ldo		16(%0),%0	; Yes.  Perform add.\n"		\
+"	extru,=3D		%1,23,8,%%r0	; Bits 15..8 zero?\n"		\
+"	extru,tr	%1,23,8,%1	; No.  Shift down, skip add.\n"	\
+"	ldo		8(%0),%0	; Yes.  Perform add.\n"		\
+"	extru,=3D		%1,27,4,%%r0	; Bits 7..4 zero?\n"		\
+"	extru,tr	%1,27,4,%1	; No.  Shift down, skip add.\n"	\
+"	ldo		4(%0),%0	; Yes.  Perform add.\n"		\
+"	extru,=3D		%1,29,2,%%r0	; Bits 3..2 zero?\n"		\
+"	extru,tr	%1,29,2,%1	; No.  Shift down, skip add.\n"	\
+"	ldo		2(%0),%0	; Yes.  Perform add.\n"		\
+"	extru		%1,30,1,%1	; Extract bit 1.\n"		\
+"	sub		%0,%1,%0	; Subtract it.\n"		\
+	: "=3Dr" (count), "=3Dr" (__tmp) : "1" (x));			\
+  } while (0)
+#endif /* hppa */
+
+/* These macros are for ABI=3D2.0w.  In ABI=3D2.0n they can't be used, sin=
ce GCC
+   (3.2) puts longlong into two adjacent 32-bit registers.  Presumably this
+   is just a case of no direct support for 2.0n but treating it like 1.0. =
*/
+#if defined (__hppa) && W_TYPE_SIZE =3D=3D 64 && ! defined (_LONG_LONG_LIM=
B)
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("add%I5 %5,%r4,%1\n\tadd,dc %r2,%r3,%0"			\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "rM" (ah), "rM" (bh), "%rM" (al), "rI" (bl))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("sub%I4 %4,%r5,%1\n\tsub,db %r2,%r3,%0"			\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "rM" (ah), "rM" (bh), "rI" (al), "rM" (bl))
+#endif /* hppa */
+
+#if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_T=
YPE_SIZE =3D=3D 32
+#if defined (__zarch__) || defined (HAVE_HOST_CPU_s390_zarch)
+#define add_ssaaaa(sh, sl, ah, al, bh, bl)				\
+  do {									\
+/*  if (__builtin_constant_p (bl))					\
+      __asm__ ("alfi\t%1,%o5\n\talcr\t%0,%3"				\
+	       : "=3Dr" (sh), "=3D&r" (sl)					\
+	       : "0"  (ah), "r" (bh), "%1" (al), "n" (bl) __CLOBBER_CC);\
+    else								\
+*/    __asm__ ("alr\t%1,%5\n\talcr\t%0,%3"				\
+	       : "=3Dr" (sh), "=3D&r" (sl)					\
+	       : "0"  (ah), "r" (bh), "%1" (al), "r" (bl)__CLOBBER_CC);	\
+  } while (0)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl)				\
+  do {									\
+/*  if (__builtin_constant_p (bl))					\
+      __asm__ ("slfi\t%1,%o5\n\tslbr\t%0,%3"				\
+	       : "=3Dr" (sh), "=3D&r" (sl)					\
+	       : "0" (ah), "r" (bh), "1" (al), "n" (bl) __CLOBBER_CC);	\
+    else								\
+*/    __asm__ ("slr\t%1,%5\n\tslbr\t%0,%3"				\
+	       : "=3Dr" (sh), "=3D&r" (sl)					\
+	       : "0" (ah), "r" (bh), "1" (al), "r" (bl) __CLOBBER_CC);	\
+  } while (0)
+#if __GMP_GNUC_PREREQ (4,5)
+#define umul_ppmm(xh, xl, m0, m1)					\
+  do {									\
+    union {UDItype __ll;						\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x;							\
+    __x.__ll =3D (UDItype) (m0) * (UDItype) (m1);				\
+    (xh) =3D __x.__i.__h; (xl) =3D __x.__i.__l;				\
+  } while (0)
+#else
+#if 0
+/* FIXME: this fails if gcc knows about the 64-bit registers.  Use only
+   with a new enough processor pretending we have 32-bit registers.  */
+#define umul_ppmm(xh, xl, m0, m1)					\
+  do {									\
+    union {UDItype __ll;						\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x;							\
+    __asm__ ("mlr\t%0,%2"						\
+	     : "=3Dr" (__x.__ll)						\
+	     : "%0" (m0), "r" (m1));					\
+    (xh) =3D __x.__i.__h; (xl) =3D __x.__i.__l;				\
+  } while (0)
+#else
+#define umul_ppmm(xh, xl, m0, m1)					\
+  do {									\
+  /* When we have 64-bit regs and gcc is aware of that, we cannot simply u=
se
+     DImode for the product, since that would be allocated to a single 64-=
bit
+     register, whereas mlr uses the low 32-bits of an even-odd register pa=
ir.
+  */									\
+    register USItype __r0 __asm__ ("0");				\
+    register USItype __r1 __asm__ ("1") =3D (m0);				\
+    __asm__ ("mlr\t%0,%3"						\
+	     : "=3Dr" (__r0), "=3Dr" (__r1)					\
+	     : "r" (__r1), "r" (m1));					\
+    (xh) =3D __r0; (xl) =3D __r1;						\
+  } while (0)
+#endif /* if 0 */
+#endif
+#if 0
+/* FIXME: this fails if gcc knows about the 64-bit registers.  Use only
+   with a new enough processor pretending we have 32-bit registers.  */
+#define udiv_qrnnd(q, r, n1, n0, d)					\
+  do {									\
+    union {UDItype __ll;						\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x;							\
+    __x.__i.__h =3D n1; __x.__i.__l =3D n0;					\
+    __asm__ ("dlr\t%0,%2"						\
+	     : "=3Dr" (__x.__ll)						\
+	     : "0" (__x.__ll), "r" (d));				\
+    (q) =3D __x.__i.__l; (r) =3D __x.__i.__h;				\
+  } while (0)
+#else
+#define udiv_qrnnd(q, r, n1, n0, d)					\
+  do {									\
+    register USItype __r0 __asm__ ("0") =3D (n1);				\
+    register USItype __r1 __asm__ ("1") =3D (n0);				\
+    __asm__ ("dlr\t%0,%4"						\
+	     : "=3Dr" (__r0), "=3Dr" (__r1)					\
+	     : "r" (__r0), "r" (__r1), "r" (d));			\
+    (q) =3D __r1; (r) =3D __r0;						\
+  } while (0)
+#endif /* if 0 */
+#else /* if __zarch__ */
+/* FIXME: this fails if gcc knows about the 64-bit registers.  */
+#define smul_ppmm(xh, xl, m0, m1)					\
+  do {									\
+    union {DItype __ll;							\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x;							\
+    __asm__ ("mr\t%0,%2"						\
+	     : "=3Dr" (__x.__ll)						\
+	     : "%0" (m0), "r" (m1));					\
+    (xh) =3D __x.__i.__h; (xl) =3D __x.__i.__l;				\
+  } while (0)
+/* FIXME: this fails if gcc knows about the 64-bit registers.  */
+#define sdiv_qrnnd(q, r, n1, n0, d)					\
+  do {									\
+    union {DItype __ll;							\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x;							\
+    __x.__i.__h =3D n1; __x.__i.__l =3D n0;					\
+    __asm__ ("dr\t%0,%2"						\
+	     : "=3Dr" (__x.__ll)						\
+	     : "0" (__x.__ll), "r" (d));				\
+    (q) =3D __x.__i.__l; (r) =3D __x.__i.__h;				\
+  } while (0)
+#endif /* if __zarch__ */
+#endif
+
+#if defined (__s390x__) && W_TYPE_SIZE =3D=3D 64
+/* We need to cast operands with register constraints, otherwise their typ=
es
+   will be assumed to be SImode by gcc.  For these machines, such operatio=
ns
+   will insert a value into the low 32 bits, and leave the high 32 bits wi=
th
+   garbage.  */
+#define add_ssaaaa(sh, sl, ah, al, bh, bl)				\
+  do {									\
+    __asm__ ("algr\t%1,%5\n\talcgr\t%0,%3"				\
+	       : "=3Dr" (sh), "=3D&r" (sl)					\
+	       : "0"  ((UDItype)(ah)), "r" ((UDItype)(bh)),		\
+		 "%1" ((UDItype)(al)), "r" ((UDItype)(bl)) __CLOBBER_CC); \
+  } while (0)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl)				\
+  do {									\
+    __asm__ ("slgr\t%1,%5\n\tslbgr\t%0,%3"				\
+	     : "=3Dr" (sh), "=3D&r" (sl)					\
+	     : "0" ((UDItype)(ah)), "r" ((UDItype)(bh)),		\
+	       "1" ((UDItype)(al)), "r" ((UDItype)(bl)) __CLOBBER_CC);	\
+  } while (0)
+#define umul_ppmm(xh, xl, m0, m1)					\
+  do {									\
+    union {unsigned int __attribute__ ((mode(TI))) __ll;		\
+	   struct {UDItype __h, __l;} __i;				\
+	  } __x;							\
+    __asm__ ("mlgr\t%0,%2"						\
+	     : "=3Dr" (__x.__ll)						\
+	     : "%0" ((UDItype)(m0)), "r" ((UDItype)(m1)));		\
+    (xh) =3D __x.__i.__h; (xl) =3D __x.__i.__l;				\
+  } while (0)
+#define udiv_qrnnd(q, r, n1, n0, d)					\
+  do {									\
+    union {unsigned int __attribute__ ((mode(TI))) __ll;		\
+	   struct {UDItype __h, __l;} __i;				\
+	  } __x;							\
+    __x.__i.__h =3D n1; __x.__i.__l =3D n0;					\
+    __asm__ ("dlgr\t%0,%2"						\
+	     : "=3Dr" (__x.__ll)						\
+	     : "0" (__x.__ll), "r" ((UDItype)(d)));			\
+    (q) =3D __x.__i.__l; (r) =3D __x.__i.__h;				\
+  } while (0)
+#if 0 /* FIXME: Enable for z10 (?) */
+#define count_leading_zeros(cnt, x)					\
+  do {									\
+    union {unsigned int __attribute__ ((mode(TI))) __ll;		\
+	   struct {UDItype __h, __l;} __i;				\
+	  } __clr_cnt;							\
+    __asm__ ("flogr\t%0,%1"						\
+	     : "=3Dr" (__clr_cnt.__ll)					\
+	     : "r" (x) __CLOBBER_CC);					\
+    (cnt) =3D __clr_cnt.__i.__h;						\
+  } while (0)
+#endif
+#endif
+
+#if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("addl %5,%k1\n\tadcl %3,%k0"					\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "0"  ((USItype)(ah)), "g" ((USItype)(bh)),			\
+	     "%1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("subl %5,%k1\n\tsbbl %3,%k0"					\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "0" ((USItype)(ah)), "g" ((USItype)(bh)),			\
+	     "1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("mull %3"							\
+	   : "=3Da" (w0), "=3Dd" (w1)					\
+	   : "%0" ((USItype)(u)), "rm" ((USItype)(v)))
+#define udiv_qrnnd(q, r, n1, n0, dx) /* d renamed to dx avoiding "=3Dd" */\
+  __asm__ ("divl %4"		     /* stringification in K&R C */	\
+	   : "=3Da" (q), "=3Dd" (r)						\
+	   : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "rm" ((USItype)(dx)))
+
+#if HAVE_HOST_CPU_i586 || HAVE_HOST_CPU_pentium || HAVE_HOST_CPU_pentiummmx
+/* Pentium bsrl takes between 10 and 72 cycles depending where the most
+   significant 1 bit is, hence the use of the following alternatives.  bsfl
+   is slow too, between 18 and 42 depending where the least significant 1
+   bit is, so let the generic count_trailing_zeros below make use of the
+   count_leading_zeros here too.  */
+
+#if HAVE_HOST_CPU_pentiummmx && ! defined (LONGLONG_STANDALONE)
+/* The following should be a fixed 14 or 15 cycles, but possibly plus an L1
+   cache miss reading from __clz_tab.  For P55 it's favoured over the float
+   below so as to avoid mixing MMX and x87, since the penalty for switching
+   between the two is about 100 cycles.
+
+   The asm block sets __shift to -3 if the high 24 bits are clear, -2 for
+   16, -1 for 8, or 0 otherwise.  This could be written equivalently as
+   follows, but as of gcc 2.95.2 it results in conditional jumps.
+
+       __shift =3D -(__n < 0x1000000);
+       __shift -=3D (__n < 0x10000);
+       __shift -=3D (__n < 0x100);
+
+   The middle two sbbl and cmpl's pair, and with luck something gcc
+   generates might pair with the first cmpl and the last sbbl.  The "32+1"
+   constant could be folded into __clz_tab[], but it doesn't seem worth
+   making a different table just for that.  */
+
+#define count_leading_zeros(c,n)					\
+  do {									\
+    USItype  __n =3D (n);							\
+    USItype  __shift;							\
+    __asm__ ("cmpl  $0x1000000, %1\n"					\
+	     "sbbl  %0, %0\n"						\
+	     "cmpl  $0x10000, %1\n"					\
+	     "sbbl  $0, %0\n"						\
+	     "cmpl  $0x100, %1\n"					\
+	     "sbbl  $0, %0\n"						\
+	     : "=3D&r" (__shift) : "r"  (__n));				\
+    __shift =3D __shift*8 + 24 + 1;					\
+    (c) =3D 32 + 1 - __shift - __clz_tab[__n >> __shift];			\
+  } while (0)
+#define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+#define COUNT_LEADING_ZEROS_0   31   /* n=3D=3D0 indistinguishable from n=
=3D=3D1 */
+
+#else /* ! pentiummmx || LONGLONG_STANDALONE */
+/* The following should be a fixed 14 cycles or so.  Some scheduling
+   opportunities should be available between the float load/store too.  Th=
is
+   sort of code is used in gcc 3 for __builtin_ffs (with "n&-n") and is
+   apparently suggested by the Intel optimizing manual (don't know exactly
+   where).  gcc 2.95 or up will be best for this, so the "double" is
+   correctly aligned on the stack.  */
+#define count_leading_zeros(c,n)					\
+  do {									\
+    union {								\
+      double    d;							\
+      unsigned  a[2];							\
+    } __u;								\
+    ASSERT ((n) !=3D 0);							\
+    __u.d =3D (UWtype) (n);						\
+    (c) =3D 0x3FF + 31 - (__u.a[1] >> 20);				\
+  } while (0)
+#define COUNT_LEADING_ZEROS_0   (0x3FF + 31)
+#endif /* pentiummx */
+
+#else /* ! pentium */
+
+#if __GMP_GNUC_PREREQ (3,4)  /* using bsrl */
+#define count_leading_zeros(count,x)  count_leading_zeros_gcc_clz(count,x)
+#endif /* gcc clz */
+
+/* On P6, gcc prior to 3.0 generates a partial register stall for
+   __cbtmp^31, due to using "xorb $31" instead of "xorl $31", the former
+   being 1 code byte smaller.  "31-__cbtmp" is a workaround, probably at t=
he
+   cost of one extra instruction.  Do this for "i386" too, since that means
+   generic x86.  */
+#if ! defined (count_leading_zeros) && __GNUC__ < 3                     \
+  && (HAVE_HOST_CPU_i386						\
+      || HAVE_HOST_CPU_i686						\
+      || HAVE_HOST_CPU_pentiumpro					\
+      || HAVE_HOST_CPU_pentium2						\
+      || HAVE_HOST_CPU_pentium3)
+#define count_leading_zeros(count, x)					\
+  do {									\
+    USItype __cbtmp;							\
+    ASSERT ((x) !=3D 0);							\
+    __asm__ ("bsrl %1,%0" : "=3Dr" (__cbtmp) : "rm" ((USItype)(x)));	\
+    (count) =3D 31 - __cbtmp;						\
+  } while (0)
+#endif /* gcc<3 asm bsrl */
+
+#ifndef count_leading_zeros
+#define count_leading_zeros(count, x)					\
+  do {									\
+    USItype __cbtmp;							\
+    ASSERT ((x) !=3D 0);							\
+    __asm__ ("bsrl %1,%0" : "=3Dr" (__cbtmp) : "rm" ((USItype)(x)));	\
+    (count) =3D __cbtmp ^ 31;						\
+  } while (0)
+#endif /* asm bsrl */
+
+#if __GMP_GNUC_PREREQ (3,4)  /* using bsfl */
+#define count_trailing_zeros(count,x)  count_trailing_zeros_gcc_ctz(count,=
x)
+#endif /* gcc ctz */
+
+#ifndef count_trailing_zeros
+#define count_trailing_zeros(count, x)					\
+  do {									\
+    ASSERT ((x) !=3D 0);							\
+    __asm__ ("bsfl %1,%k0" : "=3Dr" (count) : "rm" ((USItype)(x)));	\
+  } while (0)
+#endif /* asm bsfl */
+
+#endif /* ! pentium */
+
+#ifndef UMUL_TIME
+#define UMUL_TIME 10
+#endif
+#ifndef UDIV_TIME
+#define UDIV_TIME 40
+#endif
+#endif /* 80x86 */
+
+#if defined (__amd64__) && W_TYPE_SIZE =3D=3D 64
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("addq %5,%q1\n\tadcq %3,%q0"					\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "0"  ((UDItype)(ah)), "rme" ((UDItype)(bh)),		\
+	     "%1" ((UDItype)(al)), "rme" ((UDItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("subq %5,%q1\n\tsbbq %3,%q0"					\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "0" ((UDItype)(ah)), "rme" ((UDItype)(bh)),		\
+	     "1" ((UDItype)(al)), "rme" ((UDItype)(bl)))
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("mulq %3"							\
+	   : "=3Da" (w0), "=3Dd" (w1)					\
+	   : "%0" ((UDItype)(u)), "rm" ((UDItype)(v)))
+#define udiv_qrnnd(q, r, n1, n0, dx) /* d renamed to dx avoiding "=3Dd" */\
+  __asm__ ("divq %4"		     /* stringification in K&R C */	\
+	   : "=3Da" (q), "=3Dd" (r)						\
+	   : "0" ((UDItype)(n0)), "1" ((UDItype)(n1)), "rm" ((UDItype)(dx)))
+/* bsrq destination must be a 64-bit register, hence UDItype for __cbtmp. =
*/
+#define count_leading_zeros(count, x)					\
+  do {									\
+    UDItype __cbtmp;							\
+    ASSERT ((x) !=3D 0);							\
+    __asm__ ("bsrq %1,%0" : "=3Dr" (__cbtmp) : "rm" ((UDItype)(x)));	\
+    (count) =3D __cbtmp ^ 63;						\
+  } while (0)
+/* bsfq destination must be a 64-bit register, "%q0" forces this in case
+   count is only an int. */
+#define count_trailing_zeros(count, x)					\
+  do {									\
+    ASSERT ((x) !=3D 0);							\
+    __asm__ ("bsfq %1,%q0" : "=3Dr" (count) : "rm" ((UDItype)(x)));	\
+  } while (0)
+#endif /* x86_64 */
+
+#if defined (__i860__) && W_TYPE_SIZE =3D=3D 32
+#define rshift_rhlc(r,h,l,c) \
+  __asm__ ("shr %3,r0,r0\;shrd %1,%2,%0"				\
+	   "=3Dr" (r) : "r" (h), "r" (l), "rn" (c))
+#endif /* i860 */
+
+#if defined (__i960__) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("cmpo 1,0\;addc %5,%4,%1\;addc %3,%2,%0"			\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "dI" (ah), "dI" (bh), "%dI" (al), "dI" (bl))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("cmpo 0,0\;subc %5,%4,%1\;subc %3,%2,%0"			\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "dI" (ah), "dI" (bh), "dI" (al), "dI" (bl))
+#define umul_ppmm(w1, w0, u, v) \
+  ({union {UDItype __ll;						\
+	   struct {USItype __l, __h;} __i;				\
+	  } __x;							\
+  __asm__ ("emul %2,%1,%0"						\
+	   : "=3Dd" (__x.__ll) : "%dI" (u), "dI" (v));			\
+  (w1) =3D __x.__i.__h; (w0) =3D __x.__i.__l;})
+#define __umulsidi3(u, v) \
+  ({UDItype __w;							\
+    __asm__ ("emul %2,%1,%0" : "=3Dd" (__w) : "%dI" (u), "dI" (v));	\
+    __w; })
+#define udiv_qrnnd(q, r, nh, nl, d) \
+  do {									\
+    union {UDItype __ll;						\
+	   struct {USItype __l, __h;} __i;				\
+	  } __nn;							\
+    __nn.__i.__h =3D (nh); __nn.__i.__l =3D (nl);				\
+    __asm__ ("ediv %d,%n,%0"						\
+	   : "=3Dd" (__rq.__ll) : "dI" (__nn.__ll), "dI" (d));		\
+    (r) =3D __rq.__i.__l; (q) =3D __rq.__i.__h;				\
+  } while (0)
+#define count_leading_zeros(count, x) \
+  do {									\
+    USItype __cbtmp;							\
+    __asm__ ("scanbit %1,%0" : "=3Dr" (__cbtmp) : "r" (x));		\
+    (count) =3D __cbtmp ^ 31;						\
+  } while (0)
+#define COUNT_LEADING_ZEROS_0 (-32) /* sic */
+#if defined (__i960mx)		/* what is the proper symbol to test??? */
+#define rshift_rhlc(r,h,l,c) \
+  do {									\
+    union {UDItype __ll;						\
+	   struct {USItype __l, __h;} __i;				\
+	  } __nn;							\
+    __nn.__i.__h =3D (h); __nn.__i.__l =3D (l);				\
+    __asm__ ("shre %2,%1,%0" : "=3Dd" (r) : "dI" (__nn.__ll), "dI" (c));	\
+  }
+#endif /* i960mx */
+#endif /* i960 */
+
+#if (defined (__mc68000__) || defined (__mc68020__) || defined(mc68020) \
+     || defined (__m68k__) || defined (__mc5200__) || defined (__mc5206e__=
) \
+     || defined (__mc5307__)) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0"				\
+	   : "=3Dd" (sh), "=3D&d" (sl)					\
+	   : "0"  ((USItype)(ah)), "d" ((USItype)(bh)),			\
+	     "%1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0"				\
+	   : "=3Dd" (sh), "=3D&d" (sl)					\
+	   : "0" ((USItype)(ah)), "d" ((USItype)(bh)),			\
+	     "1" ((USItype)(al)), "g" ((USItype)(bl)))
+/* The '020, '030, '040 and CPU32 have 32x32->64 and 64/32->32q-32r.  */
+#if defined (__mc68020__) || defined(mc68020) \
+     || defined (__mc68030__) || defined (mc68030) \
+     || defined (__mc68040__) || defined (mc68040) \
+     || defined (__mcpu32__) || defined (mcpu32) \
+     || defined (__NeXT__)
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("mulu%.l %3,%1:%0"						\
+	   : "=3Dd" (w0), "=3Dd" (w1)					\
+	   : "%0" ((USItype)(u)), "dmi" ((USItype)(v)))
+#define UMUL_TIME 45
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  __asm__ ("divu%.l %4,%1:%0"						\
+	   : "=3Dd" (q), "=3Dd" (r)						\
+	   : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "dmi" ((USItype)(d)))
+#define UDIV_TIME 90
+#define sdiv_qrnnd(q, r, n1, n0, d) \
+  __asm__ ("divs%.l %4,%1:%0"						\
+	   : "=3Dd" (q), "=3Dd" (r)						\
+	   : "0" ((USItype)(n0)), "1" ((USItype)(n1)), "dmi" ((USItype)(d)))
+#else /* for other 68k family members use 16x16->32 multiplication */
+#define umul_ppmm(xh, xl, a, b) \
+  do { USItype __umul_tmp1, __umul_tmp2;				\
+	__asm__ ("| Inlined umul_ppmm\n"				\
+"	move%.l	%5,%3\n"						\
+"	move%.l	%2,%0\n"						\
+"	move%.w	%3,%1\n"						\
+"	swap	%3\n"							\
+"	swap	%0\n"							\
+"	mulu%.w	%2,%1\n"						\
+"	mulu%.w	%3,%0\n"						\
+"	mulu%.w	%2,%3\n"						\
+"	swap	%2\n"							\
+"	mulu%.w	%5,%2\n"						\
+"	add%.l	%3,%2\n"						\
+"	jcc	1f\n"							\
+"	add%.l	%#0x10000,%0\n"						\
+"1:	move%.l	%2,%3\n"						\
+"	clr%.w	%2\n"							\
+"	swap	%2\n"							\
+"	swap	%3\n"							\
+"	clr%.w	%3\n"							\
+"	add%.l	%3,%1\n"						\
+"	addx%.l	%2,%0\n"						\
+"	| End inlined umul_ppmm"					\
+	      : "=3D&d" (xh), "=3D&d" (xl),					\
+		"=3Dd" (__umul_tmp1), "=3D&d" (__umul_tmp2)			\
+	      : "%2" ((USItype)(a)), "d" ((USItype)(b)));		\
+  } while (0)
+#define UMUL_TIME 100
+#define UDIV_TIME 400
+#endif /* not mc68020 */
+/* The '020, '030, '040 and '060 have bitfield insns.
+   GCC 3.4 defines __mc68020__ when in CPU32 mode, check for __mcpu32__ to
+   exclude bfffo on that chip (bitfield insns not available).  */
+#if (defined (__mc68020__) || defined (mc68020)    \
+     || defined (__mc68030__) || defined (mc68030) \
+     || defined (__mc68040__) || defined (mc68040) \
+     || defined (__mc68060__) || defined (mc68060) \
+     || defined (__NeXT__))                        \
+  && ! defined (__mcpu32__)
+#define count_leading_zeros(count, x) \
+  __asm__ ("bfffo %1{%b2:%b2},%0"					\
+	   : "=3Dd" (count)						\
+	   : "od" ((USItype) (x)), "n" (0))
+#define COUNT_LEADING_ZEROS_0 32
+#endif
+#endif /* mc68000 */
+
+#if defined (__m88000__) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3"			\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "rJ" (ah), "rJ" (bh), "%rJ" (al), "rJ" (bl))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3"			\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "rJ" (ah), "rJ" (bh), "rJ" (al), "rJ" (bl))
+#define count_leading_zeros(count, x) \
+  do {									\
+    USItype __cbtmp;							\
+    __asm__ ("ff1 %0,%1" : "=3Dr" (__cbtmp) : "r" (x));			\
+    (count) =3D __cbtmp ^ 31;						\
+  } while (0)
+#define COUNT_LEADING_ZEROS_0 63 /* sic */
+#if defined (__m88110__)
+#define umul_ppmm(wh, wl, u, v) \
+  do {									\
+    union {UDItype __ll;						\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x;							\
+    __asm__ ("mulu.d %0,%1,%2" : "=3Dr" (__x.__ll) : "r" (u), "r" (v));	\
+    (wh) =3D __x.__i.__h;							\
+    (wl) =3D __x.__i.__l;							\
+  } while (0)
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  ({union {UDItype __ll;						\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x, __q;							\
+  __x.__i.__h =3D (n1); __x.__i.__l =3D (n0);				\
+  __asm__ ("divu.d %0,%1,%2"						\
+	   : "=3Dr" (__q.__ll) : "r" (__x.__ll), "r" (d));		\
+  (r) =3D (n0) - __q.__l * (d); (q) =3D __q.__l; })
+#define UMUL_TIME 5
+#define UDIV_TIME 25
+#else
+#define UMUL_TIME 17
+#define UDIV_TIME 150
+#endif /* __m88110__ */
+#endif /* __m88000__ */
+
+#if defined (__mips) && W_TYPE_SIZE =3D=3D 32
+#if __GMP_GNUC_PREREQ (4,4)
+#define umul_ppmm(w1, w0, u, v) \
+  do {									\
+    UDItype __ll =3D (UDItype)(u) * (v);					\
+    w1 =3D __ll >> 32;							\
+    w0 =3D __ll;								\
+  } while (0)
+#endif
+#if !defined (umul_ppmm) && __GMP_GNUC_PREREQ (2,7)
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("multu %2,%3" : "=3Dl" (w0), "=3Dh" (w1) : "d" (u), "d" (v))
+#endif
+#if !defined (umul_ppmm)
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("multu %2,%3\n\tmflo %0\n\tmfhi %1"				\
+	   : "=3Dd" (w0), "=3Dd" (w1) : "d" (u), "d" (v))
+#endif
+#define UMUL_TIME 10
+#define UDIV_TIME 100
+#endif /* __mips */
+
+#if (defined (__mips) && __mips >=3D 3) && W_TYPE_SIZE =3D=3D 64
+#if __GMP_GNUC_PREREQ (4,4)
+#define umul_ppmm(w1, w0, u, v) \
+  do {									\
+    typedef unsigned int __ll_UTItype __attribute__((mode(TI)));	\
+    __ll_UTItype __ll =3D (__ll_UTItype)(u) * (v);			\
+    w1 =3D __ll >> 64;							\
+    w0 =3D __ll;								\
+  } while (0)
+#endif
+#if !defined (umul_ppmm) && __GMP_GNUC_PREREQ (2,7)
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("dmultu %2,%3" : "=3Dl" (w0), "=3Dh" (w1) : "d" (u), "d" (v))
+#endif
+#if !defined (umul_ppmm)
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("dmultu %2,%3\n\tmflo %0\n\tmfhi %1"				\
+	   : "=3Dd" (w0), "=3Dd" (w1) : "d" (u), "d" (v))
+#endif
+#define UMUL_TIME 20
+#define UDIV_TIME 140
+#endif /* __mips */
+
+#if defined (__mmix__) && W_TYPE_SIZE =3D=3D 64
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("MULU %0,%2,%3" : "=3Dr" (w0), "=3Dz" (w1) : "r" (u), "r" (v))
+#endif
+
+#if defined (__ns32000__) && W_TYPE_SIZE =3D=3D 32
+#define umul_ppmm(w1, w0, u, v) \
+  ({union {UDItype __ll;						\
+	   struct {USItype __l, __h;} __i;				\
+	  } __x;							\
+  __asm__ ("meid %2,%0"							\
+	   : "=3Dg" (__x.__ll)						\
+	   : "%0" ((USItype)(u)), "g" ((USItype)(v)));			\
+  (w1) =3D __x.__i.__h; (w0) =3D __x.__i.__l;})
+#define __umulsidi3(u, v) \
+  ({UDItype __w;							\
+    __asm__ ("meid %2,%0"						\
+	     : "=3Dg" (__w)						\
+	     : "%0" ((USItype)(u)), "g" ((USItype)(v)));		\
+    __w; })
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  ({union {UDItype __ll;						\
+	   struct {USItype __l, __h;} __i;				\
+	  } __x;							\
+  __x.__i.__h =3D (n1); __x.__i.__l =3D (n0);				\
+  __asm__ ("deid %2,%0"							\
+	   : "=3Dg" (__x.__ll)						\
+	   : "0" (__x.__ll), "g" ((USItype)(d)));			\
+  (r) =3D __x.__i.__l; (q) =3D __x.__i.__h; })
+#define count_trailing_zeros(count,x) \
+  do {									\
+    __asm__ ("ffsd	%2,%0"						\
+	     : "=3Dr" (count)						\
+	     : "0" ((USItype) 0), "r" ((USItype) (x)));			\
+  } while (0)
+#endif /* __ns32000__ */
+
+/* In the past we had a block of various #defines tested
+       _ARCH_PPC    - AIX
+       _ARCH_PWR    - AIX
+       __powerpc__  - gcc
+       __POWERPC__  - BEOS
+       __ppc__      - Darwin
+       PPC          - old gcc, GNU/Linux, SysV
+   The plain PPC test was not good for vxWorks, since PPC is defined on all
+   CPUs there (eg. m68k too), as a constant one is expected to compare
+   CPU_FAMILY against.
+
+   At any rate, this was pretty unattractive and a bit fragile.  The use of
+   HAVE_HOST_CPU_FAMILY is designed to cut through it all and be sure of
+   getting the desired effect.
+
+   ENHANCE-ME: We should test _IBMR2 here when we add assembly support for
+   the system vendor compilers.  (Is that vendor compilers with inline asm,
+   or what?)  */
+
+#if (HAVE_HOST_CPU_FAMILY_power || HAVE_HOST_CPU_FAMILY_powerpc)        \
+  && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  do {									\
+    if (__builtin_constant_p (bh) && (bh) =3D=3D 0)				\
+      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2"		\
+	     : "=3Dr" (sh), "=3D&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
+    else if (__builtin_constant_p (bh) && (bh) =3D=3D ~(USItype) 0)		\
+      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2"		\
+	     : "=3Dr" (sh), "=3D&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
+    else								\
+      __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3"		\
+	     : "=3Dr" (sh), "=3D&r" (sl)					\
+	     : "r" (ah), "r" (bh), "%r" (al), "rI" (bl));		\
+  } while (0)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  do {									\
+    if (__builtin_constant_p (ah) && (ah) =3D=3D 0)				\
+      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2"	\
+	       : "=3Dr" (sh), "=3D&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
+    else if (__builtin_constant_p (ah) && (ah) =3D=3D ~(USItype) 0)		\
+      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2"	\
+	       : "=3Dr" (sh), "=3D&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
+    else if (__builtin_constant_p (bh) && (bh) =3D=3D 0)			\
+      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2"		\
+	       : "=3Dr" (sh), "=3D&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
+    else if (__builtin_constant_p (bh) && (bh) =3D=3D ~(USItype) 0)		\
+      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2"		\
+	       : "=3Dr" (sh), "=3D&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
+    else								\
+      __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2"	\
+	       : "=3Dr" (sh), "=3D&r" (sl)					\
+	       : "r" (ah), "r" (bh), "rI" (al), "r" (bl));		\
+  } while (0)
+#define count_leading_zeros(count, x) \
+  __asm__ ("{cntlz|cntlzw} %0,%1" : "=3Dr" (count) : "r" (x))
+#define COUNT_LEADING_ZEROS_0 32
+#if HAVE_HOST_CPU_FAMILY_powerpc
+#if __GMP_GNUC_PREREQ (4,4)
+#define umul_ppmm(w1, w0, u, v) \
+  do {									\
+    UDItype __ll =3D (UDItype)(u) * (v);					\
+    w1 =3D __ll >> 32;							\
+    w0 =3D __ll;								\
+  } while (0)
+#endif
+#if !defined (umul_ppmm)
+#define umul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    USItype __m0 =3D (m0), __m1 =3D (m1);					\
+    __asm__ ("mulhwu %0,%1,%2" : "=3Dr" (ph) : "%r" (m0), "r" (m1));	\
+    (pl) =3D __m0 * __m1;							\
+  } while (0)
+#endif
+#define UMUL_TIME 15
+#define smul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    SItype __m0 =3D (m0), __m1 =3D (m1);					\
+    __asm__ ("mulhw %0,%1,%2" : "=3Dr" (ph) : "%r" (m0), "r" (m1));	\
+    (pl) =3D __m0 * __m1;							\
+  } while (0)
+#define SMUL_TIME 14
+#define UDIV_TIME 120
+#else
+#define UMUL_TIME 8
+#define smul_ppmm(xh, xl, m0, m1) \
+  __asm__ ("mul %0,%2,%3" : "=3Dr" (xh), "=3Dq" (xl) : "r" (m0), "r" (m1))
+#define SMUL_TIME 4
+#define sdiv_qrnnd(q, r, nh, nl, d) \
+  __asm__ ("div %0,%2,%4" : "=3Dr" (q), "=3Dq" (r) : "r" (nh), "1" (nl), "=
r" (d))
+#define UDIV_TIME 100
+#endif
+#endif /* 32-bit POWER architecture variants.  */
+
+/* We should test _IBMR2 here when we add assembly support for the system
+   vendor compilers.  */
+#if HAVE_HOST_CPU_FAMILY_powerpc && W_TYPE_SIZE =3D=3D 64
+#if !defined (_LONG_LONG_LIMB)
+/* _LONG_LONG_LIMB is ABI=3Dmode32 where adde operates on 32-bit values.  =
So
+   use adde etc only when not _LONG_LONG_LIMB.  */
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  do {									\
+    if (__builtin_constant_p (bh) && (bh) =3D=3D 0)				\
+      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2"		\
+	     : "=3Dr" (sh), "=3D&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
+    else if (__builtin_constant_p (bh) && (bh) =3D=3D ~(UDItype) 0)		\
+      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2"		\
+	     : "=3Dr" (sh), "=3D&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
+    else								\
+      __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3"		\
+	     : "=3Dr" (sh), "=3D&r" (sl)					\
+	     : "r" (ah), "r" (bh), "%r" (al), "rI" (bl));		\
+  } while (0)
+/* We use "*rI" for the constant operand here, since with just "I", gcc ba=
rfs.
+   This might seem strange, but gcc folds away the dead code late.  */
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  do {									      \
+    if (__builtin_constant_p (bl) && bl > -0x8000 && bl <=3D 0x8000) {	   =
   \
+	if (__builtin_constant_p (ah) && (ah) =3D=3D 0)			      \
+	  __asm__ ("{ai|addic} %1,%3,%4\n\t{sfze|subfze} %0,%2"		      \
+		   : "=3Dr" (sh), "=3D&r" (sl) : "r" (bh), "rI" (al), "*rI" (-bl)); \
+	else if (__builtin_constant_p (ah) && (ah) =3D=3D ~(UDItype) 0)	      \
+	  __asm__ ("{ai|addic} %1,%3,%4\n\t{sfme|subfme} %0,%2"		      \
+		   : "=3Dr" (sh), "=3D&r" (sl) : "r" (bh), "rI" (al), "*rI" (-bl)); \
+	else if (__builtin_constant_p (bh) && (bh) =3D=3D 0)		      \
+	  __asm__ ("{ai|addic} %1,%3,%4\n\t{ame|addme} %0,%2"		      \
+		   : "=3Dr" (sh), "=3D&r" (sl) : "r" (ah), "rI" (al), "*rI" (-bl)); \
+	else if (__builtin_constant_p (bh) && (bh) =3D=3D ~(UDItype) 0)	      \
+	  __asm__ ("{ai|addic} %1,%3,%4\n\t{aze|addze} %0,%2"		      \
+		   : "=3Dr" (sh), "=3D&r" (sl) : "r" (ah), "rI" (al), "*rI" (-bl)); \
+	else								      \
+	  __asm__ ("{ai|addic} %1,%4,%5\n\t{sfe|subfe} %0,%3,%2"	      \
+		   : "=3Dr" (sh), "=3D&r" (sl)				      \
+		   : "r" (ah), "r" (bh), "rI" (al), "*rI" (-bl));	      \
+      } else {								      \
+	if (__builtin_constant_p (ah) && (ah) =3D=3D 0)			      \
+	  __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2"	      \
+		   : "=3Dr" (sh), "=3D&r" (sl) : "r" (bh), "rI" (al), "r" (bl));  \
+	else if (__builtin_constant_p (ah) && (ah) =3D=3D ~(UDItype) 0)	      \
+	  __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2"	      \
+		   : "=3Dr" (sh), "=3D&r" (sl) : "r" (bh), "rI" (al), "r" (bl));  \
+	else if (__builtin_constant_p (bh) && (bh) =3D=3D 0)		      \
+	  __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2"	      \
+		   : "=3Dr" (sh), "=3D&r" (sl) : "r" (ah), "rI" (al), "r" (bl));  \
+	else if (__builtin_constant_p (bh) && (bh) =3D=3D ~(UDItype) 0)	      \
+	  __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2"	      \
+		   : "=3Dr" (sh), "=3D&r" (sl) : "r" (ah), "rI" (al), "r" (bl));  \
+	else								      \
+	  __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2"	      \
+		   : "=3Dr" (sh), "=3D&r" (sl)				      \
+		   : "r" (ah), "r" (bh), "rI" (al), "r" (bl));		      \
+      }									      \
+  } while (0)
+#endif /* ! _LONG_LONG_LIMB */
+#define count_leading_zeros(count, x) \
+  __asm__ ("cntlzd %0,%1" : "=3Dr" (count) : "r" (x))
+#define COUNT_LEADING_ZEROS_0 64
+#if 0 && __GMP_GNUC_PREREQ (4,4) /* Disable, this results in libcalls! */
+#define umul_ppmm(w1, w0, u, v) \
+  do {									\
+    typedef unsigned int __ll_UTItype __attribute__((mode(TI)));	\
+    __ll_UTItype __ll =3D (__ll_UTItype)(u) * (v);			\
+    w1 =3D __ll >> 64;							\
+    w0 =3D __ll;								\
+  } while (0)
+#endif
+#if !defined (umul_ppmm)
+#define umul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    UDItype __m0 =3D (m0), __m1 =3D (m1);					\
+    __asm__ ("mulhdu %0,%1,%2" : "=3Dr" (ph) : "%r" (m0), "r" (m1));	\
+    (pl) =3D __m0 * __m1;							\
+  } while (0)
+#endif
+#define UMUL_TIME 15
+#define smul_ppmm(ph, pl, m0, m1) \
+  do {									\
+    DItype __m0 =3D (m0), __m1 =3D (m1);					\
+    __asm__ ("mulhd %0,%1,%2" : "=3Dr" (ph) : "%r" (m0), "r" (m1));	\
+    (pl) =3D __m0 * __m1;							\
+  } while (0)
+#define SMUL_TIME 14  /* ??? */
+#define UDIV_TIME 120 /* ??? */
+#endif /* 64-bit PowerPC.  */
+
+#if defined (__pyr__) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("addw %5,%1\n\taddwc %3,%0"					\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "0"  ((USItype)(ah)), "g" ((USItype)(bh)),			\
+	     "%1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("subw %5,%1\n\tsubwb %3,%0"					\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "0" ((USItype)(ah)), "g" ((USItype)(bh)),			\
+	     "1" ((USItype)(al)), "g" ((USItype)(bl)))
+/* This insn works on Pyramids with AP, XP, or MI CPUs, but not with SP.  =
*/
+#define umul_ppmm(w1, w0, u, v) \
+  ({union {UDItype __ll;						\
+	   struct {USItype __h, __l;} __i;				\
+	  } __x;							\
+  __asm__ ("movw %1,%R0\n\tuemul %2,%0"					\
+	   : "=3D&r" (__x.__ll)						\
+	   : "g" ((USItype) (u)), "g" ((USItype)(v)));			\
+  (w1) =3D __x.__i.__h; (w0) =3D __x.__i.__l;})
+#endif /* __pyr__ */
+
+#if defined (__ibm032__) /* RT/ROMP */  && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("a %1,%5\n\tae %0,%3"					\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "0"  ((USItype)(ah)), "r" ((USItype)(bh)),			\
+	     "%1" ((USItype)(al)), "r" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("s %1,%5\n\tse %0,%3"					\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "0" ((USItype)(ah)), "r" ((USItype)(bh)),			\
+	     "1" ((USItype)(al)), "r" ((USItype)(bl)))
+#define smul_ppmm(ph, pl, m0, m1) \
+  __asm__ (								\
+       "s	r2,r2\n"						\
+"	mts r10,%2\n"							\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	m	r2,%3\n"						\
+"	cas	%0,r2,r0\n"						\
+"	mfs	r10,%1"							\
+	   : "=3Dr" (ph), "=3Dr" (pl)					\
+	   : "%r" ((USItype)(m0)), "r" ((USItype)(m1))			\
+	   : "r2")
+#define UMUL_TIME 20
+#define UDIV_TIME 200
+#define count_leading_zeros(count, x) \
+  do {									\
+    if ((x) >=3D 0x10000)							\
+      __asm__ ("clz	%0,%1"						\
+	       : "=3Dr" (count) : "r" ((USItype)(x) >> 16));		\
+    else								\
+      {									\
+	__asm__ ("clz	%0,%1"						\
+		 : "=3Dr" (count) : "r" ((USItype)(x)));			\
+	(count) +=3D 16;							\
+      }									\
+  } while (0)
+#endif /* RT/ROMP */
+
+#if (defined (__SH2__) || defined (__SH3__) || defined (__SH4__)) && W_TYP=
E_SIZE =3D=3D 32
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("dmulu.l %2,%3\n\tsts macl,%1\n\tsts mach,%0"		\
+	   : "=3Dr" (w1), "=3Dr" (w0) : "r" (u), "r" (v) : "macl", "mach")
+#define UMUL_TIME 5
+#endif
+
+#if defined (__sparc__) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0"				\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "rJ" (ah), "rI" (bh),"%rJ" (al), "rI" (bl)			\
+	   __CLOBBER_CC)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0"				\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "rJ" (ah), "rI" (bh), "rJ" (al), "rI" (bl)	\
+	   __CLOBBER_CC)
+/* FIXME: When gcc -mcpu=3Dv9 is used on solaris, gcc/config/sol2-sld-64.h
+   doesn't define anything to indicate that to us, it only sets __sparcv8.=
 */
+#if defined (__sparc_v9__) || defined (__sparcv9)
+/* Perhaps we should use floating-point operations here?  */
+#if 0
+/* Triggers a bug making mpz/tests/t-gcd.c fail.
+   Perhaps we simply need explicitly zero-extend the inputs?  */
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("mulx %2,%3,%%g1; srl %%g1,0,%1; srlx %%g1,32,%0" :		\
+	   "=3Dr" (w1), "=3Dr" (w0) : "r" (u), "r" (v) : "g1")
+#else
+/* Use v8 umul until above bug is fixed.  */
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=3Dr" (w1), "=3Dr" (w0) : "r" (u),=
 "r" (v))
+#endif
+/* Use a plain v8 divide for v9.  */
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  do {									\
+    USItype __q;							\
+    __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0"			\
+	     : "=3Dr" (__q) : "r" (n1), "r" (n0), "r" (d));		\
+    (r) =3D (n0) - __q * (d);						\
+    (q) =3D __q;								\
+  } while (0)
+#else
+#if defined (__sparc_v8__)   /* gcc normal */				\
+  || defined (__sparcv8)     /* gcc solaris */				\
+  || HAVE_HOST_CPU_supersparc
+/* Don't match immediate range because, 1) it is not often useful,
+   2) the 'I' flag thinks of the range as a 13 bit signed interval,
+   while we want to match a 13 bit interval, sign extended to 32 bits,
+   but INTERPRETED AS UNSIGNED.  */
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=3Dr" (w1), "=3Dr" (w0) : "r" (u),=
 "r" (v))
+#define UMUL_TIME 5
+
+#if HAVE_HOST_CPU_supersparc
+#define UDIV_TIME 60		/* SuperSPARC timing */
+#else
+/* Don't use this on SuperSPARC because its udiv only handles 53 bit
+   dividends and will trap to the kernel for the rest. */
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  do {									\
+    USItype __q;							\
+    __asm__ ("mov %1,%%y;nop;nop;nop;udiv %2,%3,%0"			\
+	     : "=3Dr" (__q) : "r" (n1), "r" (n0), "r" (d));		\
+    (r) =3D (n0) - __q * (d);						\
+    (q) =3D __q;								\
+  } while (0)
+#define UDIV_TIME 25
+#endif /* HAVE_HOST_CPU_supersparc */
+
+#else /* ! __sparc_v8__ */
+#if defined (__sparclite__)
+/* This has hardware multiply but not divide.  It also has two additional
+   instructions scan (ffs from high bit) and divscc.  */
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("umul %2,%3,%1;rd %%y,%0" : "=3Dr" (w1), "=3Dr" (w0) : "r" (u),=
 "r" (v))
+#define UMUL_TIME 5
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  __asm__ ("! Inlined udiv_qrnnd\n"					\
+"	wr	%%g0,%2,%%y	! Not a delayed write for sparclite\n"	\
+"	tst	%%g0\n"							\
+"	divscc	%3,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%%g1\n"						\
+"	divscc	%%g1,%4,%0\n"						\
+"	rd	%%y,%1\n"						\
+"	bl,a 1f\n"							\
+"	add	%1,%4,%1\n"						\
+"1:	! End of inline udiv_qrnnd"					\
+	   : "=3Dr" (q), "=3Dr" (r) : "r" (n1), "r" (n0), "rI" (d)		\
+	   : "%g1" __AND_CLOBBER_CC)
+#define UDIV_TIME 37
+#define count_leading_zeros(count, x) \
+  __asm__ ("scan %1,1,%0" : "=3Dr" (count) : "r" (x))
+/* Early sparclites return 63 for an argument of 0, but they warn that fut=
ure
+   implementations might change this.  Therefore, leave COUNT_LEADING_ZERO=
S_0
+   undefined.  */
+#endif /* __sparclite__ */
+#endif /* __sparc_v8__ */
+#endif /* __sparc_v9__ */
+/* Default to sparc v7 versions of umul_ppmm and udiv_qrnnd.  */
+#ifndef umul_ppmm
+#define umul_ppmm(w1, w0, u, v) \
+  __asm__ ("! Inlined umul_ppmm\n"					\
+"	wr	%%g0,%2,%%y	! SPARC has 0-3 delay insn after a wr\n" \
+"	sra	%3,31,%%g2	! Don't move this insn\n"		\
+"	and	%2,%%g2,%%g2	! Don't move this insn\n"		\
+"	andcc	%%g0,0,%%g1	! Don't move this insn\n"		\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,%3,%%g1\n"						\
+"	mulscc	%%g1,0,%%g1\n"						\
+"	add	%%g1,%%g2,%0\n"						\
+"	rd	%%y,%1"							\
+	   : "=3Dr" (w1), "=3Dr" (w0) : "%rI" (u), "r" (v)			\
+	   : "%g1", "%g2" __AND_CLOBBER_CC)
+#define UMUL_TIME 39		/* 39 instructions */
+#endif
+#ifndef udiv_qrnnd
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
+  do { UWtype __r;							\
+    (q) =3D __MPN(udiv_qrnnd) (&__r, (n1), (n0), (d));			\
+    (r) =3D __r;								\
+  } while (0)
+extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, UWtype);
+#ifndef UDIV_TIME
+#define UDIV_TIME 140
+#endif
+#endif /* LONGLONG_STANDALONE */
+#endif /* udiv_qrnnd */
+#endif /* __sparc__ */
+
+#if defined (__sparc__) && W_TYPE_SIZE =3D=3D 64
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ (								\
+       "addcc	%r4,%5,%1\n"						\
+      "	addccc	%r6,%7,%%g0\n"						\
+      "	addc	%r2,%3,%0"						\
+	  : "=3Dr" (sh), "=3D&r" (sl)					\
+	  : "rJ" (ah), "rI" (bh), "%rJ" (al), "rI" (bl),		\
+	    "%rJ" ((al) >> 32), "rI" ((bl) >> 32)			\
+	   __CLOBBER_CC)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ (								\
+       "subcc	%r4,%5,%1\n"						\
+      "	subccc	%r6,%7,%%g0\n"						\
+      "	subc	%r2,%3,%0"						\
+	  : "=3Dr" (sh), "=3D&r" (sl)					\
+	  : "rJ" (ah), "rI" (bh), "rJ" (al), "rI" (bl),		\
+	    "rJ" ((al) >> 32), "rI" ((bl) >> 32)			\
+	   __CLOBBER_CC)
+#endif
+
+#if defined (__vax__) && W_TYPE_SIZE =3D=3D 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("addl2 %5,%1\n\tadwc %3,%0"					\
+	   : "=3Dg" (sh), "=3D&g" (sl)					\
+	   : "0"  ((USItype)(ah)), "g" ((USItype)(bh)),			\
+	     "%1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("subl2 %5,%1\n\tsbwc %3,%0"					\
+	   : "=3Dg" (sh), "=3D&g" (sl)					\
+	   : "0" ((USItype)(ah)), "g" ((USItype)(bh)),			\
+	     "1" ((USItype)(al)), "g" ((USItype)(bl)))
+#define smul_ppmm(xh, xl, m0, m1) \
+  do {									\
+    union {UDItype __ll;						\
+	   struct {USItype __l, __h;} __i;				\
+	  } __x;							\
+    USItype __m0 =3D (m0), __m1 =3D (m1);					\
+    __asm__ ("emul %1,%2,$0,%0"						\
+	     : "=3Dg" (__x.__ll) : "g" (__m0), "g" (__m1));		\
+    (xh) =3D __x.__i.__h; (xl) =3D __x.__i.__l;				\
+  } while (0)
+#define sdiv_qrnnd(q, r, n1, n0, d) \
+  do {									\
+    union {DItype __ll;							\
+	   struct {SItype __l, __h;} __i;				\
+	  } __x;							\
+    __x.__i.__h =3D n1; __x.__i.__l =3D n0;					\
+    __asm__ ("ediv %3,%2,%0,%1"						\
+	     : "=3Dg" (q), "=3Dg" (r) : "g" (__x.__ll), "g" (d));		\
+  } while (0)
+#if 0
+/* FIXME: This instruction appears to be unimplemented on some systems (vax
+   8800 maybe). */
+#define count_trailing_zeros(count,x)					\
+  do {									\
+    __asm__ ("ffs 0, 31, %1, %0"					\
+	     : "=3Dg" (count)						\
+	     : "g" ((USItype) (x)));					\
+  } while (0)
+#endif
+#endif /* __vax__ */
+
+#if defined (__z8000__) && W_TYPE_SIZE =3D=3D 16
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  __asm__ ("add	%H1,%H5\n\tadc	%H0,%H3"				\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "0"  ((unsigned int)(ah)), "r" ((unsigned int)(bh)),	\
+	     "%1" ((unsigned int)(al)), "rQR" ((unsigned int)(bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  __asm__ ("sub	%H1,%H5\n\tsbc	%H0,%H3"				\
+	   : "=3Dr" (sh), "=3D&r" (sl)					\
+	   : "0" ((unsigned int)(ah)), "r" ((unsigned int)(bh)),	\
+	     "1" ((unsigned int)(al)), "rQR" ((unsigned int)(bl)))
+#define umul_ppmm(xh, xl, m0, m1) \
+  do {									\
+    union {long int __ll;						\
+	   struct {unsigned int __h, __l;} __i;				\
+	  } __x;							\
+    unsigned int __m0 =3D (m0), __m1 =3D (m1);				\
+    __asm__ ("mult	%S0,%H3"					\
+	     : "=3Dr" (__x.__i.__h), "=3Dr" (__x.__i.__l)			\
+	     : "%1" (m0), "rQR" (m1));					\
+    (xh) =3D __x.__i.__h; (xl) =3D __x.__i.__l;				\
+    (xh) +=3D ((((signed int) __m0 >> 15) & __m1)				\
+	     + (((signed int) __m1 >> 15) & __m0));			\
+  } while (0)
+#endif /* __z8000__ */
+
+#endif /* __GNUC__ */
+
+#endif /* NO_ASM */
+
+
+/* FIXME: "sidi" here is highly doubtful, should sometimes be "diti".  */
+#if !defined (umul_ppmm) && defined (__umulsidi3)
+#define umul_ppmm(ph, pl, m0, m1) \
+  {									\
+    UDWtype __ll =3D __umulsidi3 (m0, m1);				\
+    ph =3D (UWtype) (__ll >> W_TYPE_SIZE);				\
+    pl =3D (UWtype) __ll;							\
+  }
+#endif
+
+#if !defined (__umulsidi3)
+#define __umulsidi3(u, v) \
+  ({UWtype __hi, __lo;							\
+    umul_ppmm (__hi, __lo, u, v);					\
+    ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
+#endif
+
+
+/* Use mpn_umul_ppmm or mpn_udiv_qrnnd functions, if they exist.  The "_r"
+   forms have "reversed" arguments, meaning the pointer is last, which
+   sometimes allows better parameter passing, in particular on 64-bit
+   hppa. */
+
+#define mpn_umul_ppmm  __MPN(umul_ppmm)
+extern UWtype mpn_umul_ppmm (UWtype *, UWtype, UWtype);
+
+#if ! defined (umul_ppmm) && HAVE_NATIVE_mpn_umul_ppmm  \
+  && ! defined (LONGLONG_STANDALONE)
+#define umul_ppmm(wh, wl, u, v)						      \
+  do {									      \
+    UWtype __umul_ppmm__p0;						      \
+    (wh) =3D mpn_umul_ppmm (&__umul_ppmm__p0, (UWtype) (u), (UWtype) (v));=
      \
+    (wl) =3D __umul_ppmm__p0;						      \
+  } while (0)
+#endif
+
+#define mpn_umul_ppmm_r  __MPN(umul_ppmm_r)
+extern UWtype mpn_umul_ppmm_r (UWtype, UWtype, UWtype *);
+
+#if ! defined (umul_ppmm) && HAVE_NATIVE_mpn_umul_ppmm_r	\
+  && ! defined (LONGLONG_STANDALONE)
+#define umul_ppmm(wh, wl, u, v)						      \
+  do {									      \
+    UWtype __umul_ppmm__p0;						      \
+    (wh) =3D mpn_umul_ppmm_r ((UWtype) (u), (UWtype) (v), &__umul_ppmm__p0=
);    \
+    (wl) =3D __umul_ppmm__p0;						      \
+  } while (0)
+#endif
+
+#define mpn_udiv_qrnnd  __MPN(udiv_qrnnd)
+extern UWtype mpn_udiv_qrnnd (UWtype *, UWtype, UWtype, UWtype);
+
+#if ! defined (udiv_qrnnd) && HAVE_NATIVE_mpn_udiv_qrnnd	\
+  && ! defined (LONGLONG_STANDALONE)
+#define udiv_qrnnd(q, r, n1, n0, d)					\
+  do {									\
+    UWtype __udiv_qrnnd__r;						\
+    (q) =3D mpn_udiv_qrnnd (&__udiv_qrnnd__r,				\
+			  (UWtype) (n1), (UWtype) (n0), (UWtype) d);	\
+    (r) =3D __udiv_qrnnd__r;						\
+  } while (0)
+#endif
+
+#define mpn_udiv_qrnnd_r  __MPN(udiv_qrnnd_r)
+extern UWtype mpn_udiv_qrnnd_r (UWtype, UWtype, UWtype, UWtype *);
+
+#if ! defined (udiv_qrnnd) && HAVE_NATIVE_mpn_udiv_qrnnd_r	\
+  && ! defined (LONGLONG_STANDALONE)
+#define udiv_qrnnd(q, r, n1, n0, d)					\
+  do {									\
+    UWtype __udiv_qrnnd__r;						\
+    (q) =3D mpn_udiv_qrnnd_r ((UWtype) (n1), (UWtype) (n0), (UWtype) d,	\
+			    &__udiv_qrnnd__r);				\
+    (r) =3D __udiv_qrnnd__r;						\
+  } while (0)
+#endif
+
+
+/* If this machine has no inline assembler, use C macros.  */
+
+#if !defined (add_ssaaaa)
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+  do {									\
+    UWtype __x;								\
+    __x =3D (al) + (bl);							\
+    (sh) =3D (ah) + (bh) + (__x < (al));					\
+    (sl) =3D __x;								\
+  } while (0)
+#endif
+
+#if !defined (sub_ddmmss)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+  do {									\
+    UWtype __x;								\
+    __x =3D (al) - (bl);							\
+    (sh) =3D (ah) - (bh) - ((al) < (bl));                                 \
+    (sl) =3D __x;								\
+  } while (0)
+#endif
+
+/* If we lack umul_ppmm but have smul_ppmm, define umul_ppmm in terms of
+   smul_ppmm.  */
+#if !defined (umul_ppmm) && defined (smul_ppmm)
+#define umul_ppmm(w1, w0, u, v)						\
+  do {									\
+    UWtype __w1;							\
+    UWtype __xm0 =3D (u), __xm1 =3D (v);					\
+    smul_ppmm (__w1, w0, __xm0, __xm1);					\
+    (w1) =3D __w1 + (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1)		\
+		+ (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0);		\
+  } while (0)
+#endif
+
+/* If we still don't have umul_ppmm, define it using plain C.
+
+   For reference, when this code is used for squaring (ie. u and v identic=
al
+   expressions), gcc recognises __x1 and __x2 are the same and generates 3
+   multiplies, not 4.  The subsequent additions could be optimized a bit,
+   but the only place GMP currently uses such a square is mpn_sqr_basecase,
+   and chips obliged to use this generic C umul will have plenty of worse
+   performance problems than a couple of extra instructions on the diagonal
+   of sqr_basecase.  */
+
+#if !defined (umul_ppmm)
+#define umul_ppmm(w1, w0, u, v)						\
+  do {									\
+    UWtype __x0, __x1, __x2, __x3;					\
+    UHWtype __ul, __vl, __uh, __vh;					\
+    UWtype __u =3D (u), __v =3D (v);					\
+									\
+    __ul =3D __ll_lowpart (__u);						\
+    __uh =3D __ll_highpart (__u);						\
+    __vl =3D __ll_lowpart (__v);						\
+    __vh =3D __ll_highpart (__v);						\
+									\
+    __x0 =3D (UWtype) __ul * __vl;					\
+    __x1 =3D (UWtype) __ul * __vh;					\
+    __x2 =3D (UWtype) __uh * __vl;					\
+    __x3 =3D (UWtype) __uh * __vh;					\
+									\
+    __x1 +=3D __ll_highpart (__x0);/* this can't give carry */		\
+    __x1 +=3D __x2;		/* but this indeed can */		\
+    if (__x1 < __x2)		/* did we get it? */			\
+      __x3 +=3D __ll_B;		/* yes, add it in the proper pos. */	\
+									\
+    (w1) =3D __x3 + __ll_highpart (__x1);					\
+    (w0) =3D (__x1 << W_TYPE_SIZE/2) + __ll_lowpart (__x0);		\
+  } while (0)
+#endif
+
+/* If we don't have smul_ppmm, define it using umul_ppmm (which surely will
+   exist in one form or another.  */
+#if !defined (smul_ppmm)
+#define smul_ppmm(w1, w0, u, v)						\
+  do {									\
+    UWtype __w1;							\
+    UWtype __xm0 =3D (u), __xm1 =3D (v);					\
+    umul_ppmm (__w1, w0, __xm0, __xm1);					\
+    (w1) =3D __w1 - (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1)		\
+		- (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0);		\
+  } while (0)
+#endif
+
+/* Define this unconditionally, so it can be used for debugging.  */
+#define __udiv_qrnnd_c(q, r, n1, n0, d) \
+  do {									\
+    UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m;			\
+									\
+    ASSERT ((d) !=3D 0);							\
+    ASSERT ((n1) < (d));						\
+									\
+    __d1 =3D __ll_highpart (d);						\
+    __d0 =3D __ll_lowpart (d);						\
+									\
+    __q1 =3D (n1) / __d1;							\
+    __r1 =3D (n1) - __q1 * __d1;						\
+    __m =3D __q1 * __d0;							\
+    __r1 =3D __r1 * __ll_B | __ll_highpart (n0);				\
+    if (__r1 < __m)							\
+      {									\
+	__q1--, __r1 +=3D (d);						\
+	if (__r1 >=3D (d)) /* i.e. we didn't get carry when adding to __r1 */\
+	  if (__r1 < __m)						\
+	    __q1--, __r1 +=3D (d);					\
+      }									\
+    __r1 -=3D __m;							\
+									\
+    __q0 =3D __r1 / __d1;							\
+    __r0 =3D __r1  - __q0 * __d1;						\
+    __m =3D __q0 * __d0;							\
+    __r0 =3D __r0 * __ll_B | __ll_lowpart (n0);				\
+    if (__r0 < __m)							\
+      {									\
+	__q0--, __r0 +=3D (d);						\
+	if (__r0 >=3D (d))						\
+	  if (__r0 < __m)						\
+	    __q0--, __r0 +=3D (d);					\
+      }									\
+    __r0 -=3D __m;							\
+									\
+    (q) =3D __q1 * __ll_B | __q0;						\
+    (r) =3D __r0;								\
+  } while (0)
+
+/* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
+   __udiv_w_sdiv (defined in libgcc or elsewhere).  */
+#if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
+#define udiv_qrnnd(q, r, nh, nl, d) \
+  do {									\
+    UWtype __r;								\
+    (q) =3D __MPN(udiv_w_sdiv) (&__r, nh, nl, d);				\
+    (r) =3D __r;								\
+  } while (0)
+__GMP_DECLSPEC UWtype __MPN(udiv_w_sdiv) (UWtype *, UWtype, UWtype, UWtype=
);
+#endif
+
+/* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  =
*/
+#if !defined (udiv_qrnnd)
+#define UDIV_NEEDS_NORMALIZATION 1
+#define udiv_qrnnd __udiv_qrnnd_c
+#endif
+
+#if !defined (count_leading_zeros)
+#define count_leading_zeros(count, x) \
+  do {									\
+    UWtype __xr =3D (x);							\
+    UWtype __a;								\
+									\
+    if (W_TYPE_SIZE =3D=3D 32)						\
+      {									\
+	__a =3D __xr < ((UWtype) 1 << 2*__BITS4)				\
+	  ? (__xr < ((UWtype) 1 << __BITS4) ? 1 : __BITS4 + 1)		\
+	  : (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 + 1		\
+	  : 3*__BITS4 + 1);						\
+      }									\
+    else								\
+      {									\
+	for (__a =3D W_TYPE_SIZE - 8; __a > 0; __a -=3D 8)			\
+	  if (((__xr >> __a) & 0xff) !=3D 0)				\
+	    break;							\
+	++__a;								\
+      }									\
+									\
+    (count) =3D W_TYPE_SIZE + 1 - __a - __clz_tab[__xr >> __a];		\
+  } while (0)
+/* This version gives a well-defined value for zero. */
+#define COUNT_LEADING_ZEROS_0 (W_TYPE_SIZE - 1)
+#define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+#define COUNT_LEADING_ZEROS_SLOW
+#endif
+
+/* clz_tab needed by mpn/x86/pentium/mod_1.asm in a fat binary */
+#if HAVE_HOST_CPU_FAMILY_x86 && WANT_FAT_BINARY
+#define COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+#endif
+
+#ifdef COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+extern const unsigned char __GMP_DECLSPEC __clz_tab[129];
+#endif
+
+#if !defined (count_trailing_zeros)
+#if !defined (COUNT_LEADING_ZEROS_SLOW)
+/* Define count_trailing_zeros using an asm count_leading_zeros.  */
+#define count_trailing_zeros(count, x)					\
+  do {									\
+    UWtype __ctz_x =3D (x);						\
+    UWtype __ctz_c;							\
+    ASSERT (__ctz_x !=3D 0);						\
+    count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x);			\
+    (count) =3D W_TYPE_SIZE - 1 - __ctz_c;				\
+  } while (0)
+#else
+/* Define count_trailing_zeros in plain C, assuming small counts are commo=
n.
+   We use clz_tab without ado, since the C count_leading_zeros above will =
have
+   pulled it in.  */
+#define count_trailing_zeros(count, x)					\
+  do {									\
+    UWtype __ctz_x =3D (x);						\
+    int __ctz_c;							\
+									\
+    if (LIKELY ((__ctz_x & 0xff) !=3D 0))					\
+      (count) =3D __clz_tab[__ctz_x & -__ctz_x] - 2;			\
+    else								\
+      {									\
+	for (__ctz_c =3D 8 - 2; __ctz_c < W_TYPE_SIZE - 2; __ctz_c +=3D 8)	\
+	  {								\
+	    __ctz_x >>=3D 8;						\
+	    if (LIKELY ((__ctz_x & 0xff) !=3D 0))				\
+	      break;							\
+	  }								\
+									\
+	(count) =3D __ctz_c + __clz_tab[__ctz_x & -__ctz_x];		\
+      }									\
+  } while (0)
+#endif
+#endif
+
+#ifndef UDIV_NEEDS_NORMALIZATION
+#define UDIV_NEEDS_NORMALIZATION 0
+#endif
+
+/* Whether udiv_qrnnd is actually implemented with udiv_qrnnd_preinv, and
+   that hence the latter should always be used.  */
+#ifndef UDIV_PREINV_ALWAYS
+#define UDIV_PREINV_ALWAYS 0
+#endif
+
+/* Give defaults for UMUL_TIME and UDIV_TIME.  */
+#ifndef UMUL_TIME
+#define UMUL_TIME 1
+#endif
+
+#ifndef UDIV_TIME
+#define UDIV_TIME UMUL_TIME
+#endif
--=20
1.8.0.rc0.18.gf84667d


>From 49f5c21fff9241c195d74101a334fdc2c8dc33e8 Mon Sep 17 00:00:00 2001
From: =3D?UTF-8?q?Niels=3D20M=3DC3=3DB6ller?=3D <nisse@lysator.liu.se>
Date: Wed, 19 Sep 2012 16:20:11 +0200
Subject: [PATCH 6/8] factor: more improvements
MIME-Version: 1.0
Content-Type: text/plain; charset=3DUTF-8
Content-Transfer-Encoding: 8bit

* src/factor-ng.c: Import some improvements from
http://gmplib.org:8000/factoring
Co-authored-by: Torbj=F6rn Granlund <tg@gmplib.org>
---
 src/factor-ng.c | 124 ++++++++++++++++++++++++++++++----------------------=
----
 1 file changed, 66 insertions(+), 58 deletions(-)

diff --git a/src/factor-ng.c b/src/factor-ng.c
index 776aaa6..36be5e6 100644
--- a/src/factor-ng.c
+++ b/src/factor-ng.c
@@ -1743,8 +1743,10 @@ is_square (uintmax_t x)
   return 0;
 }

-static const unsigned short invtab[] =3D
+/* invtab[i] =3D floor(0x10000 / (0x100 + i) */
+static const unsigned short invtab[0x81] =3D
   {
+    0x200,
     0x1fc, 0x1f8, 0x1f4, 0x1f0, 0x1ec, 0x1e9, 0x1e5, 0x1e1,
     0x1de, 0x1da, 0x1d7, 0x1d4, 0x1d0, 0x1cd, 0x1ca, 0x1c7,
     0x1c3, 0x1c0, 0x1bd, 0x1ba, 0x1b7, 0x1b4, 0x1b2, 0x1af,
@@ -1767,17 +1769,22 @@ static const unsigned short invtab[] =3D
    that q < 0x40; here it instead uses a table of (Euclidian) inverses.  */
 #define div_smallq(q, r, u, d)                                          \
   do {                                                                  \
-    if (0 && (u) / 0x40 < (d))                                          \
+    if ((u) / 0x40 < (d))                                               \
       {                                                                 \
         int _cnt;                                                       \
         uintmax_t _dinv, _mask, _q, _r;                                 \
         count_leading_zeros (_cnt, (d));                                \
-                                                                        \
-        _dinv =3D invtab[((d) >> (W_TYPE_SIZE - 8 - _cnt))                \
-                       - (1 << (8 - 1))];                               \
-                                                                        \
         _r =3D (u);                                                       \
-        _q =3D _r * _dinv >> (W_TYPE_SIZE + 8 - _cnt);                    \
+        if (UNLIKELY (_cnt > (W_TYPE_SIZE - 8)))                        \
+          {                                                             \
+            _dinv =3D invtab[((d) << (_cnt + 8 - W_TYPE_SIZE)) - 0x80];   \
+            _q =3D _dinv * _r >> (8 + W_TYPE_SIZE - _cnt);                \
+          }                                                             \
+        else                                                            \
+          {                                                             \
+            _dinv =3D invtab[((d) >> (W_TYPE_SIZE - 8 - _cnt)) - 0x7f];   \
+            _q =3D _dinv * (_r >> (W_TYPE_SIZE - 3 - _cnt)) >> 11;        \
+          }                                                             \
         _r -=3D _q*(d);                                                   \
                                                                         \
         _mask =3D -(uintmax_t) (_r >=3D (d));                             =
  \
@@ -1837,8 +1844,9 @@ static unsigned int q_freq[Q_FREQ_SIZE + 1];
 # define MIN(a,b) ((a) < (b) ? (a) : (b))
 #endif

-
-static void
+/* Return true on success.  Expected to fail only for numbers
+   >=3D 2^{2*W_TYPE_SIZE - 2}, or close to that limit. */
+static bool
 factor_using_squfof (uintmax_t n1, uintmax_t n0, struct factors *factors)
 {
   /* Uses algorithm and notation from
@@ -1858,35 +1866,41 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, st=
ruct factors *factors)
       1155, 15, 231, 35, 3, 55, 7, 11, 0
     };

-  uintmax_t S;
   const unsigned int *m;

   struct { uintmax_t Q; uintmax_t P; } queue[QUEUE_SIZE];

-  S =3D isqrt2 (n1, n0);
+  if (n1 >=3D ((uintmax_t) 1 << (W_TYPE_SIZE - 2)))
+    return false;
+
+  uintmax_t sqrt_n =3D isqrt2 (n1, n0);

-  if (n0 =3D=3D S * S)
+  if (n0 =3D=3D sqrt_n * sqrt_n)
     {
       uintmax_t p1, p0;

-      umul_ppmm (p1, p0, S, S);
+      umul_ppmm (p1, p0, sqrt_n, sqrt_n);
       assert (p0 =3D=3D n0);

       if (n1 =3D=3D p1)
         {
-          if (prime_p (S))
-            factor_insert_multiplicity (factors, S, 2);
+          if (prime_p (sqrt_n))
+            factor_insert_multiplicity (factors, sqrt_n, 2);
           else
             {
               struct factors f;

               f.nfactors =3D 0;
-              factor_using_squfof (0, S, &f);
+              if (!factor_using_squfof (0, sqrt_n, &f))
+                {
+                  /* Try pollard rho instead */
+                  factor_using_pollard_rho (sqrt_n, 1, &f);
+                }
               /* Duplicate the new factors */
               for (unsigned int i =3D 0; i < f.nfactors; i++)
                 factor_insert_multiplicity (factors, f.p[i], 2*f.e[i]);
             }
-          return;
+          return true;
         }
     }

@@ -1925,6 +1939,7 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, stru=
ct factors *factors)
       Dh +=3D n1 * mu;

       assert (Dl % 4 !=3D 1);
+      assert (Dh < (uintmax_t) 1 << (W_TYPE_SIZE - 2));

       S =3D isqrt2 (Dh, Dl);

@@ -1943,10 +1958,10 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, st=
ruct factors *factors)

       for (i =3D 0; i <=3D B; i++)
         {
-          uintmax_t q, P1, t, r;
+          uintmax_t q, P1, t, rem;

-          div_smallq (q, r, S+P, Q);
-          P1 =3D S - r;   /* P1 =3D q*Q - P */
+          div_smallq (q, rem, S+P, Q);
+          P1 =3D S - rem; /* P1 =3D q*Q - P */

 #if STAT_SQUFOF
           assert (q > 0);
@@ -2025,29 +2040,25 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, st=
ruct factors *factors)
                      for the case D =3D 2N. */
                   /* Compute Q =3D (D - P*P) / Q1, but we need double
                      precision. */
-                  {
-                    uintmax_t hi, lo, rem;
-                    umul_ppmm (hi, lo, P, P);
-                    sub_ddmmss (hi, lo, Dh, Dl, hi, lo);
-                    udiv_qrnnd (Q, rem, hi, lo, Q1);
-                    assert (rem =3D=3D 0);
-                  }
+                  uintmax_t hi, lo;
+                  umul_ppmm (hi, lo, P, P);
+                  sub_ddmmss (hi, lo, Dh, Dl, hi, lo);
+                  udiv_qrnnd (Q, rem, hi, lo, Q1);
+                  assert (rem =3D=3D 0);

                   for (;;)
                     {
-                      uintmax_t r;
-
                       /* Note: There appears to by a typo in the paper,
                          Step 4a in the algorithm description says q <--
                          floor([S+P]/\hat Q), but looking at the equations
                          in Sec. 3.1, it should be q <-- floor([S+P] / Q).
                          (In this code, \hat Q is Q1). */
-                      div_smallq (q, r, S+P, Q);
-                      P1 =3D S - r;       /* P1 =3D q*Q - P */
+                      div_smallq (q, rem, S+P, Q);
+                      P1 =3D S - rem;     /* P1 =3D q*Q - P */

 #if STAT_SQUFOF
                       q_freq[0]++;
-                      q_freq[MIN(q, Q_FREQ_SIZE)]++;
+                      q_freq[MIN (q, Q_FREQ_SIZE)]++;
 #endif
                       if (P =3D=3D P1)
                         break;
@@ -2065,8 +2076,8 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, stru=
ct factors *factors)

                   if (prime_p (Q))
                     factor_insert (factors, Q);
-                  else
-                    factor_using_squfof (0, Q, factors);
+                  else if (!factor_using_squfof (0, Q, factors))
+                    factor_using_pollard_rho (Q, 2, factors);

                   divexact_21 (n1, n0, n1, n0, Q);

@@ -2074,13 +2085,16 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, st=
ruct factors *factors)
                     factor_insert_large (factors, n1, n0);
                   else
                     {
-                      if (n1 =3D=3D 0)
-                        factor_using_pollard_rho (n0, 1, factors);
-                      else
-                        factor_using_squfof (n1, n0, factors);
+                      if (!factor_using_squfof (n1, n0, factors))
+                        {
+                          if (n1 =3D=3D 0)
+                            factor_using_pollard_rho (n0, 1, factors);
+                          else
+                            factor_using_pollard_rho2 (n1, n0, 1, factors);
+                        }
                     }

-                  return;
+                  return true;
                 }
             }
         next_i:
@@ -2089,8 +2103,7 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, stru=
ct factors *factors)
     next_multiplier:
       ;
     }
-  fprintf (stderr, "squfof failed.\n");
-  exit (EXIT_FAILURE);
+  return false;
 }

 static void
@@ -2104,26 +2117,21 @@ factor (uintmax_t t1, uintmax_t t0, struct factors =
*factors)

   t0 =3D factor_using_division (&t1, t1, t0, factors);

-  if (t1 =3D=3D 0)
-    {
-      if (t0 !=3D 1)
-        {
-          if (prime_p (t0))
-            factor_insert (factors, t0);
-          else if (alg =3D=3D ALG_POLLARD_RHO)
-            factor_using_pollard_rho (t0, 1, factors);
-          else
-            factor_using_squfof (0, t0, factors);
-        }
-    }
+  if (t1 =3D=3D 0 && t0 < 2)
+    return;
+
+  if (prime2_p (t1, t0))
+    factor_insert_large (factors, t1, t0);
   else
     {
-      if (prime2_p (t1, t0))
-        factor_insert_large (factors, t1, t0);
-      else if (alg =3D=3D ALG_POLLARD_RHO)
-        factor_using_pollard_rho2 (t1, t0, 1, factors);
+      if (alg =3D=3D ALG_SQUFOF)
+        if (factor_using_squfof (t1, t0, factors))
+          return;
+
+      if (t1 =3D=3D 0)
+        factor_using_pollard_rho (t0, 1, factors);
       else
-        factor_using_squfof (t1, t0, factors);
+        factor_using_pollard_rho2 (t1, t0, 1, factors);
     }
 }

--=20
1.8.0.rc0.18.gf84667d


>From 759ebcb57db73449b5670204f85931d34881b7d2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Sun, 16 Sep 2012 22:31:04 +0200
Subject: [PATCH 7/8] factor: merge with preexisting factor; integrate tests;
 avoid warnings
MIME-Version: 1.0
Content-Type: text/plain; charset=3DUTF-8
Content-Transfer-Encoding: 8bit

* src/factor.c: Renamed from factor-ng.c, with the following changes:
Adjust copyright header to be consistent with others.
Use xmalloc and xrealloc, to avoid segv upon OOM.
Switch back to using readtokens to handle input.
Diagnose invalid inputs.
s/fprintf+exit/error/
(print_factors): Add comments.
(strto2uintmax): Return strtol_error, not int.
(read_item): Remove, no longer used.
(main): Use atexit(close_stdout) so that we don't ignore failed write.
* cfg.mk: Exempt src/longlong.h from several tests.
Exempt run.sh from the test-list-consistency test.
Exempt make-prime-list.c from numerous tests, since we won't
be making it conform: it must not link with libcoreutils.a.
Exempt factor-ng.c from the no-upper-case error message test.
* AUTHORS (factor): Add Torbj=F6rn and Niels.
* tests/local.mk (factor_tests): Encode the 37 tests.
($(factor_tests)): Rule to generate a test script for each test.
* tests/factor/run.sh: New script, marked as very expensive.
* .gitignore: Ignore new generated files.
* src/local.mk (src/primes.h): New rule.
(noinst_PROGRAMS): Add make-prime-list.
(noinst_HEADERS): Add longlong.h.
Remove all wheel-related rules and files.
* src/wheel-gen.pl: Remove file.

maint: mark set-but-not-used variables with ATTRIBUTE_UNUSED
* src/factor-ng.c (redcify, prime_p, isqrt2): Mark them, so we
don't have to disable -Wunused-but-set-variable.

maint: use __builtin_expect only if __GNUC__
* src/factor-ng.c (LIKELY, UNLIKELY) [__GNUC__]: Add #ifdef guard.

build: avoid warning about unused macro
* src/factor-ng.c (__GMP_DECLSPEC): Don't define here
* src/longlong.h (__GMP_DECLSPEC): Define if not already defined.
---
 .gitignore          |    6 +-
 AUTHORS             |    2 +-
 cfg.mk              |   23 +-
 src/.gitignore      |    2 -
 src/factor-ng.c     | 2396 ------------------------------------------------
 src/factor.c        | 2497 ++++++++++++++++++++++++++++++++++++++++++++---=
----
 src/local.mk        |   31 +-
 src/longlong.h      |    6 +-
 src/wheel-gen.pl    |  114 ---
 tests/factor/run.sh |   30 +
 tests/local.mk      |   71 +-
 11 files changed, 2327 insertions(+), 2851 deletions(-)
 delete mode 100644 src/factor-ng.c
 delete mode 100755 src/wheel-gen.pl
 create mode 100755 tests/factor/run.sh

diff --git a/.gitignore b/.gitignore
index 56a9bf4..8a423f7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,7 +37,7 @@
 /coreutils-*.tar.xz
 /coreutils-*.tar.xz.sig
 /gnulib-tests
-/lib/.cvsignore
+/lib/.dirstamp
 /lib/.gitignore
 /lib/alloca.h
 /lib/arg-nonnull.h
@@ -74,6 +74,7 @@
 /lib/ref-del.sed
 /lib/selinux
 /lib/signal.h
+/lib/spawn.h
 /lib/stamp-h1
 /lib/stdalign.h
 /lib/stdio.h
@@ -152,12 +153,15 @@
 /po/remove-potcdate.sin
 /po/stamp-po
 /src/cu-progs.mk
+/src/make-prime-list
+/src/primes.h
 /src/version.c
 /src/version.h
 /stamp-h1
 /tests/*/*.log
 /tests/*/*.trs
 /tests/.built-programs
+/tests/factor/[0-9]*.sh
 /tests/t?
 /tests/test-suite.log
 ID
diff --git a/AUTHORS b/AUTHORS
index 9984a2e..552e9d4 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -26,7 +26,7 @@ echo: Brian Fox, Chet Ramey
 env: Richard Mlynarik, David MacKenzie
 expand: David MacKenzie
 expr: Mike Parker, James Youngman, Paul Eggert
-factor: Paul Rubin
+factor: Paul Rubin, Torbj=F6rn Granlund, Niels M=F6ller
 false: Jim Meyering
 fmt: Ross Paterson
 fold: David MacKenzie
diff --git a/cfg.mk b/cfg.mk
index 079ab5b..1020977 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -111,7 +111,7 @@ sc_tests_list_consistency:
 	  for t in $(all_tests); do echo $$t; done;			\
 	  cd $(top_srcdir);						\
 	  $(SHELL) build-aux/vc-list-files tests			\
-	    | grep -v '^tests/init\.sh$$'				\
+	    | grep -Ev '^tests/(factor/run|init)\.sh$$'			\
 	    | $(EGREP) "$$test_extensions_rx\$$";			\
 	} | sort | uniq -u | grep . && exit 1; :

@@ -515,10 +515,11 @@ update-copyright-env =3D \
 # List syntax-check exemptions.
 exclude_file_name_regexp--sc_space_tab =3D \
   ^(tests/pr/|tests/misc/nl\.sh$$|gl/.*\.diff$$)
-exclude_file_name_regexp--sc_bindtextdomain =3D ^(gl/.*|lib/euidaccess-sta=
t)\.c$$
+exclude_file_name_regexp--sc_bindtextdomain =3D \
+  ^(gl/.*|lib/euidaccess-stat|src/make-prime-list)\.c$$
 exclude_file_name_regexp--sc_trailing_blank =3D ^tests/pr/
 exclude_file_name_regexp--sc_system_h_headers =3D \
-  ^src/((system|copy)\.h|libstdbuf\.c)$$
+  ^src/((system|copy)\.h|libstdbuf\.c|make-prime-list\.c)$$

 _src =3D (false|lbracket|ls-(dir|ls|vdir)|tac-pipe|uname-(arch|uname))
 exclude_file_name_regexp--sc_require_config_h_first =3D \
@@ -530,7 +531,8 @@ exclude_file_name_regexp--sc_po_check =3D ^gl/
 exclude_file_name_regexp--sc_prohibit_always-defined_macros =3D \
   ^src/(seq|remove)\.c$$
 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF =3D ^tests/pr/
-exclude_file_name_regexp--sc_program_name =3D ^(gl/.*|lib/euidaccess-stat)=
\.c$$
+exclude_file_name_regexp--sc_program_name =3D \
+  ^(gl/.*|lib/euidaccess-stat|src/make-prime-list)\.c$$
 exclude_file_name_regexp--sc_file_system =3D \
   NEWS|^(init\.cfg|src/df\.c|tests/df/df-P\.sh)$$
 exclude_file_name_regexp--sc_prohibit_always_true_header_tests =3D \
@@ -539,14 +541,20 @@ exclude_file_name_regexp--sc_prohibit_fail_0 =3D \
   (^.*/git-hooks/commit-msg|^tests/init\.sh|Makefile\.am|\.mk|.*\.texi)$$
 exclude_file_name_regexp--sc_prohibit_atoi_atof =3D ^lib/euidaccess-stat\.=
c$$

+# longlong.h is maintained elsewhere.
+_ll =3D ^src/longlong\.h$$
+exclude_file_name_regexp--sc_useless_cpp_parens =3D $(_ll)
+exclude_file_name_regexp--sc_long_lines =3D $(_ll)
+exclude_file_name_regexp--sc_space_before_open_paren =3D $(_ll)
+
 tbi_1 =3D ^tests/pr/|(^gl/lib/reg.*\.c\.diff|\.mk|^man/help2man)$$
 tbi_2 =3D ^scripts/git-hooks/(pre-commit|pre-applypatch|applypatch-msg)$$
-tbi_3 =3D (GNU)?[Mm]akefile(\.am)?$$
+tbi_3 =3D (GNU)?[Mm]akefile(\.am)?$$|$(_ll)
 exclude_file_name_regexp--sc_prohibit_tab_based_indentation =3D \
   $(tbi_1)|$(tbi_2)|$(tbi_3)

 exclude_file_name_regexp--sc_preprocessor_indentation =3D \
-  ^(gl/lib/rand-isaac\.[ch]|gl/tests/test-rand-isaac\.c)$$
+  ^(gl/lib/rand-isaac\.[ch]|gl/tests/test-rand-isaac\.c)$$|$(__ll)
 exclude_file_name_regexp--sc_prohibit_stat_st_blocks =3D \
   ^(src/system\.h|tests/du/2g\.sh)$$

@@ -560,6 +568,9 @@ exclude_file_name_regexp--sc_prohibit_test_backticks =
=3D \
 exclude_file_name_regexp--sc_prohibit_operator_at_end_of_line =3D \
   ^src/(ptx|test|head)\.c$$

+exclude_file_name_regexp--sc_error_message_uppercase =3D ^src/factor\.c$$
+exclude_file_name_regexp--sc_prohibit_atoi_atof =3D ^src/make-prime-list\.=
c$$
+
 # Augment AM_CFLAGS to include our per-directory options:
 AM_CFLAGS +=3D $($(@D)_CFLAGS)

diff --git a/src/.gitignore b/src/.gitignore
index 1c1edbb..18cccc1 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -109,8 +109,6 @@ uptime
 users
 vdir
 wc
-wheel-size.h
-wheel.h
 who
 whoami
 yes
diff --git a/src/factor-ng.c b/src/factor-ng.c
deleted file mode 100644
index 36be5e6..0000000
--- a/src/factor-ng.c
+++ /dev/null
@@ -1,2396 +0,0 @@
-/* Factoring of uintmax_t numbers.
-
-   Contributed to the GNU project by Torbj=F6rn Granlund and Niels M=F6ller
-   Contains code from GNU MP.
-
-Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2009, 2012
-Free Software Foundation, Inc.
-
-This program is free software; you can redistribute it and/or modify it un=
der
-the terms of the GNU General Public License as published by the Free Softw=
are
-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 WITHOU=
T 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 wi=
th
-this program.  If not, see http://www.gnu.org/licenses/.  */
-
-/* Efficiently factor numbers that fit in one or two words (word =3D uintm=
ax_t),
-   or, with GMP, numbers of any size.
-
-  Code organisation:
-
-    There are several variants of many functions, for handling one word, t=
wo
-    words, and GMP's mpz_t type.  If the one-word variant is called foo, t=
he
-    two-word variant will be foo2, and the one for mpz_t will be mp_foo.  =
In
-    some cases, the plain function variants will handle both one-word and
-    two-word numbers, evidenced by function arguments.
-
-    The factoring code for two words will fall into the code for one word =
when
-    progress allows that.
-
-    Using GMP is optional.  Define HAVE_GMP to make this code include GMP
-    factoring code.  The GMP factoring code is based on GMP's demos/factor=
ize.c
-    (last synched 2012-09-07).  The GMP-based factoring code will stay in =
GMP
-    factoring code even if numbers get small enough for using the two-word
-    code.
-
-  Algorithm:
-
-    (1) Perform trial division using a small primes table, but without har=
dware
-        division since the primes table store inverses modulo the word bas=
e.
-        (The GMP variant of this code doesn't make use of the precomputed
-        inverses, but instead relies on GMP for fast divisibility testing.)
-    (2) Check the nature of any non-factored part using Miller-Rabin for
-        detecting composites, and Lucas for detecting primes.
-    (3) Factor any remaining composite part using the Pollard-Brent rho
-        algorithm or the SQUFOF algorithm, checking status of found factors
-        again using Miller-Rabin and Lucas.
-
-    We prefer using Hensel norm in the divisions, not the more familiar
-    Euclidian norm, since the former leads to much faster code.  In the
-    Pollard-Brent rho code and the the prime testing code, we use Montgome=
ry's
-    trick of multiplying all n-residues by the word base, allowing cheap H=
ensel
-    reductions mod n.
-
-  Improvements:
-
-    * Use modular inverses also for exact division in the Lucas code, and
-      elsewhere.  A problem is to locate the inverses not from an index, b=
ut
-      from a prime.  We might instead compute the inverse on-the-fly.
-
-    * Tune trial division table size (not forgetting that this is a standa=
lone
-      program where the table will be read from disk for each invocation).
-
-    * Implement less naive powm, using k-ary exponentiation for k =3D 3 or
-      perhaps k =3D 4.
-
-    * Try to speed trial division code for single uintmax_t numbers, i.e.,=
 the
-      code using DIVBLOCK.  It currently runs at 2 cycles per prime (Intel=
 SBR,
-      IBR), 3 cycles per prime (AMD Stars) and 5 cycles per prime (AMD BD)=
 when
-      using gcc 4.6 and 4.7.  Some software pipelining should help; 1, 2, =
and 4
-      respectively cycles ought to be possible.
-
-    * The redcify function could be vastly improved by using (plain Euclid=
ian)
-      pre-inversion (such as GMP's invert_limb) and udiv_qrnnd_preinv (from
-      GMP's gmp-impl.h).  The redcify2 function could be vastly improved u=
sing
-      similar methoods.  These functions currently dominate run time when =
using
-      the -w option.
-*/
-
-#include <config.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <inttypes.h>
-#include <errno.h>
-#include <assert.h>
-#include <ctype.h>
-#include <string.h>             /* for memmove */
-#include <unistd.h>             /* for getopt */
-#include <stdbool.h>
-
-#include "system.h"
-
-#if HAVE_GMP
-# include <gmp.h>
-#endif
-
-#ifndef STAT_SQUFOF
-# define STAT_SQUFOF 0
-#endif
-
-#ifndef USE_LONGLONG_H
-# define USE_LONGLONG_H 1
-#endif
-
-#if USE_LONGLONG_H
-
-/* Make definitions for longlong.h to make it do what it can do for us */
-# define W_TYPE_SIZE 64          /* bitcount for uintmax_t */
-# define UWtype  uintmax_t
-# define UHWtype unsigned long int
-# undef UDWtype
-# if HAVE_ATTRIBUTE_MODE
-typedef unsigned int UQItype    __attribute__ ((mode (QI)));
-typedef          int SItype     __attribute__ ((mode (SI)));
-typedef unsigned int USItype    __attribute__ ((mode (SI)));
-typedef          int DItype     __attribute__ ((mode (DI)));
-typedef unsigned int UDItype    __attribute__ ((mode (DI)));
-# else
-typedef unsigned char UQItype;
-typedef          long SItype;
-typedef unsigned long int USItype;
-#  if HAVE_LONG_LONG
-typedef long long int DItype;
-typedef unsigned long long int UDItype;
-#  else /* Assume `long' gives us a wide enough type.  Needed for hppa2.0w=
.  */
-typedef long int DItype;
-typedef unsigned long int UDItype;
-#  endif
-# endif
-# define LONGLONG_STANDALONE     /* Don't require GMP's longlong.h mdep fi=
les */
-# define ASSERT(x)               /* FIXME make longlong.h really standalon=
e */
-# define __GMP_DECLSPEC          /* FIXME make longlong.h really standalon=
e */
-# define __clz_tab factor_clz_tab /* Rename to avoid glibc collision */
-# ifndef __GMP_GNUC_PREREQ
-#  define __GMP_GNUC_PREREQ(a,b) 1
-# endif
-# if _ARCH_PPC
-#  define HAVE_HOST_CPU_FAMILY_powerpc 1
-# endif
-# include "longlong.h"
-# ifdef COUNT_LEADING_ZEROS_NEED_CLZ_TAB
-const unsigned char factor_clz_tab[129] =3D
-{
-  1,2,3,3,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
-  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
-  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
-  9
-};
-# endif
-
-#else /* not USE_LONGLONG_H */
-
-# define W_TYPE_SIZE (8 * sizeof (uintmax_t))
-# define __ll_B ((uintmax_t) 1 << (W_TYPE_SIZE / 2))
-# define __ll_lowpart(t)  ((uintmax_t) (t) & (__ll_B - 1))
-# define __ll_highpart(t) ((uintmax_t) (t) >> (W_TYPE_SIZE / 2))
-
-#endif
-
-enum alg_type { ALG_POLLARD_RHO =3D 1, ALG_SQUFOF =3D 2 };
-
-static enum alg_type alg;
-
-/* 2*3*5*7*11...*101 is 128 bits, and has 26 prime factors */
-#define MAX_NFACTS 26
-
-struct factors
-{
-  uintmax_t     plarge[2]; /* Can have a single large factor */
-  uintmax_t     p[MAX_NFACTS];
-  unsigned char e[MAX_NFACTS];
-  unsigned char nfactors;
-};
-
-#if HAVE_GMP
-struct mp_factors
-{
-  mpz_t         *p;
-  unsigned long int *e;
-  unsigned long int nfactors;
-};
-#endif
-
-static void factor (uintmax_t, uintmax_t, struct factors *);
-
-#ifndef umul_ppmm
-# define umul_ppmm(w1, w0, u, v)                                         \
-  do {                                                                  \
-    uintmax_t __x0, __x1, __x2, __x3;                                   \
-    unsigned long int __ul, __vl, __uh, __vh;                           \
-    uintmax_t __u =3D (u), __v =3D (v);                                   =
  \
-                                                                        \
-    __ul =3D __ll_lowpart (__u);                                          \
-    __uh =3D __ll_highpart (__u);                                         \
-    __vl =3D __ll_lowpart (__v);                                          \
-    __vh =3D __ll_highpart (__v);                                         \
-                                                                        \
-    __x0 =3D (uintmax_t) __ul * __vl;                                     \
-    __x1 =3D (uintmax_t) __ul * __vh;                                     \
-    __x2 =3D (uintmax_t) __uh * __vl;                                     \
-    __x3 =3D (uintmax_t) __uh * __vh;                                     \
-                                                                        \
-    __x1 +=3D __ll_highpart (__x0);/* this can't give carry */            \
-    __x1 +=3D __x2;               /* but this indeed can */               \
-    if (__x1 < __x2)            /* did we get it? */                    \
-      __x3 +=3D __ll_B;           /* yes, add it in the proper pos. */    \
-                                                                        \
-    (w1) =3D __x3 + __ll_highpart (__x1);                                 \
-    (w0) =3D (__x1 << W_TYPE_SIZE / 2) + __ll_lowpart (__x0);             \
-  } while (0)
-#endif
-
-#if !defined(udiv_qrnnd) || defined(UDIV_NEEDS_NORMALIZATION)
-/* Define our own, not needing normalization. This function is
-   currently not performance critical, so keep it simple. Similar to
-   the mod macro below. */
-# undef udiv_qrnnd
-# define udiv_qrnnd(q, r, n1, n0, d)                                     \
-  do {                                                                  \
-    uintmax_t __d1, __d0, __q, __r1, __r0;                              \
-                                                                        \
-    assert ((n1) < (d));                                                \
-    __d1 =3D (d); __d0 =3D 0;                                             =
  \
-    __r1 =3D (n1); __r0 =3D (n0);                                         =
  \
-    __q =3D 0;                                                            \
-    for (unsigned int __i =3D W_TYPE_SIZE; __i > 0; __i--)                \
-      {                                                                 \
-        rsh2 (__d1, __d0, __d1, __d0, 1);                               \
-        __q <<=3D 1;                                                      \
-        if (ge2 (__r1, __r0, __d1, __d0))                               \
-          {                                                             \
-            __q++;                                                      \
-            sub_ddmmss (__r1, __r0, __r1, __r0, __d1, __d0);            \
-          }                                                             \
-      }                                                                 \
-    (r) =3D __r0;                                                         \
-    (q) =3D __q;                                                          \
-  } while (0)
-#endif
-
-#if !defined (add_ssaaaa)
-# define add_ssaaaa(sh, sl, ah, al, bh, bl)                              \
-  do {                                                                  \
-    uintmax_t _add_x;                                                   \
-    _add_x =3D (al) + (bl);                                               \
-    (sh) =3D (ah) + (bh) + (_add_x < (al));                               \
-    (sl) =3D _add_x;                                                      \
-  } while (0)
-#endif
-
-#define rsh2(rh, rl, ah, al, cnt)                                       \
-  do {                                                                  \
-    (rl) =3D ((ah) << (W_TYPE_SIZE - (cnt))) | ((al) >> (cnt));           \
-    (rh) =3D (ah) >> (cnt);                                               \
-  } while (0)
-
-#define lsh2(rh, rl, ah, al, cnt)                                       \
-  do {                                                                  \
-    (rh) =3D ((ah) << cnt) | ((al) >> (W_TYPE_SIZE - (cnt)));             \
-    (rl) =3D (al) << (cnt);                                               \
-  } while (0)
-
-#define ge2(ah, al, bh, bl)                                             \
-  ((ah) > (bh) || ((ah) =3D=3D (bh) && (al) >=3D (bl)))
-
-#define gt2(ah, al, bh, bl)                                             \
-  ((ah) > (bh) || ((ah) =3D=3D (bh) && (al) > (bl)))
-
-#ifndef sub_ddmmss
-# define sub_ddmmss(rh, rl, ah, al, bh, bl)                              \
-  do {                                                                  \
-    uintmax_t _cy;                                                      \
-    _cy =3D (al) < (bl);                                                  \
-    (rl) =3D (al) - (bl);                                                 \
-    (rh) =3D (ah) - (bh) - _cy;                                           \
-  } while (0)
-#endif
-
-#ifndef count_leading_zeros
-# define count_leading_zeros(count, x) do {                              \
-    uintmax_t __clz_x =3D (x);                                            \
-    unsigned int __clz_c;                                               \
-    for (__clz_c =3D 0;                                                   \
-         (__clz_x & ((uintmax_t) 0xff << (W_TYPE_SIZE - 8))) =3D=3D 0;    =
  \
-         __clz_c +=3D 8)                                                  \
-      __clz_x <<=3D 8;                                                    \
-    for (; (intmax_t)__clz_x >=3D 0; __clz_c++)                           \
-      __clz_x <<=3D 1;                                                    \
-    (count) =3D __clz_c;                                                  \
-  } while (0)
-#endif
-
-#ifndef count_trailing_zeros
-# define count_trailing_zeros(count, x) do {                             \
-    uintmax_t __ctz_x =3D (x);                                            \
-    unsigned int __ctz_c =3D 0;                                           \
-    while ((__ctz_x & 1) =3D=3D 0)                                        =
  \
-      {                                                                 \
-        __ctz_x >>=3D 1;                                                  \
-        __ctz_c++;                                                      \
-      }                                                                 \
-    (count) =3D __ctz_c;                                                  \
-  } while (0)
-#endif
-
-/* Requires that a < n and b <=3D n */
-#define submod(r,a,b,n)                                                 \
-  do {                                                                  \
-    uintmax_t _t =3D - (uintmax_t) (a < b);                               \
-    (r) =3D ((n) & _t) + (a) - (b);                                       \
-  } while (0)
-
-#define addmod(r,a,b,n)                                                 \
-  submod((r), (a), ((n) - (b)), (n))
-
-/* Modular two-word addition and subtraction.  For performance reasons, the
-   most significant bit of n1 must be clear.  The destination variables mu=
st be
-   distinct from the mod operand.  */
-#define addmod2(r1, r0, a1, a0, b1, b0, n1, n0)                         \
-  do {                                                                  \
-    add_ssaaaa ((r1), (r0), (a1), (a0), (b1), (b0));                    \
-    if (ge2 ((r1), (r0), (n1), (n0)))                                   \
-      sub_ddmmss ((r1), (r0), (r1), (r0), (n1), (n0));                  \
-  } while (0)
-#define submod2(r1, r0, a1, a0, b1, b0, n1, n0)                         \
-  do {                                                                  \
-    sub_ddmmss ((r1), (r0), (a1), (a0), (b1), (b0));                    \
-    if ((intmax_t) (r1) < 0)                                            \
-      add_ssaaaa ((r1), (r0), (r1), (r0), (n1), (n0));                  \
-  } while (0)
-
-#define HIGHBIT_TO_MASK(x)                                              \
-  (((intmax_t)-1 >> 1) < 0                                              \
-   ? (uintmax_t)((intmax_t)(x) >> (W_TYPE_SIZE - 1))                    \
-   : ((x) & ((uintmax_t) 1 << (W_TYPE_SIZE - 1))                        \
-      ? UINTMAX_MAX : (uintmax_t) 0))
-
-/* Compute r =3D a mod d, where r =3D <*t1,retval>, a =3D <a1,a0>, d =3D <=
d1,d0>.
-   Requires that d1 !=3D 0.  */
-static uintmax_t
-mod2 (uintmax_t *r1, uintmax_t a1, uintmax_t a0, uintmax_t d1, uintmax_t d=
0)
-{
-  int cntd, cnta;
-
-  assert (d1 !=3D 0);
-
-  if (a1 =3D=3D 0)
-    {
-      *r1 =3D 0;
-      return a0;
-    }
-
-  count_leading_zeros (cntd, d1);
-  count_leading_zeros (cnta, a1);
-  int cnt =3D cntd - cnta;
-  lsh2 (d1, d0, d1, d0, cnt);
-  for (int i =3D 0; i < cnt; i++)
-    {
-      if (ge2 (a1, a0, d1, d0))
-        sub_ddmmss (a1, a0, a1, a0, d1, d0);
-      rsh2 (d1, d0, d1, d0, 1);
-    }
-
-  *r1 =3D a1;
-  return a0;
-}
-
-static uintmax_t _GL_ATTRIBUTE_CONST
-gcd_odd (uintmax_t a, uintmax_t b)
-{
-  if ( (b & 1) =3D=3D 0)
-    {
-      uintmax_t t =3D b;
-      b =3D a;
-      a =3D t;
-    }
-  if (a =3D=3D 0)
-    return b;
-
-  /* Take out least significant one bit, to make room for sign */
-  b >>=3D 1;
-
-  for (;;)
-    {
-      uintmax_t t;
-      uintmax_t bgta;
-
-      while ((a & 1) =3D=3D 0)
-        a >>=3D 1;
-      a >>=3D 1;
-
-      t =3D a - b;
-      if (t =3D=3D 0)
-        return (a << 1) + 1;
-
-      bgta =3D HIGHBIT_TO_MASK (t);
-
-      /* b <-- min (a, b) */
-      b +=3D (bgta & t);
-
-      /* a <-- |a - b| */
-      a =3D (t ^ bgta) - bgta;
-    }
-}
-
-static uintmax_t
-gcd2_odd (uintmax_t *r1, uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax=
_t b0)
-{
-  while ((a0 & 1) =3D=3D 0)
-    rsh2 (a1, a0, a1, a0, 1);
-  while ((b0 & 1) =3D=3D 0)
-    rsh2 (b1, b0, b1, b0, 1);
-
-  for (;;)
-    {
-      if ((b1 | a1) =3D=3D 0)
-        {
-          *r1 =3D 0;
-          return gcd_odd (b0, a0);
-        }
-
-      if (gt2 (a1, a0, b1, b0))
-        {
-          sub_ddmmss (a1, a0, a1, a0, b1, b0);
-          do
-            rsh2 (a1, a0, a1, a0, 1);
-          while ((a0 & 1) =3D=3D 0);
-        }
-      else if (gt2 (b1, b0, a1, a0))
-        {
-          sub_ddmmss (b1, b0, b1, b0, a1, a0);
-          do
-            rsh2 (b1, b0, b1, b0, 1);
-          while ((b0 & 1) =3D=3D 0);
-        }
-      else
-        break;
-    }
-
-  *r1 =3D a1;
-  return a0;
-}
-
-static void
-factor_insert_multiplicity (struct factors *factors,
-                            uintmax_t prime, unsigned int m)
-{
-  unsigned int nfactors =3D factors->nfactors;
-  uintmax_t *p =3D factors->p;
-  unsigned char *e =3D factors->e;
-
-  /* Locate position for insert new or increment e.  */
-  int i;
-  for (i =3D nfactors - 1; i >=3D 0; i--)
-    {
-      if (p[i] <=3D prime)
-        break;
-    }
-
-  if (i < 0 || p[i] !=3D prime)
-    {
-      for (int j =3D nfactors - 1; j > i; j--)
-        {
-          p[j + 1] =3D p[j];
-          e[j + 1] =3D e[j];
-        }
-      p[i + 1] =3D prime;
-      e[i + 1] =3D m;
-      factors->nfactors =3D nfactors + 1;
-    }
-  else
-    {
-      e[i] +=3D m;
-    }
-}
-
-#define factor_insert(f, p) factor_insert_multiplicity(f, p, 1)
-
-static void
-factor_insert_large (struct factors *factors,
-                     uintmax_t p1, uintmax_t p0)
-{
-  if (p1 > 0)
-    {
-      assert (factors->plarge[1] =3D=3D 0);
-      factors->plarge[0] =3D p0;
-      factors->plarge[1] =3D p1;
-    }
-  else
-    factor_insert (factors, p0);
-}
-
-#if HAVE_GMP
-static void mp_factor (mpz_t, struct mp_factors *);
-
-static void
-mp_factor_init (struct mp_factors *factors)
-{
-  factors->p =3D malloc (1);
-  factors->e =3D malloc (1);
-  factors->nfactors =3D 0;
-}
-
-static void
-mp_factor_clear (struct mp_factors *factors)
-{
-  for (unsigned int i =3D 0; i < factors->nfactors; i++)
-    mpz_clear (factors->p[i]);
-
-  free (factors->p);
-  free (factors->e);
-}
-
-static void
-mp_factor_insert (struct mp_factors *factors, mpz_t prime)
-{
-  unsigned long int nfactors =3D factors->nfactors;
-  mpz_t         *p  =3D factors->p;
-  unsigned long int *e  =3D factors->e;
-  long i;
-
-  /* Locate position for insert new or increment e.  */
-  for (i =3D nfactors - 1; i >=3D 0; i--)
-    {
-      if (mpz_cmp (p[i], prime) <=3D 0)
-        break;
-    }
-
-  if (i < 0 || mpz_cmp (p[i], prime) !=3D 0)
-    {
-      p =3D realloc (p, (nfactors + 1) * sizeof p[0]);
-      e =3D realloc (e, (nfactors + 1) * sizeof e[0]);
-
-      mpz_init (p[nfactors]);
-      for (long j =3D nfactors - 1; j > i; j--)
-        {
-          mpz_set (p[j + 1], p[j]);
-          e[j + 1] =3D e[j];
-        }
-      mpz_set (p[i + 1], prime);
-      e[i + 1] =3D 1;
-
-      factors->p =3D p;
-      factors->e =3D e;
-      factors->nfactors =3D nfactors + 1;
-    }
-  else
-    {
-      e[i] +=3D 1;
-    }
-}
-
-static void
-mp_factor_insert_ui (struct mp_factors *factors, unsigned long int prime)
-{
-  mpz_t pz;
-
-  mpz_init_set_ui (pz, prime);
-  mp_factor_insert (factors, pz);
-  mpz_clear (pz);
-}
-#endif /* HAVE_GMP */
-
-
-#define P(a,b,c,d) a,
-static const unsigned char primes_diff[] =3D {
-#include "primes.h"
-0,0,0,0,0,0,0                           /* 7 sentinels for 8-way loop */
-};
-#undef P
-
-#define PRIMES_PTAB_ENTRIES (sizeof(primes_diff) / sizeof(primes_diff[0]) =
- 8 + 1)
-
-#define P(a,b,c,d) b,
-static const unsigned char primes_diff8[] =3D {
-#include "primes.h"
-0,0,0,0,0,0,0                           /* 7 sentinels for 8-way loop */
-};
-#undef P
-
-struct primes_dtab
-{
-  uintmax_t binv, lim;
-};
-
-#define P(a,b,c,d) {c,d},
-static const struct primes_dtab primes_dtab[] =3D {
-#include "primes.h"
-{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0} /* 7 sentinels for 8-way loop */
-};
-#undef P
-
-/* This flag is honoured just in the GMP code. */
-static int flag_verbose =3D 0;
-
-/* Prove primality or run probabilistic tests.  */
-static int flag_prove_primality =3D 1;
-
-/* Number of Miller-Rabin tests to run when not proving primality. */
-#define MR_REPS 25
-
-#define LIKELY(cond)    __builtin_expect ((cond) !=3D 0, 1)
-#define UNLIKELY(cond)  __builtin_expect ((cond) !=3D 0, 0)
-
-static void
-factor_insert_refind (struct factors *factors, uintmax_t p, unsigned int i,
-                      unsigned int off)
-{
-  for (unsigned int j =3D 0; j < off; j++)
-    p +=3D primes_diff[i + j];
-  factor_insert (factors, p);
-}
-
-/* Trial division with odd primes uses the following trick.
-
-   Let p be an odd prime, and B =3D 2^{W_TYPE_SIZE}. For simplicity,
-   consider the case t < B (this is the second loop below).
-
-   From our tables we get
-
-     binv =3D p^{-1} (mod B)
-     lim =3D floor ( (B-1) / p ).
-
-   First assume that t is a multiple of p, t =3D q * p. Then 0 <=3D q <=3D
-   lim (and all quotients in this range occur for some t).
-
-   Then t =3D q * p is true also (mod B), and p is invertible we get
-
-     q =3D t * binv (mod B).
-
-   Next, assume that t is *not* divisible by p. Since multiplication
-   by binv (mod B) is a one-to-one mapping,
-
-     t * binv (mod B) > lim,
-
-   because all the smaller values are already taken.
-
-   This can be summed up by saying that the function
-
-     q(t) =3D binv * t (mod B)
-
-   is a permutation of the range 0 <=3D t < B, with the curious property
-   that it maps the multiples of p onto the range 0 <=3D q <=3D lim, in
-   order, and the non-multiples of p onto the range lim < q < B.
- */
-
-static uintmax_t
-factor_using_division (uintmax_t *t1p, uintmax_t t1, uintmax_t t0,
-                       struct factors *factors)
-{
-  if (t0 % 2 =3D=3D 0)
-    {
-      unsigned int cnt;
-
-      if (t0 =3D=3D 0)
-        {
-          count_trailing_zeros (cnt, t1);
-          t0 =3D t1 >> cnt;
-          t1 =3D 0;
-          cnt +=3D W_TYPE_SIZE;
-        }
-      else
-        {
-          count_trailing_zeros (cnt, t0);
-          rsh2 (t1, t0, t1, t0, cnt);
-        }
-
-      factor_insert_multiplicity (factors, 2, cnt);
-    }
-
-  uintmax_t p =3D 3;
-  unsigned int i;
-  for (i =3D 0; t1 > 0 && i < PRIMES_PTAB_ENTRIES; i++)
-    {
-      for (;;)
-        {
-          uintmax_t q1, q0, hi, lo;
-
-          q0 =3D t0 * primes_dtab[i].binv;
-          umul_ppmm (hi, lo, q0, p);
-          if (hi > t1)
-            break;
-          hi =3D t1 - hi;
-          q1 =3D hi * primes_dtab[i].binv;
-          if (LIKELY (q1 > primes_dtab[i].lim))
-            break;
-          t1 =3D q1; t0 =3D q0;
-          factor_insert (factors, p);
-        }
-      p +=3D primes_diff[i + 1];
-    }
-  if (t1p)
-    *t1p =3D t1;
-
-#define DIVBLOCK(I)                                                     \
-  do {                                                                  \
-    for (;;)                                                            \
-      {                                                                 \
-        q =3D t0 * pd[I].binv;                                            \
-        if (LIKELY (q > pd[I].lim))                                     \
-          break;                                                        \
-        t0 =3D q;                                                         \
-        factor_insert_refind (factors, p, i + 1, I);                    \
-      }                                                                 \
-  } while (0)
-
-  for (; i < PRIMES_PTAB_ENTRIES; i +=3D 8)
-    {
-      uintmax_t q;
-      const struct primes_dtab *pd =3D &primes_dtab[i];
-      DIVBLOCK (0);
-      DIVBLOCK (1);
-      DIVBLOCK (2);
-      DIVBLOCK (3);
-      DIVBLOCK (4);
-      DIVBLOCK (5);
-      DIVBLOCK (6);
-      DIVBLOCK (7);
-
-      p +=3D primes_diff8[i];
-      if (p * p > t0)
-        break;
-    }
-
-  return t0;
-}
-
-#if HAVE_GMP
-static void
-mp_factor_using_division (mpz_t t, struct mp_factors *factors)
-{
-  mpz_t q;
-  unsigned long int p;
-
-  if (flag_verbose > 0)
-    {
-      printf ("[trial division] ");
-    }
-
-  mpz_init (q);
-
-  p =3D mpz_scan1 (t, 0);
-  mpz_div_2exp (t, t, p);
-  while (p)
-    {
-      mp_factor_insert_ui (factors, 2);
-      --p;
-    }
-
-  p =3D 3;
-  for (unsigned int i =3D 1; i <=3D PRIMES_PTAB_ENTRIES;)
-    {
-      if (! mpz_divisible_ui_p (t, p))
-        {
-          p +=3D primes_diff[i++];
-          if (mpz_cmp_ui (t, p * p) < 0)
-            break;
-        }
-      else
-        {
-          mpz_tdiv_q_ui (t, t, p);
-          mp_factor_insert_ui (factors, p);
-        }
-    }
-
-  mpz_clear (q);
-}
-#endif
-
-/* Entry i contains (2i+1)^(-1) mod 2^8.  */
-static const unsigned char  binvert_table[128] =3D
-{
-  0x01, 0xAB, 0xCD, 0xB7, 0x39, 0xA3, 0xC5, 0xEF,
-  0xF1, 0x1B, 0x3D, 0xA7, 0x29, 0x13, 0x35, 0xDF,
-  0xE1, 0x8B, 0xAD, 0x97, 0x19, 0x83, 0xA5, 0xCF,
-  0xD1, 0xFB, 0x1D, 0x87, 0x09, 0xF3, 0x15, 0xBF,
-  0xC1, 0x6B, 0x8D, 0x77, 0xF9, 0x63, 0x85, 0xAF,
-  0xB1, 0xDB, 0xFD, 0x67, 0xE9, 0xD3, 0xF5, 0x9F,
-  0xA1, 0x4B, 0x6D, 0x57, 0xD9, 0x43, 0x65, 0x8F,
-  0x91, 0xBB, 0xDD, 0x47, 0xC9, 0xB3, 0xD5, 0x7F,
-  0x81, 0x2B, 0x4D, 0x37, 0xB9, 0x23, 0x45, 0x6F,
-  0x71, 0x9B, 0xBD, 0x27, 0xA9, 0x93, 0xB5, 0x5F,
-  0x61, 0x0B, 0x2D, 0x17, 0x99, 0x03, 0x25, 0x4F,
-  0x51, 0x7B, 0x9D, 0x07, 0x89, 0x73, 0x95, 0x3F,
-  0x41, 0xEB, 0x0D, 0xF7, 0x79, 0xE3, 0x05, 0x2F,
-  0x31, 0x5B, 0x7D, 0xE7, 0x69, 0x53, 0x75, 0x1F,
-  0x21, 0xCB, 0xED, 0xD7, 0x59, 0xC3, 0xE5, 0x0F,
-  0x11, 0x3B, 0x5D, 0xC7, 0x49, 0x33, 0x55, 0xFF
-};
-
-/* Compute n^(-1) mod B, using a Newton iteration.  */
-#define binv(inv,n)                                                     \
-  do {                                                                  \
-    uintmax_t  __n =3D (n);                                               \
-    uintmax_t  __inv;                                                   \
-                                                                        \
-    __inv =3D binvert_table[(__n / 2) & 0x7F]; /*  8 */                   \
-    if (W_TYPE_SIZE > 8)   __inv =3D 2 * __inv - __inv * __inv * __n;     \
-    if (W_TYPE_SIZE > 16)  __inv =3D 2 * __inv - __inv * __inv * __n;     \
-    if (W_TYPE_SIZE > 32)  __inv =3D 2 * __inv - __inv * __inv * __n;     \
-                                                                        \
-    if (W_TYPE_SIZE > 64)                                               \
-      {                                                                 \
-        int  __invbits =3D 64;                                            \
-        do {                                                            \
-          __inv =3D 2 * __inv - __inv * __inv * __n;                      \
-          __invbits *=3D 2;                                               \
-        } while (__invbits < W_TYPE_SIZE);                              \
-      }                                                                 \
-                                                                        \
-    (inv) =3D __inv;                                                      \
-  } while (0)
-
-/* q =3D u / d, assuming d|u.  */
-#define divexact_21(q1, q0, u1, u0, d)                                  \
-  do {                                                                  \
-    uintmax_t _di, _q0;                                                 \
-    binv (_di, (d));                                                    \
-    _q0 =3D (u0) * _di;                                                   \
-    if ((u1) >=3D (d))                                                    \
-      {                                                                 \
-        uintmax_t _p1, _p0;                                             \
-        umul_ppmm (_p1, _p0, _q0, d);                                   \
-        (q1) =3D ((u1) - _p1) * _di;                                      \
-        (q0) =3D _q0;                                                     \
-      }                                                                 \
-    else                                                                \
-      {                                                                 \
-        (q0) =3D _q0;                                                     \
-        (q1) =3D 0;                                                       \
-      }                                                                 \
-  } while(0)
-
-/* x B (mod n). */
-#define redcify(r_prim, r, n)                                           \
-  do {                                                                  \
-    uintmax_t _redcify_q;                                               \
-    udiv_qrnnd (_redcify_q, r_prim, r, 0, n);                           \
-  } while (0)
-
-/* x B^2 (mod n). Requires x > 0, n1 < B/2 */
-#define redcify2(r1, r0, x, n1, n0)                                     \
-  do {                                                                  \
-    uintmax_t _r1, _r0, _i;                                             \
-    if ((x) < (n1))                                                     \
-      {                                                                 \
-        _r1 =3D (x); _r0 =3D 0;                                           =
  \
-        _i =3D W_TYPE_SIZE;                                               \
-      }                                                                 \
-    else                                                                \
-      {                                                                 \
-        _r1 =3D 0; _r0 =3D (x);                                           =
  \
-        _i =3D 2*W_TYPE_SIZE;                                             \
-      }                                                                 \
-    while (_i-- > 0)                                                    \
-      {                                                                 \
-        lsh2 (_r1, _r0, _r1, _r0, 1);                                   \
-        if (ge2 (_r1, _r0, (n1), (n0)))                                 \
-          sub_ddmmss (_r1, _r0, _r1, _r0, (n1), (n0));                  \
-      }                                                                 \
-    (r1) =3D _r1;                                                         \
-    (r0) =3D _r0;                                                         \
-  } while (0)
-
-/* Modular two-word multiplication, r =3D a * b mod m, with mi =3D m^(-1) =
mod B.
-   Both a and b must be in redc form, the result will be in redc form too.=
 */
-static inline uintmax_t
-mulredc (uintmax_t a, uintmax_t b, uintmax_t m, uintmax_t mi)
-{
-  uintmax_t rh, rl, q, th, tl, xh;
-
-  umul_ppmm (rh, rl, a, b);
-  q =3D rl * mi;
-  umul_ppmm (th, tl, q, m);
-  xh =3D rh - th;
-  if (rh < th)
-    xh +=3D m;
-
-  return xh;
-}
-
-/* Modular two-word multiplication, r =3D a * b mod m, with mi =3D m^(-1) =
mod B.
-   Both a and b must be in redc form, the result will be in redc form too.
-   For performance reasons, the most significant bit of m must be clear. */
-static uintmax_t
-mulredc2 (uintmax_t *r1p,
-          uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax_t b0,
-          uintmax_t m1, uintmax_t m0, uintmax_t mi)
-{
-  uintmax_t r1, r0, q, p1, p0, t1, t0, s1, s0;
-  mi =3D -mi;
-  assert ( (a1 >> (W_TYPE_SIZE - 1)) =3D=3D 0);
-  assert ( (b1 >> (W_TYPE_SIZE - 1)) =3D=3D 0);
-  assert ( (m1 >> (W_TYPE_SIZE - 1)) =3D=3D 0);
-
-  /* First compute a0 * <b1, b0> B^{-1}
-        +-----+
-        |a0 b0|
-     +--+--+--+
-     |a0 b1|
-     +--+--+--+
-        |q0 m0|
-     +--+--+--+
-     |q0 m1|
-    -+--+--+--+
-     |r1|r0| 0|
-     +--+--+--+
-  */
-  umul_ppmm (t1, t0, a0, b0);
-  umul_ppmm (r1, r0, a0, b1);
-  q =3D mi * t0;
-  umul_ppmm (p1, p0, q, m0);
-  umul_ppmm (s1, s0, q, m1);
-  r0 +=3D (t0 !=3D 0); /* Carry */
-  add_ssaaaa (r1, r0, r1, r0, 0, p1);
-  add_ssaaaa (r1, r0, r1, r0, 0, t1);
-  add_ssaaaa (r1, r0, r1, r0, s1, s0);
-
-  /* Next, (a1 * <b1, b0> + <r1, r0> B^{-1}
-        +-----+
-        |a1 b0|
-        +--+--+
-        |r1|r0|
-     +--+--+--+
-     |a1 b1|
-     +--+--+--+
-        |q1 m0|
-     +--+--+--+
-     |q1 m1|
-    -+--+--+--+
-     |r1|r0| 0|
-     +--+--+--+
-  */
-  umul_ppmm (t1, t0, a1, b0);
-  umul_ppmm (s1, s0, a1, b1);
-  add_ssaaaa (t1, t0, t1, t0, 0, r0);
-  q =3D mi * t0;
-  add_ssaaaa (r1, r0, s1, s0, 0, r1);
-  umul_ppmm (p1, p0, q, m0);
-  umul_ppmm (s1, s0, q, m1);
-  r0 +=3D (t0 !=3D 0); /* Carry */
-  add_ssaaaa (r1, r0, r1, r0, 0, p1);
-  add_ssaaaa (r1, r0, r1, r0, 0, t1);
-  add_ssaaaa (r1, r0, r1, r0, s1, s0);
-
-  if (ge2 (r1, r0, m1, m0))
-    sub_ddmmss (r1, r0, r1, r0, m1, m0);
-
-  *r1p =3D r1;
-  return r0;
-}
-
-static uintmax_t _GL_ATTRIBUTE_CONST
-powm (uintmax_t b, uintmax_t e, uintmax_t n, uintmax_t ni, uintmax_t one)
-{
-  uintmax_t y =3D one;
-
-  if (e & 1)
-    y =3D b;
-
-  while (e !=3D 0)
-    {
-      b =3D mulredc (b, b, n, ni);
-      e >>=3D 1;
-
-      if (e & 1)
-        y =3D mulredc (y, b, n, ni);
-    }
-
-  return y;
-}
-
-static uintmax_t
-powm2 (uintmax_t *r1m,
-       const uintmax_t *bp, const uintmax_t *ep, const uintmax_t *np,
-       uintmax_t ni, const uintmax_t *one)
-{
-  uintmax_t r1, r0, b1, b0, n1, n0;
-  unsigned int i;
-  uintmax_t e;
-
-  b0 =3D bp[0];
-  b1 =3D bp[1];
-  n0 =3D np[0];
-  n1 =3D np[1];
-
-  r0 =3D one[0];
-  r1 =3D one[1];
-
-  for (e =3D ep[0], i =3D W_TYPE_SIZE; i > 0; i--, e >>=3D 1)
-    {
-      if (e & 1)
-        {
-          r0 =3D mulredc2 (r1m, r1, r0, b1, b0, n1, n0, ni);
-          r1 =3D *r1m;
-        }
-      b0 =3D mulredc2 (r1m, b1, b0, b1, b0, n1, n0, ni);
-      b1 =3D *r1m;
-    }
-  for (e =3D ep[1]; e > 0; e >>=3D 1)
-    {
-      if (e & 1)
-        {
-          r0 =3D mulredc2 (r1m, r1, r0, b1, b0, n1, n0, ni);
-          r1 =3D *r1m;
-        }
-      b0 =3D mulredc2 (r1m, b1, b0, b1, b0, n1, n0, ni);
-      b1 =3D *r1m;
-    }
-  *r1m =3D r1;
-  return r0;
-}
-
-static bool _GL_ATTRIBUTE_CONST
-millerrabin (uintmax_t n, uintmax_t ni, uintmax_t b, uintmax_t q,
-             unsigned int k, uintmax_t one)
-{
-  uintmax_t y =3D powm (b, q, n, ni, one);
-
-  uintmax_t nm1 =3D n - one;      /* -1, but in redc representation. */
-
-  if (y =3D=3D one || y =3D=3D nm1)
-    return true;
-
-  for (unsigned int i =3D 1; i < k; i++)
-    {
-      y =3D mulredc (y, y, n, ni);
-
-      if (y =3D=3D nm1)
-        return true;
-      if (y =3D=3D one)
-        return false;
-    }
-  return false;
-}
-
-static bool
-millerrabin2 (const uintmax_t *np, uintmax_t ni, const uintmax_t *bp,
-              const uintmax_t *qp, unsigned int k, const uintmax_t *one)
-{
-  uintmax_t y1, y0, nm1_1, nm1_0, r1m;
-
-  y0 =3D powm2 (&r1m, bp, qp, np, ni, one);
-  y1 =3D r1m;
-
-  if (y0 =3D=3D one[0] && y1 =3D=3D one[1])
-    return true;
-
-  sub_ddmmss (nm1_1, nm1_0, np[1], np[0], one[1], one[0]);
-
-  if (y0 =3D=3D nm1_0 && y1 =3D=3D nm1_1)
-    return true;
-
-  for (unsigned int i =3D 1; i < k; i++)
-    {
-      y0 =3D mulredc2 (&r1m, y1, y0, y1, y0, np[1], np[0], ni);
-      y1 =3D r1m;
-
-      if (y0 =3D=3D nm1_0 && y1 =3D=3D nm1_1)
-        return true;
-      if (y0 =3D=3D one[0] && y1 =3D=3D one[1])
-        return false;
-    }
-  return false;
-}
-
-#if HAVE_GMP
-static bool
-mp_millerrabin (mpz_srcptr n, mpz_srcptr nm1, mpz_ptr x, mpz_ptr y,
-                mpz_srcptr q, unsigned long int k)
-{
-  mpz_powm (y, x, q, n);
-
-  if (mpz_cmp_ui (y, 1) =3D=3D 0 || mpz_cmp (y, nm1) =3D=3D 0)
-    return true;
-
-  for (unsigned long int i =3D 1; i < k; i++)
-    {
-      mpz_powm_ui (y, y, 2, n);
-      if (mpz_cmp (y, nm1) =3D=3D 0)
-        return true;
-      if (mpz_cmp_ui (y, 1) =3D=3D 0)
-        return false;
-    }
-  return false;
-}
-#endif
-
-/* Lucas' prime test.  The number of iterations vary greatly, up to a few =
dozen
-   have been observed.  The average seem to be about 2.  */
-static bool
-prime_p (uintmax_t n)
-{
-  int k;
-  bool is_prime;
-  uintmax_t a_prim, one, ni;
-  struct factors factors;
-
-  if (n <=3D 1)
-    return false;
-
-  /* We have already casted out small primes. */
-  if (n < (uintmax_t) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME)
-    return true;
-
-  /* Precomputation for Miller-Rabin.  */
-  uintmax_t q =3D n - 1;
-  for (k =3D 0; (q & 1) =3D=3D 0; k++)
-    q >>=3D 1;
-
-  uintmax_t a =3D 2;
-  binv (ni, n);                 /* ni <- 1/n mod B */
-  redcify (one, 1, n);
-  addmod (a_prim, one, one, n); /* i.e., redcify a =3D 2 */
-
-  /* Perform a Miller-Rabin test, finds most composites quickly.  */
-  if (!millerrabin (n, ni, a_prim, q, k, one))
-    return false;
-
-  if (flag_prove_primality)
-    {
-      /* Factor n-1 for Lucas.  */
-      factor (0, n - 1, &factors);
-    }
-
-  /* Loop until Lucas proves our number prime, or Miller-Rabin proves our
-     number composite.  */
-  for (unsigned int r =3D 0; r < PRIMES_PTAB_ENTRIES; r++)
-    {
-      if (flag_prove_primality)
-        {
-          is_prime =3D true;
-          for (unsigned int i =3D 0; i < factors.nfactors && is_prime; i++)
-            {
-              is_prime =3D powm (a_prim, (n - 1) / factors.p[i], n, ni, on=
e) !=3D one;
-            }
-        }
-      else
-        {
-          /* After enough Miller-Rabin runs, be content. */
-          is_prime =3D (r =3D=3D MR_REPS - 1);
-        }
-
-      if (is_prime)
-        return true;
-
-      a +=3D primes_diff[r];      /* Establish new base.  */
-
-      /* The following is equivalent to redcify (a_prim, a, n).  It runs f=
aster
-         on most processors, since it avoids udiv_qrnnd.  If we go down the
-         udiv_qrnnd_preinv path, this code should be replaced.  */
-      {
-        uintmax_t dummy, s1, s0;
-        umul_ppmm (s1, s0, one, a);
-        if (LIKELY (s1 =3D=3D 0))
-          a_prim =3D s0 % n;
-        else
-          udiv_qrnnd (dummy, a_prim, s1, s0, n);
-      }
-
-      if (!millerrabin (n, ni, a_prim, q, k, one))
-        return false;
-    }
-
-  fprintf (stderr, "Lucas prime test failure.  This should not happen\n");
-  abort ();
-}
-
-static bool
-prime2_p (uintmax_t n1, uintmax_t n0)
-{
-  uintmax_t q[2], nm1[2];
-  uintmax_t a_prim[2];
-  uintmax_t one[2];
-  uintmax_t na[2];
-  uintmax_t ni;
-  unsigned int k;
-  struct factors factors;
-
-  if (n1 =3D=3D 0)
-    return prime_p (n0);
-
-  nm1[1] =3D n1 - (n0 =3D=3D 0);
-  nm1[0] =3D n0 - 1;
-  if (nm1[0] =3D=3D 0)
-    {
-      count_trailing_zeros (k, nm1[1]);
-
-      q[0] =3D nm1[1] >> k;
-      q[1] =3D 0;
-      k +=3D W_TYPE_SIZE;
-    }
-  else
-    {
-      count_trailing_zeros (k, nm1[0]);
-      rsh2 (q[1], q[0], nm1[1], nm1[0], k);
-    }
-
-  uintmax_t a =3D 2;
-  binv (ni, n0);
-  redcify2 (one[1], one[0], 1, n1, n0);
-  addmod2 (a_prim[1], a_prim[0], one[1], one[0], one[1], one[0], n1, n0);
-
-  /* FIXME: Use scalars or pointers in arguments? Some consistency needed.=
 */
-  na[0] =3D n0;
-  na[1] =3D n1;
-
-  if (!millerrabin2 (na, ni, a_prim, q, k, one))
-    return false;
-
-  if (flag_prove_primality)
-    {
-      /* Factor n-1 for Lucas.  */
-      factor (nm1[1], nm1[0], &factors);
-    }
-
-  /* Loop until Lucas proves our number prime, or Miller-Rabin proves our
-     number composite.  */
-  for (unsigned int r =3D 0; r < PRIMES_PTAB_ENTRIES; r++)
-    {
-      bool is_prime;
-      uintmax_t e[2], y[2];
-
-      if (flag_prove_primality)
-        {
-          is_prime =3D true;
-          if (factors.plarge[1])
-            {
-              uintmax_t pi;
-              binv (pi, factors.plarge[0]);
-              e[0] =3D pi * nm1[0];
-              e[1] =3D 0;
-              y[0] =3D powm2 (&y[1], a_prim, e, na, ni, one);
-              is_prime =3D (y[0] !=3D one[0] || y[1] !=3D one[1]);
-            }
-          for (unsigned int i =3D 0; i < factors.nfactors && is_prime; i++)
-            {
-              /* FIXME: We always have the factor 2. Do we really need to =
handle it
-                 here? We have done the same powering as part of millerrab=
in. */
-              if (factors.p[i] =3D=3D 2)
-                rsh2 (e[1], e[0], nm1[1], nm1[0], 1);
-              else
-                divexact_21 (e[1], e[0], nm1[1], nm1[0], factors.p[i]);
-              y[0] =3D powm2 (&y[1], a_prim, e, na, ni, one);
-              is_prime =3D (y[0] !=3D one[0] || y[1] !=3D one[1]);
-            }
-        }
-      else
-        {
-          /* After enough Miller-Rabin runs, be content. */
-          is_prime =3D (r =3D=3D MR_REPS - 1);
-        }
-
-      if (is_prime)
-        return true;
-
-      a +=3D primes_diff[r];      /* Establish new base.  */
-      redcify2 (a_prim[1], a_prim[0], a, n1, n0);
-
-      if (!millerrabin2 (na, ni, a_prim, q, k, one))
-        return false;
-    }
-
-  fprintf (stderr, "Lucas prime test failure.  This should not happen\n");
-  abort ();
-}
-
-#if HAVE_GMP
-static bool
-mp_prime_p (mpz_t n)
-{
-  bool is_prime;
-  mpz_t q, a, nm1, tmp;
-  struct mp_factors factors;
-
-  if (mpz_cmp_ui (n, 1) <=3D 0)
-    return false;
-
-  /* We have already casted out small primes. */
-  if (mpz_cmp_ui (n, (long) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME) < 0)
-    return true;
-
-  mpz_inits (q, a, nm1, tmp, NULL);
-
-  /* Precomputation for Miller-Rabin.  */
-  mpz_sub_ui (nm1, n, 1);
-
-  /* Find q and k, where q is odd and n =3D 1 + 2**k * q.  */
-  unsigned long int k =3D mpz_scan1 (nm1, 0);
-  mpz_tdiv_q_2exp (q, nm1, k);
-
-  mpz_set_ui (a, 2);
-
-  /* Perform a Miller-Rabin test, finds most composites quickly.  */
-  if (!mp_millerrabin (n, nm1, a, tmp, q, k))
-    {
-      is_prime =3D false;
-      goto ret2;
-    }
-
-  if (flag_prove_primality)
-    {
-      /* Factor n-1 for Lucas.  */
-      mpz_set (tmp, nm1);
-      mp_factor (tmp, &factors);
-    }
-
-  /* Loop until Lucas proves our number prime, or Miller-Rabin proves our
-     number composite.  */
-  for (unsigned int r =3D 0; r < PRIMES_PTAB_ENTRIES; r++)
-    {
-      if (flag_prove_primality)
-        {
-          is_prime =3D true;
-          for (unsigned long int i =3D 0; i < factors.nfactors && is_prime=
; i++)
-            {
-              mpz_divexact (tmp, nm1, factors.p[i]);
-              mpz_powm (tmp, a, tmp, n);
-              is_prime =3D mpz_cmp_ui (tmp, 1) !=3D 0;
-            }
-        }
-      else
-        {
-          /* After enough Miller-Rabin runs, be content. */
-          is_prime =3D (r =3D=3D MR_REPS - 1);
-        }
-
-      if (is_prime)
-        goto ret1;
-
-      mpz_add_ui (a, a, primes_diff[r]);        /* Establish new base.  */
-
-      if (!mp_millerrabin (n, nm1, a, tmp, q, k))
-        {
-          is_prime =3D false;
-          goto ret1;
-        }
-    }
-
-  fprintf (stderr, "Lucas prime test failure.  This should not happen\n");
-  abort ();
-
- ret1:
-  if (flag_prove_primality)
-    mp_factor_clear (&factors);
- ret2:
-  mpz_clears (q, a, nm1, tmp, NULL);
-
-  return is_prime;
-}
-#endif
-
-static void
-factor_using_pollard_rho (uintmax_t n, unsigned long int a,
-                          struct factors *factors)
-{
-  uintmax_t x, z, y, P, t, ni, g;
-
-  unsigned long int k =3D 1;
-  unsigned long int l =3D 1;
-
-  redcify (P, 1, n);
-  addmod (x, P, P, n);          /* i.e., redcify(2) */
-  y =3D z =3D x;
-
-  while (n !=3D 1)
-    {
-      assert (a < n);
-
-      binv (ni, n);             /* FIXME: when could we use old 'ni' value=
? */
-
-      for (;;)
-        {
-          do
-            {
-              x =3D mulredc (x, x, n, ni);
-              addmod (x, x, a, n);
-
-              submod (t, z, x, n);
-              P =3D mulredc (P, t, n, ni);
-
-              if (k % 32 =3D=3D 1)
-                {
-                  if (gcd_odd (P, n) !=3D 1)
-                    goto factor_found;
-                  y =3D x;
-                }
-            }
-          while (--k !=3D 0);
-
-          z =3D x;
-          k =3D l;
-          l =3D 2 * l;
-          for (unsigned long int i =3D 0; i < k; i++)
-            {
-              x =3D mulredc (x, x, n, ni);
-              addmod (x, x, a, n);
-            }
-          y =3D x;
-        }
-
-    factor_found:
-      do
-        {
-          y =3D mulredc (y, y, n, ni);
-          addmod (y, y, a, n);
-
-          submod (t, z, y, n);
-          g =3D gcd_odd (t, n);
-        }
-      while (g =3D=3D 1);
-
-      n =3D n / g;
-
-      if (!prime_p (g))
-        factor_using_pollard_rho (g, a + 1, factors);
-      else
-        factor_insert (factors, g);
-
-      if (prime_p (n))
-        {
-          factor_insert (factors, n);
-          break;
-        }
-
-      x =3D x % n;
-      z =3D z % n;
-      y =3D y % n;
-    }
-}
-
-static void
-factor_using_pollard_rho2 (uintmax_t n1, uintmax_t n0, unsigned long int a,
-                           struct factors *factors)
-{
-  uintmax_t x1, x0, z1, z0, y1, y0, P1, P0, t1, t0, ni, g1, g0, r1m;
-
-  unsigned long int k =3D 1;
-  unsigned long int l =3D 1;
-
-  redcify2 (P1, P0, 1, n1, n0);
-  addmod2 (x1, x0, P1, P0, P1, P0, n1, n0); /* i.e., redcify(2) */
-  y1 =3D z1 =3D x1;
-  y0 =3D z0 =3D x0;
-
-  while (n1 !=3D 0 || n0 !=3D 1)
-    {
-      binv (ni, n0);
-
-      for (;;)
-        {
-          do
-            {
-              x0 =3D mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
-              x1 =3D r1m;
-              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
-
-              submod2 (t1, t0, z1, z0, x1, x0, n1, n0);
-              P0 =3D mulredc2 (&r1m, P1, P0, t1, t0, n1, n0, ni);
-              P1 =3D r1m;
-
-              if (k % 32 =3D=3D 1)
-                {
-                  g0 =3D gcd2_odd (&g1, P1, P0, n1, n0);
-                  if (g1 !=3D 0 || g0 !=3D 1)
-                    goto factor_found;
-                  y1 =3D x1; y0 =3D x0;
-                }
-            }
-          while (--k !=3D 0);
-
-          z1 =3D x1; z0 =3D x0;
-          k =3D l;
-          l =3D 2 * l;
-          for (unsigned long int i =3D 0; i < k; i++)
-            {
-              x0 =3D mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
-              x1 =3D r1m;
-              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
-            }
-          y1 =3D x1; y0 =3D x0;
-        }
-
-    factor_found:
-      do
-        {
-          y0 =3D mulredc2 (&r1m, y1, y0, y1, y0, n1, n0, ni);
-          y1 =3D r1m;
-          addmod2 (y1, y0, y1, y0, 0, a, n1, n0);
-
-          submod2 (t1, t0, z1, z0, y1, y0, n1, n0);
-          g0 =3D gcd2_odd (&g1, t1, t0, n1, n0);
-        }
-      while (g1 =3D=3D 0 && g0 =3D=3D 1);
-
-      if (g1 =3D=3D 0)
-        {
-          /* The found factor is one word. */
-          divexact_21 (n1, n0, n1, n0, g0);     /* n =3D n / g */
-
-          if (!prime_p (g0))
-            factor_using_pollard_rho (g0, a + 1, factors);
-          else
-            factor_insert (factors, g0);
-        }
-      else
-        {
-          /* The found factor is two words.  This is highly unlikely, thus=
 hard
-             to trigger.  Please be careful before you change this code!  =
*/
-          uintmax_t ginv;
-
-          binv (ginv, g0);      /* Compute n =3D n / g.  Since the result =
will */
-          n0 =3D ginv * n0;       /* fit one word, we can compute the quot=
ient */
-          n1 =3D 0;               /* modulo B, ignoring the high divisor w=
ord. */
-
-          if (!prime2_p (g1, g0))
-            factor_using_pollard_rho2 (g1, g0, a + 1, factors);
-          else
-            factor_insert_large (factors, g1, g0);
-        }
-
-      if (n1 =3D=3D 0)
-        {
-          if (prime_p (n0))
-            {
-              factor_insert (factors, n0);
-              break;
-            }
-
-          factor_using_pollard_rho (n0, a, factors);
-          return;
-        }
-
-      if (prime2_p (n1, n0))
-        {
-          factor_insert_large (factors, n1, n0);
-          break;
-        }
-
-      x0 =3D mod2 (&x1, x1, x0, n1, n0);
-      z0 =3D mod2 (&z1, z1, z0, n1, n0);
-      y0 =3D mod2 (&y1, y1, y0, n1, n0);
-    }
-}
-
-#if HAVE_GMP
-static void
-mp_factor_using_pollard_rho (mpz_t n, unsigned long int a,
-                             struct mp_factors *factors)
-{
-  mpz_t x, z, y, P;
-  mpz_t t, t2;
-  unsigned long long int k, l;
-
-  if (flag_verbose > 0)
-    {
-      printf ("[pollard-rho (%lu)] ", a);
-    }
-
-  mpz_inits (t, t2, NULL);
-  mpz_init_set_si (y, 2);
-  mpz_init_set_si (x, 2);
-  mpz_init_set_si (z, 2);
-  mpz_init_set_ui (P, 1);
-  k =3D 1;
-  l =3D 1;
-
-  while (mpz_cmp_ui (n, 1) !=3D 0)
-    {
-      for (;;)
-        {
-          do
-            {
-              mpz_mul (t, x, x);
-              mpz_mod (x, t, n);
-              mpz_add_ui (x, x, a);
-
-              mpz_sub (t, z, x);
-              mpz_mul (t2, P, t);
-              mpz_mod (P, t2, n);
-
-              if (k % 32 =3D=3D 1)
-                {
-                  mpz_gcd (t, P, n);
-                  if (mpz_cmp_ui (t, 1) !=3D 0)
-                    goto factor_found;
-                  mpz_set (y, x);
-                }
-            }
-          while (--k !=3D 0);
-
-          mpz_set (z, x);
-          k =3D l;
-          l =3D 2 * l;
-          for (unsigned long long int i =3D 0; i < k; i++)
-            {
-              mpz_mul (t, x, x);
-              mpz_mod (x, t, n);
-              mpz_add_ui (x, x, a);
-            }
-          mpz_set (y, x);
-        }
-
-    factor_found:
-      do
-        {
-          mpz_mul (t, y, y);
-          mpz_mod (y, t, n);
-          mpz_add_ui (y, y, a);
-
-          mpz_sub (t, z, y);
-          mpz_gcd (t, t, n);
-        }
-      while (mpz_cmp_ui (t, 1) =3D=3D 0);
-
-      mpz_divexact (n, n, t);   /* divide by t, before t is overwritten */
-
-      if (!mp_prime_p (t))
-        {
-          if (flag_verbose > 0)
-            {
-              printf ("[composite factor--restarting pollard-rho] ");
-            }
-          mp_factor_using_pollard_rho (t, a + 1, factors);
-        }
-      else
-        {
-          mp_factor_insert (factors, t);
-        }
-
-      if (mp_prime_p (n))
-        {
-          mp_factor_insert (factors, n);
-          break;
-        }
-
-      mpz_mod (x, x, n);
-      mpz_mod (z, z, n);
-      mpz_mod (y, y, n);
-    }
-
-  mpz_clears (P, t2, t, z, x, y, NULL);
-}
-#endif
-
-/* FIXME: Maybe better to use an iteration converging to 1/sqrt(n)?  If
-   algorithm is replaced, consider also returning the remainder. */
-static uintmax_t _GL_ATTRIBUTE_CONST
-isqrt (uintmax_t n)
-{
-  uintmax_t x;
-  unsigned c;
-  if (n =3D=3D 0)
-    return 0;
-
-  count_leading_zeros (c, n);
-
-  /* Make x > sqrt(n). This will be invariant through the loop. */
-  x =3D (uintmax_t) 1 << ((W_TYPE_SIZE + 1 - c) / 2);
-
-  for (;;)
-    {
-      uintmax_t y =3D (x + n/x) / 2;
-      if (y >=3D x)
-        return x;
-
-      x =3D y;
-    }
-}
-
-static uintmax_t _GL_ATTRIBUTE_CONST
-isqrt2 (uintmax_t nh, uintmax_t nl)
-{
-  unsigned int shift;
-  uintmax_t x;
-
-  /* Ensures the remainder fits in an uintmax_t. */
-  assert (nh < ((uintmax_t) 1 << (W_TYPE_SIZE - 2)));
-
-  if (nh =3D=3D 0)
-    return isqrt (nl);
-
-  count_leading_zeros (shift, nh);
-  shift &=3D ~1;
-
-  /* Make x > sqrt(n) */
-  x =3D isqrt ( (nh << shift) + (nl >> (W_TYPE_SIZE - shift))) + 1;
-  x <<=3D (W_TYPE_SIZE - shift) / 2;
-
-  /* Do we need more than one iteration? */
-  for (;;)
-    {
-      uintmax_t q, r, y;
-      udiv_qrnnd (q, r, nh, nl, x);
-      y =3D (x + q) / 2;
-
-      if (y >=3D x)
-        {
-          uintmax_t hi, lo;
-          umul_ppmm (hi, lo, x + 1, x + 1);
-          assert (gt2 (hi, lo, nh, nl));
-
-          umul_ppmm (hi, lo, x, x);
-          assert (ge2 (nh, nl, hi, lo));
-          sub_ddmmss (hi, lo, nh, nl, hi, lo);
-          assert (hi =3D=3D 0);
-
-          return x;
-        }
-
-      x =3D y;
-    }
-}
-
-/* MAGIC[N] has a bit i set iff i is a quadratic residue mod N. */
-#define MAGIC64 ((uint64_t) 0x0202021202030213ULL)
-#define MAGIC63 ((uint64_t) 0x0402483012450293ULL)
-#define MAGIC65 ((uint64_t) 0x218a019866014613ULL)
-#define MAGIC11 0x23b
-
-/* Returns the square root if the input is a square, otherwise 0. */
-static uintmax_t _GL_ATTRIBUTE_CONST
-is_square (uintmax_t x)
-{
-  /* Uses the tests suggested by Cohen. Excludes 99% of the non-squares be=
fore
-     computing the square root. */
-  if (((MAGIC64 >> (x & 63)) & 1)
-      && ((MAGIC63 >> (x % 63)) & 1)
-      /* Both 0 and 64 are squares mod (65) */
-      && ((MAGIC65 >> ((x % 65) & 63)) & 1)
-      && ((MAGIC11 >> (x % 11) & 1)))
-    {
-      uintmax_t r =3D isqrt (x);
-      if (r*r =3D=3D x)
-        return r;
-    }
-  return 0;
-}
-
-/* invtab[i] =3D floor(0x10000 / (0x100 + i) */
-static const unsigned short invtab[0x81] =3D
-  {
-    0x200,
-    0x1fc, 0x1f8, 0x1f4, 0x1f0, 0x1ec, 0x1e9, 0x1e5, 0x1e1,
-    0x1de, 0x1da, 0x1d7, 0x1d4, 0x1d0, 0x1cd, 0x1ca, 0x1c7,
-    0x1c3, 0x1c0, 0x1bd, 0x1ba, 0x1b7, 0x1b4, 0x1b2, 0x1af,
-    0x1ac, 0x1a9, 0x1a6, 0x1a4, 0x1a1, 0x19e, 0x19c, 0x199,
-    0x197, 0x194, 0x192, 0x18f, 0x18d, 0x18a, 0x188, 0x186,
-    0x183, 0x181, 0x17f, 0x17d, 0x17a, 0x178, 0x176, 0x174,
-    0x172, 0x170, 0x16e, 0x16c, 0x16a, 0x168, 0x166, 0x164,
-    0x162, 0x160, 0x15e, 0x15c, 0x15a, 0x158, 0x157, 0x155,
-    0x153, 0x151, 0x150, 0x14e, 0x14c, 0x14a, 0x149, 0x147,
-    0x146, 0x144, 0x142, 0x141, 0x13f, 0x13e, 0x13c, 0x13b,
-    0x139, 0x138, 0x136, 0x135, 0x133, 0x132, 0x130, 0x12f,
-    0x12e, 0x12c, 0x12b, 0x129, 0x128, 0x127, 0x125, 0x124,
-    0x123, 0x121, 0x120, 0x11f, 0x11e, 0x11c, 0x11b, 0x11a,
-    0x119, 0x118, 0x116, 0x115, 0x114, 0x113, 0x112, 0x111,
-    0x10f, 0x10e, 0x10d, 0x10c, 0x10b, 0x10a, 0x109, 0x108,
-    0x107, 0x106, 0x105, 0x104, 0x103, 0x102, 0x101, 0x100,
-  };
-
-/* Compute q =3D [u/d], r =3D u mod d.  Avoids slow hardware division for =
the case
-   that q < 0x40; here it instead uses a table of (Euclidian) inverses.  */
-#define div_smallq(q, r, u, d)                                          \
-  do {                                                                  \
-    if ((u) / 0x40 < (d))                                               \
-      {                                                                 \
-        int _cnt;                                                       \
-        uintmax_t _dinv, _mask, _q, _r;                                 \
-        count_leading_zeros (_cnt, (d));                                \
-        _r =3D (u);                                                       \
-        if (UNLIKELY (_cnt > (W_TYPE_SIZE - 8)))                        \
-          {                                                             \
-            _dinv =3D invtab[((d) << (_cnt + 8 - W_TYPE_SIZE)) - 0x80];   \
-            _q =3D _dinv * _r >> (8 + W_TYPE_SIZE - _cnt);                \
-          }                                                             \
-        else                                                            \
-          {                                                             \
-            _dinv =3D invtab[((d) >> (W_TYPE_SIZE - 8 - _cnt)) - 0x7f];   \
-            _q =3D _dinv * (_r >> (W_TYPE_SIZE - 3 - _cnt)) >> 11;        \
-          }                                                             \
-        _r -=3D _q*(d);                                                   \
-                                                                        \
-        _mask =3D -(uintmax_t) (_r >=3D (d));                             =
  \
-        (r) =3D _r - (_mask & (d));                                       \
-        (q) =3D _q - _mask;                                               \
-        assert ( (q) * (d) + (r) =3D=3D u);                               =
  \
-      }                                                                 \
-    else                                                                \
-      {                                                                 \
-        uintmax_t _q =3D (u) / (d);                                       \
-        (r) =3D (u) - _q * (d);                                           \
-        (q) =3D _q;                                                       \
-      }                                                                 \
-  } while (0)
-
-/* Notes: Example N =3D 22117019. After first phase we find Q1 =3D 6314, Q
-   =3D 3025, P =3D 1737, representing F_{18} =3D (-6314, 2* 1737, 3025),
-   with 3025 =3D 55^2.
-
-   Constructing the square root, we get Q1 =3D 55, Q =3D 8653, P =3D 4652,
-   representing G_0 =3D (-55, 2*4652, 8653).
-
-   In the notation of the paper:
-
-   S_{-1} =3D 55, S_0 =3D 8653, R_0 =3D 4652
-
-   Put
-
-     t_0 =3D floor([q_0 + R_0] / S0) =3D 1
-     R_1 =3D t_0 * S_0 - R_0 =3D 4001
-     S_1 =3D S_{-1} +t_0 (R_0 - R_1) =3D 706
-*/
-
-/* Multipliers, in order of efficiency:
-   0.7268  3*5*7*11 =3D 1155 =3D 3 (mod 4)
-   0.7317  3*5*7    =3D  105 =3D 1
-   0.7820  3*5*11   =3D  165 =3D 1
-   0.7872  3*5      =3D   15 =3D 3
-   0.8101  3*7*11   =3D  231 =3D 3
-   0.8155  3*7      =3D   21 =3D 1
-   0.8284  5*7*11   =3D  385 =3D 1
-   0.8339  5*7      =3D   35 =3D 3
-   0.8716  3*11     =3D   33 =3D 1
-   0.8774  3        =3D    3 =3D 3
-   0.8913  5*11     =3D   55 =3D 3
-   0.8972  5        =3D    5 =3D 1
-   0.9233  7*11     =3D   77 =3D 1
-   0.9295  7        =3D    7 =3D 3
-   0.9934  11       =3D   11 =3D 3
-*/
-#define QUEUE_SIZE 50
-
-#if STAT_SQUFOF
-# define Q_FREQ_SIZE 50
-/* Element 0 keeps the total */
-static unsigned int q_freq[Q_FREQ_SIZE + 1];
-# define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
-/* Return true on success.  Expected to fail only for numbers
-   >=3D 2^{2*W_TYPE_SIZE - 2}, or close to that limit. */
-static bool
-factor_using_squfof (uintmax_t n1, uintmax_t n0, struct factors *factors)
-{
-  /* Uses algorithm and notation from
-
-     SQUARE FORM FACTORIZATION
-     JASON E. GOWER AND SAMUEL S. WAGSTAFF, JR.
-
-     http://homes.cerias.purdue.edu/~ssw/squfof.pdf
-   */
-
-  static const unsigned int multipliers_1[] =3D
-    { /* =3D 1 (mod 4) */
-      105, 165, 21, 385, 33, 5, 77, 1, 0
-    };
-  static const unsigned int multipliers_3[] =3D
-    { /* =3D 3 (mod 4) */
-      1155, 15, 231, 35, 3, 55, 7, 11, 0
-    };
-
-  const unsigned int *m;
-
-  struct { uintmax_t Q; uintmax_t P; } queue[QUEUE_SIZE];
-
-  if (n1 >=3D ((uintmax_t) 1 << (W_TYPE_SIZE - 2)))
-    return false;
-
-  uintmax_t sqrt_n =3D isqrt2 (n1, n0);
-
-  if (n0 =3D=3D sqrt_n * sqrt_n)
-    {
-      uintmax_t p1, p0;
-
-      umul_ppmm (p1, p0, sqrt_n, sqrt_n);
-      assert (p0 =3D=3D n0);
-
-      if (n1 =3D=3D p1)
-        {
-          if (prime_p (sqrt_n))
-            factor_insert_multiplicity (factors, sqrt_n, 2);
-          else
-            {
-              struct factors f;
-
-              f.nfactors =3D 0;
-              if (!factor_using_squfof (0, sqrt_n, &f))
-                {
-                  /* Try pollard rho instead */
-                  factor_using_pollard_rho (sqrt_n, 1, &f);
-                }
-              /* Duplicate the new factors */
-              for (unsigned int i =3D 0; i < f.nfactors; i++)
-                factor_insert_multiplicity (factors, f.p[i], 2*f.e[i]);
-            }
-          return true;
-        }
-    }
-
-  /* Select multipliers so we always get n * mu =3D 3 (mod 4) */
-  for (m =3D (n0 % 4 =3D=3D 1) ? multipliers_3 : multipliers_1;
-       *m; m++)
-    {
-      uintmax_t S, Dh, Dl, Q1, Q, P, L, L1, B;
-      unsigned int i;
-      unsigned int mu =3D *m;
-      unsigned int qpos =3D 0;
-
-      assert (mu * n0 % 4 =3D=3D 3);
-
-      /* In the notation of the paper, with mu * n =3D=3D 3 (mod 4), we
-         get \Delta =3D 4 mu * n, and the paper's \mu is 2 mu. As far as
-         I understand it, the necessary bound is 4 \mu^3 < n, or 32
-         mu^3 < n.
-
-         However, this seems insufficient: With n =3D 37243139 and mu =3D
-         105, we get a trivial factor, from the square 38809 =3D 197^2,
-         without any corresponding Q earlier in the iteration.
-
-         Requiring 64 mu^3 < n seems sufficient. */
-      if (n1 =3D=3D 0)
-        {
-          if ((uintmax_t) mu*mu*mu >=3D n0 / 64)
-            continue;
-        }
-      else
-        {
-          if (n1 > ((uintmax_t) 1 << (W_TYPE_SIZE - 2)) / mu)
-            continue;
-        }
-      umul_ppmm (Dh, Dl, n0, mu);
-      Dh +=3D n1 * mu;
-
-      assert (Dl % 4 !=3D 1);
-      assert (Dh < (uintmax_t) 1 << (W_TYPE_SIZE - 2));
-
-      S =3D isqrt2 (Dh, Dl);
-
-      Q1 =3D 1;
-      P =3D S;
-
-      /* Square root remainder fits in one word, so ignore high part. */
-      Q =3D Dl - P*P;
-      /* FIXME: When can this differ from floor(sqrt(2 sqrt(D)))? */
-      L =3D isqrt (2*S);
-      B =3D 2*L;
-      L1 =3D mu * 2 * L;
-
-      /* The form is (+/- Q1, 2P, -/+ Q), of discriminant 4 (P^2 + Q Q1) =
=3D
-         4 D. */
-
-      for (i =3D 0; i <=3D B; i++)
-        {
-          uintmax_t q, P1, t, rem;
-
-          div_smallq (q, rem, S+P, Q);
-          P1 =3D S - rem; /* P1 =3D q*Q - P */
-
-#if STAT_SQUFOF
-          assert (q > 0);
-          q_freq[0]++;
-          q_freq[MIN(q, Q_FREQ_SIZE)]++;
-#endif
-
-          if (Q <=3D L1)
-            {
-              uintmax_t g =3D Q;
-
-              if ( (Q & 1) =3D=3D 0)
-                g /=3D 2;
-
-              g /=3D gcd_odd (g, mu);
-
-              if (g <=3D L)
-                {
-                  if (qpos >=3D QUEUE_SIZE)
-                    {
-                      fprintf (stderr, "squfof queue overflow.\n");
-                      exit (EXIT_FAILURE);
-                    }
-                  queue[qpos].Q =3D g;
-                  queue[qpos].P =3D P % g;
-                  qpos++;
-                }
-            }
-
-          /* I think the difference can be either sign, but mod
-             2^W_TYPE_SIZE arithmetic should be fine. */
-          t =3D Q1 + q * (P - P1);
-          Q1 =3D Q;
-          Q =3D t;
-          P =3D P1;
-
-          if ( (i & 1) =3D=3D 0)
-            {
-              uintmax_t r =3D is_square (Q);
-              if (r)
-                {
-                  unsigned int j;
-
-                  for (j =3D 0; j < qpos; j++)
-                    {
-                      if (queue[j].Q =3D=3D r)
-                        {
-                          if (r =3D=3D 1)
-                            /* Traversed entire cycle. */
-                            goto next_multiplier;
-
-                          /* Need the absolute value for divisibility test=
. */
-                          if (P >=3D queue[j].P)
-                            t =3D P - queue[j].P;
-                          else
-                            t =3D queue[j].P - P;
-                          if (t % r =3D=3D 0)
-                            {
-                              /* Delete entries up to and including entry
-                                 j, which matched. */
-                              memmove (queue, queue + j + 1,
-                                       (qpos - j - 1) * sizeof (queue[0]));
-                              qpos -=3D (j + 1);
-                            }
-                          goto next_i;
-                        }
-                    }
-
-                  /* We have found a square form, which should give a
-                     factor. */
-                  Q1 =3D r;
-                  assert (S >=3D P); /* What signs are possible? */
-                  P +=3D r * ((S - P) / r);
-
-                  /* Note: Paper says (N - P*P) / Q1, that seems incorrect
-                     for the case D =3D 2N. */
-                  /* Compute Q =3D (D - P*P) / Q1, but we need double
-                     precision. */
-                  uintmax_t hi, lo;
-                  umul_ppmm (hi, lo, P, P);
-                  sub_ddmmss (hi, lo, Dh, Dl, hi, lo);
-                  udiv_qrnnd (Q, rem, hi, lo, Q1);
-                  assert (rem =3D=3D 0);
-
-                  for (;;)
-                    {
-                      /* Note: There appears to by a typo in the paper,
-                         Step 4a in the algorithm description says q <--
-                         floor([S+P]/\hat Q), but looking at the equations
-                         in Sec. 3.1, it should be q <-- floor([S+P] / Q).
-                         (In this code, \hat Q is Q1). */
-                      div_smallq (q, rem, S+P, Q);
-                      P1 =3D S - rem;     /* P1 =3D q*Q - P */
-
-#if STAT_SQUFOF
-                      q_freq[0]++;
-                      q_freq[MIN (q, Q_FREQ_SIZE)]++;
-#endif
-                      if (P =3D=3D P1)
-                        break;
-                      t =3D Q1 + q * (P - P1);
-                      Q1 =3D Q;
-                      Q =3D t;
-                      P =3D P1;
-                    }
-
-                  if ( (Q & 1) =3D=3D 0)
-                    Q /=3D 2;
-                  Q /=3D gcd_odd (Q, mu);
-
-                  assert (Q > 1 && (n1 || Q < n0));
-
-                  if (prime_p (Q))
-                    factor_insert (factors, Q);
-                  else if (!factor_using_squfof (0, Q, factors))
-                    factor_using_pollard_rho (Q, 2, factors);
-
-                  divexact_21 (n1, n0, n1, n0, Q);
-
-                  if (prime2_p (n1, n0))
-                    factor_insert_large (factors, n1, n0);
-                  else
-                    {
-                      if (!factor_using_squfof (n1, n0, factors))
-                        {
-                          if (n1 =3D=3D 0)
-                            factor_using_pollard_rho (n0, 1, factors);
-                          else
-                            factor_using_pollard_rho2 (n1, n0, 1, factors);
-                        }
-                    }
-
-                  return true;
-                }
-            }
-        next_i:
-          ;
-        }
-    next_multiplier:
-      ;
-    }
-  return false;
-}
-
-static void
-factor (uintmax_t t1, uintmax_t t0, struct factors *factors)
-{
-  factors->nfactors =3D 0;
-  factors->plarge[1] =3D 0;
-
-  if (t1 =3D=3D 0 && t0 < 2)
-    return;
-
-  t0 =3D factor_using_division (&t1, t1, t0, factors);
-
-  if (t1 =3D=3D 0 && t0 < 2)
-    return;
-
-  if (prime2_p (t1, t0))
-    factor_insert_large (factors, t1, t0);
-  else
-    {
-      if (alg =3D=3D ALG_SQUFOF)
-        if (factor_using_squfof (t1, t0, factors))
-          return;
-
-      if (t1 =3D=3D 0)
-        factor_using_pollard_rho (t0, 1, factors);
-      else
-        factor_using_pollard_rho2 (t1, t0, 1, factors);
-    }
-}
-
-#if HAVE_GMP
-static void
-mp_factor (mpz_t t, struct mp_factors *factors)
-{
-  mp_factor_init (factors);
-
-  if (mpz_sgn (t) !=3D 0)
-    {
-      mp_factor_using_division (t, factors);
-
-      if (mpz_cmp_ui (t, 1) !=3D 0)
-        {
-          if (flag_verbose > 0)
-            {
-              printf ("[is number prime?] ");
-            }
-          if (mp_prime_p (t))
-            mp_factor_insert (factors, t);
-          else
-            mp_factor_using_pollard_rho (t, 1, factors);
-        }
-    }
-}
-#endif
-
-static int
-strto2uintmax (uintmax_t *hip, uintmax_t *lop, const char *s)
-{
-  int errcode;
-  unsigned int lo_carry;
-  uintmax_t hi, lo;
-
-  errcode =3D -1;
-
-  hi =3D lo =3D 0;
-  for (;;)
-    {
-      unsigned int c =3D *s++;
-      if (c =3D=3D 0)
-        break;
-
-      if (UNLIKELY (c < '0' || c > '9'))
-        {
-          errcode =3D -1;
-          break;
-        }
-      c -=3D '0';
-
-      errcode =3D 0;              /* we've seen at least one valid digit */
-
-      if (UNLIKELY (hi > ~(uintmax_t)0 / 10))
-        {
-          errcode =3D -1; /* overflow */
-          break;
-        }
-      hi =3D 10 * hi;
-
-      lo_carry =3D (lo >> (W_TYPE_SIZE - 3)) + (lo >> (W_TYPE_SIZE - 1));
-      lo_carry +=3D 10 * lo < 2 * lo;
-
-      lo =3D 10 * lo;
-      lo +=3D c;
-
-      lo_carry +=3D lo < c;
-      hi +=3D lo_carry;
-      if (UNLIKELY (hi < lo_carry))
-        {
-          errcode =3D -1; /* overflow */
-          break;
-        }
-    }
-
-  *hip =3D hi;
-  *lop =3D lo;
-
-  return errcode;
-}
-
-static void
-print_uintmaxes (uintmax_t t1, uintmax_t t0)
-{
-  uintmax_t q, r;
-
-  if (t1 =3D=3D 0)
-    printf ("%ju", t0);
-  else
-    {
-      /* Use very plain code here since it seems hard to write fast code
-         without assuming a specific word size.  */
-      q =3D t1 / 1000000000;
-      r =3D t1 % 1000000000;
-      udiv_qrnnd (t0, r, r, t0, 1000000000);
-      print_uintmaxes (q, t0);
-      printf ("%09u", (int) r);
-    }
-}
-
-static void
-factor_one (const char *input)
-{
-  uintmax_t t1, t0;
-  int errcode;
-
-  /* Try converting the number to one or two words.  If it fails, use GMP =
or
-     print an error message.  The 2nd condition checks that the most
-     significant bit of the two-word number is clear, in a typesize neutral
-     way.  */
-  errcode =3D strto2uintmax (&t1, &t0, input);
-  if (errcode =3D=3D 0 && ((t1 << 1) >> 1) =3D=3D t1)
-    {
-      struct factors factors;
-
-      print_uintmaxes (t1, t0);
-      printf (":");
-
-      factor (t1, t0, &factors);
-
-      for (unsigned int j =3D 0; j < factors.nfactors; j++)
-        for (unsigned int k =3D 0; k < factors.e[j]; k++)
-          printf (" %ju", factors.p[j]);
-
-      if (factors.plarge[1])
-        {
-          printf (" ");
-          print_uintmaxes (factors.plarge[1], factors.plarge[0]);
-        }
-      puts ("");
-    }
-  else
-    {
-#if HAVE_GMP
-      mpz_t t;
-      struct mp_factors factors;
-
-      mpz_init_set_str (t, input, 10);
-
-      gmp_printf ("%Zd:", t);
-      mp_factor (t, &factors);
-
-      for (unsigned int j =3D 0; j < factors.nfactors; j++)
-        for (unsigned int k =3D 0; k < factors.e[j]; k++)
-          gmp_printf (" %Zd", factors.p[j]);
-
-      mp_factor_clear (&factors);
-      mpz_clear (t);
-      puts ("");
-#else
-      fprintf (stderr, "error: number %s not parsable or too large\n", inp=
ut);
-      exit (EXIT_FAILURE);
-#endif
-    }
-}
-
-struct inbuf
-{
-  char *buf;
-  size_t alloc;
-};
-
-/* Read white-space delimited items. Return 1 on success, 0 on EOF.
-   Exit on I/O errors. */
-int
-read_item (struct inbuf *bufstruct)
-{
-  int c;
-  size_t i;
-  char *buf =3D bufstruct->buf;
-
-  do
-    c =3D getchar_unlocked ();
-  while (isspace (c));
-
-  for (i =3D 0; !isspace(c); i++)
-    {
-      if (c < 0)
-        {
-          if (ferror (stdin))
-            {
-              fprintf (stderr, "read error on stdin: %s\n", strerror(errno=
));
-              exit (EXIT_FAILURE);
-            }
-          if (i =3D=3D 0)
-            return 0;
-          else
-            break;
-        }
-
-      if (UNLIKELY (bufstruct->alloc <=3D i + 1)) /* +1 byte for terminati=
ng NUL */
-        {
-          bufstruct->alloc =3D bufstruct->alloc * 5 / 4 + 1;
-          bufstruct->buf =3D realloc (bufstruct->buf, bufstruct->alloc);
-          buf =3D bufstruct->buf;
-        }
-
-      buf[i] =3D c;
-      c =3D getchar_unlocked ();
-    }
-
-  buf[i] =3D '\0';
-  return 1;
-}
-
-int
-main (int argc, char *argv[])
-{
-  int c;
-
-  alg =3D ALG_POLLARD_RHO;        /* Default to Pollard rho */
-
-  while ( (c =3D getopt(argc, argv, "svw")) !=3D -1)
-    switch (c)
-      {
-      case 's':
-        alg =3D ALG_SQUFOF;
-        break;
-      case 'v':
-        flag_verbose =3D 1;
-        break;
-      case 'w':
-        flag_prove_primality =3D 0;
-        break;
-      case '?':
-        printf ("Usage: %s [-s] number ...\n", argv[0]);
-        return EXIT_FAILURE;
-      }
-#if STAT_SQUFOF
-  if (alg =3D=3D ALG_SQUFOF)
-    memset (q_freq, 0, sizeof (q_freq));
-#endif
-
-  if (optind < argc)
-    for (int i =3D optind; i < argc; i++)
-      factor_one (argv[i]);
-  else
-    {
-      struct inbuf bufstruct;
-      bufstruct.alloc =3D 50;     /* enough unless HAVE_GMP */
-      bufstruct.buf =3D malloc (bufstruct.alloc);
-      while (read_item (&bufstruct))
-        factor_one (bufstruct.buf);
-    }
-
-#if STAT_SQUFOF
-  if (alg =3D=3D ALG_SQUFOF && q_freq[0] > 0)
-    {
-      double acc_f;
-      printf ("q  freq.  cum. freq.(total: %d)\n", q_freq[0]);
-      for (unsigned int i =3D 1, acc_f =3D 0.0; i <=3D Q_FREQ_SIZE; i++)
-        {
-          double f =3D (double) q_freq[i] / q_freq[0];
-          acc_f +=3D f;
-          printf ("%s%d %.2f%% %.2f%%\n", i =3D=3D Q_FREQ_SIZE ? ">=3D" : =
"", i,
-                  100.0 * f, 100.0 * acc_f);
-        }
-    }
-#endif
-
-  exit (EXIT_SUCCESS);
-}
diff --git a/src/factor.c b/src/factor.c
index e63e0e0..84d9721 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -14,17 +14,79 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  =
*/

-/* Written by Paul Rubin <phr@ocf.berkeley.edu>.
+/* Originally written by Paul Rubin <phr@ocf.berkeley.edu>.
    Adapted for GNU, fixed to factor UINT_MAX by Jim Meyering.
    Arbitrary-precision code adapted by James Youngman from Torbj=F6rn
    Granlund's factorize.c, from GNU MP version 4.2.2.
+   In 2012, the core was rewritten by Torbj=F6rn Granlund and Niels M=F6ll=
er.
+   Contains code from GNU MP.  */
+
+/* Efficiently factor numbers that fit in one or two words (word =3D uintm=
ax_t),
+   or, with GMP, numbers of any size.
+
+  Code organisation:
+
+    There are several variants of many functions, for handling one word, t=
wo
+    words, and GMP's mpz_t type.  If the one-word variant is called foo, t=
he
+    two-word variant will be foo2, and the one for mpz_t will be mp_foo.  =
In
+    some cases, the plain function variants will handle both one-word and
+    two-word numbers, evidenced by function arguments.
+
+    The factoring code for two words will fall into the code for one word =
when
+    progress allows that.
+
+    Using GMP is optional.  Define HAVE_GMP to make this code include GMP
+    factoring code.  The GMP factoring code is based on GMP's demos/factor=
ize.c
+    (last synched 2012-09-07).  The GMP-based factoring code will stay in =
GMP
+    factoring code even if numbers get small enough for using the two-word
+    code.
+
+  Algorithm:
+
+    (1) Perform trial division using a small primes table, but without har=
dware
+        division since the primes table store inverses modulo the word bas=
e.
+        (The GMP variant of this code doesn't make use of the precomputed
+        inverses, but instead relies on GMP for fast divisibility testing.)
+    (2) Check the nature of any non-factored part using Miller-Rabin for
+        detecting composites, and Lucas for detecting primes.
+    (3) Factor any remaining composite part using the Pollard-Brent rho
+        algorithm or the SQUFOF algorithm, checking status of found factors
+        again using Miller-Rabin and Lucas.
+
+    We prefer using Hensel norm in the divisions, not the more familiar
+    Euclidian norm, since the former leads to much faster code.  In the
+    Pollard-Brent rho code and the prime testing code, we use Montgomery's
+    trick of multiplying all n-residues by the word base, allowing cheap H=
ensel
+    reductions mod n.
+
+  Improvements:
+
+    * Use modular inverses also for exact division in the Lucas code, and
+      elsewhere.  A problem is to locate the inverses not from an index, b=
ut
+      from a prime.  We might instead compute the inverse on-the-fly.
+
+    * Tune trial division table size (not forgetting that this is a standa=
lone
+      program where the table will be read from disk for each invocation).
+
+    * Implement less naive powm, using k-ary exponentiation for k =3D 3 or
+      perhaps k =3D 4.
+
+    * Try to speed trial division code for single uintmax_t numbers, i.e.,=
 the
+      code using DIVBLOCK.  It currently runs at 2 cycles per prime (Intel=
 SBR,
+      IBR), 3 cycles per prime (AMD Stars) and 5 cycles per prime (AMD BD)=
 when
+      using gcc 4.6 and 4.7.  Some software pipelining should help; 1, 2, =
and 4
+      respectively cycles ought to be possible.
+
+    * The redcify function could be vastly improved by using (plain Euclid=
ian)
+      pre-inversion (such as GMP's invert_limb) and udiv_qrnnd_preinv (from
+      GMP's gmp-impl.h).  The redcify2 function could be vastly improved u=
sing
+      similar methoods.  These functions currently dominate run time when =
using
+      the -w option.
 */

 #include <config.h>
 #include <getopt.h>
-#include <stdarg.h>
 #include <stdio.h>
-#include <sys/types.h>
 #if HAVE_GMP
 # include <gmp.h>
 #endif
@@ -40,17 +102,540 @@
 /* The official name of this program (e.g., no 'g' prefix).  */
 #define PROGRAM_NAME "factor"

-#define AUTHORS proper_name ("Paul Rubin")
+#define AUTHORS \
+  proper_name ("Paul Rubin"),                                           \
+  proper_name_utf8 ("Torbjorn Granlund", "Torbj\303\266rn Granlund"),   \
+  proper_name_utf8 ("Niels Moller", "Niels M\303\266ller")

 /* Token delimiters when reading from a file.  */
 #define DELIM "\n\t "

-static bool verbose =3D false;
+#ifndef STAT_SQUFOF
+# define STAT_SQUFOF 0
+#endif
+
+#ifndef USE_LONGLONG_H
+# define USE_LONGLONG_H 1
+#endif
+
+#if USE_LONGLONG_H
+
+/* Make definitions for longlong.h to make it do what it can do for us */
+# define W_TYPE_SIZE 64          /* bitcount for uintmax_t */
+# define UWtype  uintmax_t
+# define UHWtype unsigned long int
+# undef UDWtype
+# if HAVE_ATTRIBUTE_MODE
+typedef unsigned int UQItype    __attribute__ ((mode (QI)));
+typedef          int SItype     __attribute__ ((mode (SI)));
+typedef unsigned int USItype    __attribute__ ((mode (SI)));
+typedef          int DItype     __attribute__ ((mode (DI)));
+typedef unsigned int UDItype    __attribute__ ((mode (DI)));
+# else
+typedef unsigned char UQItype;
+typedef          long SItype;
+typedef unsigned long int USItype;
+#  if HAVE_LONG_LONG
+typedef long long int DItype;
+typedef unsigned long long int UDItype;
+#  else /* Assume `long' gives us a wide enough type.  Needed for hppa2.0w=
.  */
+typedef long int DItype;
+typedef unsigned long int UDItype;
+#  endif
+# endif
+# define LONGLONG_STANDALONE     /* Don't require GMP's longlong.h mdep fi=
les */
+# define ASSERT(x)               /* FIXME make longlong.h really standalon=
e */
+# define __clz_tab factor_clz_tab /* Rename to avoid glibc collision */
+# ifndef __GMP_GNUC_PREREQ
+#  define __GMP_GNUC_PREREQ(a,b) 1
+# endif
+# if _ARCH_PPC
+#  define HAVE_HOST_CPU_FAMILY_powerpc 1
+# endif
+# include "longlong.h"
+# ifdef COUNT_LEADING_ZEROS_NEED_CLZ_TAB
+const unsigned char factor_clz_tab[129] =3D
+{
+  1,2,3,3,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+  9
+};
+# endif
+
+#else /* not USE_LONGLONG_H */
+
+# define W_TYPE_SIZE (8 * sizeof (uintmax_t))
+# define __ll_B ((uintmax_t) 1 << (W_TYPE_SIZE / 2))
+# define __ll_lowpart(t)  ((uintmax_t) (t) & (__ll_B - 1))
+# define __ll_highpart(t) ((uintmax_t) (t) >> (W_TYPE_SIZE / 2))
+
+#endif
+
+enum alg_type { ALG_POLLARD_RHO =3D 1, ALG_SQUFOF =3D 2 };
+
+static enum alg_type alg;
+
+/* 2*3*5*7*11...*101 is 128 bits, and has 26 prime factors */
+#define MAX_NFACTS 26
+
+enum
+{
+  VERBOSE_OPTION =3D CHAR_MAX + 1
+};
+
+static struct option const long_options[] =3D
+{
+  {"verbose", no_argument, NULL, VERBOSE_OPTION},
+  {GETOPT_HELP_OPTION_DECL},
+  {GETOPT_VERSION_OPTION_DECL},
+  {NULL, 0, NULL, 0}
+};
+
+struct factors
+{
+  uintmax_t     plarge[2]; /* Can have a single large factor */
+  uintmax_t     p[MAX_NFACTS];
+  unsigned char e[MAX_NFACTS];
+  unsigned char nfactors;
+};

 #if HAVE_GMP
-static mpz_t *factor =3D NULL;
-static size_t nfactors_found =3D 0;
-static size_t nfactors_allocated =3D 0;
+struct mp_factors
+{
+  mpz_t             *p;
+  unsigned long int *e;
+  unsigned long int nfactors;
+};
+#endif
+
+static void factor (uintmax_t, uintmax_t, struct factors *);
+
+#ifndef umul_ppmm
+# define umul_ppmm(w1, w0, u, v)                                        \
+  do {                                                                  \
+    uintmax_t __x0, __x1, __x2, __x3;                                   \
+    unsigned long int __ul, __vl, __uh, __vh;                           \
+    uintmax_t __u =3D (u), __v =3D (v);                                   =
  \
+                                                                        \
+    __ul =3D __ll_lowpart (__u);                                          \
+    __uh =3D __ll_highpart (__u);                                         \
+    __vl =3D __ll_lowpart (__v);                                          \
+    __vh =3D __ll_highpart (__v);                                         \
+                                                                        \
+    __x0 =3D (uintmax_t) __ul * __vl;                                     \
+    __x1 =3D (uintmax_t) __ul * __vh;                                     \
+    __x2 =3D (uintmax_t) __uh * __vl;                                     \
+    __x3 =3D (uintmax_t) __uh * __vh;                                     \
+                                                                        \
+    __x1 +=3D __ll_highpart (__x0);/* this can't give carry */            \
+    __x1 +=3D __x2;               /* but this indeed can */               \
+    if (__x1 < __x2)            /* did we get it? */                    \
+      __x3 +=3D __ll_B;           /* yes, add it in the proper pos. */    \
+                                                                        \
+    (w1) =3D __x3 + __ll_highpart (__x1);                                 \
+    (w0) =3D (__x1 << W_TYPE_SIZE / 2) + __ll_lowpart (__x0);             \
+  } while (0)
+#endif
+
+#if !defined udiv_qrnnd || defined UDIV_NEEDS_NORMALIZATION
+/* Define our own, not needing normalization. This function is
+   currently not performance critical, so keep it simple. Similar to
+   the mod macro below. */
+# undef udiv_qrnnd
+# define udiv_qrnnd(q, r, n1, n0, d)                                    \
+  do {                                                                  \
+    uintmax_t __d1, __d0, __q, __r1, __r0;                              \
+                                                                        \
+    assert ((n1) < (d));                                                \
+    __d1 =3D (d); __d0 =3D 0;                                             =
  \
+    __r1 =3D (n1); __r0 =3D (n0);                                         =
  \
+    __q =3D 0;                                                            \
+    for (unsigned int __i =3D W_TYPE_SIZE; __i > 0; __i--)                \
+      {                                                                 \
+        rsh2 (__d1, __d0, __d1, __d0, 1);                               \
+        __q <<=3D 1;                                                      \
+        if (ge2 (__r1, __r0, __d1, __d0))                               \
+          {                                                             \
+            __q++;                                                      \
+            sub_ddmmss (__r1, __r0, __r1, __r0, __d1, __d0);            \
+          }                                                             \
+      }                                                                 \
+    (r) =3D __r0;                                                         \
+    (q) =3D __q;                                                          \
+  } while (0)
+#endif
+
+#if !defined add_ssaaaa
+# define add_ssaaaa(sh, sl, ah, al, bh, bl)                             \
+  do {                                                                  \
+    uintmax_t _add_x;                                                   \
+    _add_x =3D (al) + (bl);                                               \
+    (sh) =3D (ah) + (bh) + (_add_x < (al));                               \
+    (sl) =3D _add_x;                                                      \
+  } while (0)
+#endif
+
+#define rsh2(rh, rl, ah, al, cnt)                                       \
+  do {                                                                  \
+    (rl) =3D ((ah) << (W_TYPE_SIZE - (cnt))) | ((al) >> (cnt));           \
+    (rh) =3D (ah) >> (cnt);                                               \
+  } while (0)
+
+#define lsh2(rh, rl, ah, al, cnt)                                       \
+  do {                                                                  \
+    (rh) =3D ((ah) << cnt) | ((al) >> (W_TYPE_SIZE - (cnt)));             \
+    (rl) =3D (al) << (cnt);                                               \
+  } while (0)
+
+#define ge2(ah, al, bh, bl)                                             \
+  ((ah) > (bh) || ((ah) =3D=3D (bh) && (al) >=3D (bl)))
+
+#define gt2(ah, al, bh, bl)                                             \
+  ((ah) > (bh) || ((ah) =3D=3D (bh) && (al) > (bl)))
+
+#ifndef sub_ddmmss
+# define sub_ddmmss(rh, rl, ah, al, bh, bl)                             \
+  do {                                                                  \
+    uintmax_t _cy;                                                      \
+    _cy =3D (al) < (bl);                                                  \
+    (rl) =3D (al) - (bl);                                                 \
+    (rh) =3D (ah) - (bh) - _cy;                                           \
+  } while (0)
+#endif
+
+#ifndef count_leading_zeros
+# define count_leading_zeros(count, x) do {                             \
+    uintmax_t __clz_x =3D (x);                                            \
+    unsigned int __clz_c;                                               \
+    for (__clz_c =3D 0;                                                   \
+         (__clz_x & ((uintmax_t) 0xff << (W_TYPE_SIZE - 8))) =3D=3D 0;    =
  \
+         __clz_c +=3D 8)                                                  \
+      __clz_x <<=3D 8;                                                    \
+    for (; (intmax_t)__clz_x >=3D 0; __clz_c++)                           \
+      __clz_x <<=3D 1;                                                    \
+    (count) =3D __clz_c;                                                  \
+  } while (0)
+#endif
+
+#ifndef count_trailing_zeros
+# define count_trailing_zeros(count, x) do {                            \
+    uintmax_t __ctz_x =3D (x);                                            \
+    unsigned int __ctz_c =3D 0;                                           \
+    while ((__ctz_x & 1) =3D=3D 0)                                        =
  \
+      {                                                                 \
+        __ctz_x >>=3D 1;                                                  \
+        __ctz_c++;                                                      \
+      }                                                                 \
+    (count) =3D __ctz_c;                                                  \
+  } while (0)
+#endif
+
+/* Requires that a < n and b <=3D n */
+#define submod(r,a,b,n)                                                 \
+  do {                                                                  \
+    uintmax_t _t =3D - (uintmax_t) (a < b);                               \
+    (r) =3D ((n) & _t) + (a) - (b);                                       \
+  } while (0)
+
+#define addmod(r,a,b,n)                                                 \
+  submod ((r), (a), ((n) - (b)), (n))
+
+/* Modular two-word addition and subtraction.  For performance reasons, the
+   most significant bit of n1 must be clear.  The destination variables mu=
st be
+   distinct from the mod operand.  */
+#define addmod2(r1, r0, a1, a0, b1, b0, n1, n0)                         \
+  do {                                                                  \
+    add_ssaaaa ((r1), (r0), (a1), (a0), (b1), (b0));                    \
+    if (ge2 ((r1), (r0), (n1), (n0)))                                   \
+      sub_ddmmss ((r1), (r0), (r1), (r0), (n1), (n0));                  \
+  } while (0)
+#define submod2(r1, r0, a1, a0, b1, b0, n1, n0)                         \
+  do {                                                                  \
+    sub_ddmmss ((r1), (r0), (a1), (a0), (b1), (b0));                    \
+    if ((intmax_t) (r1) < 0)                                            \
+      add_ssaaaa ((r1), (r0), (r1), (r0), (n1), (n0));                  \
+  } while (0)
+
+#define HIGHBIT_TO_MASK(x)                                              \
+  (((intmax_t)-1 >> 1) < 0                                              \
+   ? (uintmax_t)((intmax_t)(x) >> (W_TYPE_SIZE - 1))                    \
+   : ((x) & ((uintmax_t) 1 << (W_TYPE_SIZE - 1))                        \
+      ? UINTMAX_MAX : (uintmax_t) 0))
+
+/* Compute r =3D a mod d, where r =3D <*t1,retval>, a =3D <a1,a0>, d =3D <=
d1,d0>.
+   Requires that d1 !=3D 0.  */
+static uintmax_t
+mod2 (uintmax_t *r1, uintmax_t a1, uintmax_t a0, uintmax_t d1, uintmax_t d=
0)
+{
+  int cntd, cnta;
+
+  assert (d1 !=3D 0);
+
+  if (a1 =3D=3D 0)
+    {
+      *r1 =3D 0;
+      return a0;
+    }
+
+  count_leading_zeros (cntd, d1);
+  count_leading_zeros (cnta, a1);
+  int cnt =3D cntd - cnta;
+  lsh2 (d1, d0, d1, d0, cnt);
+  for (int i =3D 0; i < cnt; i++)
+    {
+      if (ge2 (a1, a0, d1, d0))
+        sub_ddmmss (a1, a0, a1, a0, d1, d0);
+      rsh2 (d1, d0, d1, d0, 1);
+    }
+
+  *r1 =3D a1;
+  return a0;
+}
+
+static uintmax_t _GL_ATTRIBUTE_CONST
+gcd_odd (uintmax_t a, uintmax_t b)
+{
+  if ( (b & 1) =3D=3D 0)
+    {
+      uintmax_t t =3D b;
+      b =3D a;
+      a =3D t;
+    }
+  if (a =3D=3D 0)
+    return b;
+
+  /* Take out least significant one bit, to make room for sign */
+  b >>=3D 1;
+
+  for (;;)
+    {
+      uintmax_t t;
+      uintmax_t bgta;
+
+      while ((a & 1) =3D=3D 0)
+        a >>=3D 1;
+      a >>=3D 1;
+
+      t =3D a - b;
+      if (t =3D=3D 0)
+        return (a << 1) + 1;
+
+      bgta =3D HIGHBIT_TO_MASK (t);
+
+      /* b <-- min (a, b) */
+      b +=3D (bgta & t);
+
+      /* a <-- |a - b| */
+      a =3D (t ^ bgta) - bgta;
+    }
+}
+
+static uintmax_t
+gcd2_odd (uintmax_t *r1, uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax=
_t b0)
+{
+  while ((a0 & 1) =3D=3D 0)
+    rsh2 (a1, a0, a1, a0, 1);
+  while ((b0 & 1) =3D=3D 0)
+    rsh2 (b1, b0, b1, b0, 1);
+
+  for (;;)
+    {
+      if ((b1 | a1) =3D=3D 0)
+        {
+          *r1 =3D 0;
+          return gcd_odd (b0, a0);
+        }
+
+      if (gt2 (a1, a0, b1, b0))
+        {
+          sub_ddmmss (a1, a0, a1, a0, b1, b0);
+          do
+            rsh2 (a1, a0, a1, a0, 1);
+          while ((a0 & 1) =3D=3D 0);
+        }
+      else if (gt2 (b1, b0, a1, a0))
+        {
+          sub_ddmmss (b1, b0, b1, b0, a1, a0);
+          do
+            rsh2 (b1, b0, b1, b0, 1);
+          while ((b0 & 1) =3D=3D 0);
+        }
+      else
+        break;
+    }
+
+  *r1 =3D a1;
+  return a0;
+}
+
+static void
+factor_insert_multiplicity (struct factors *factors,
+                            uintmax_t prime, unsigned int m)
+{
+  unsigned int nfactors =3D factors->nfactors;
+  uintmax_t *p =3D factors->p;
+  unsigned char *e =3D factors->e;
+
+  /* Locate position for insert new or increment e.  */
+  int i;
+  for (i =3D nfactors - 1; i >=3D 0; i--)
+    {
+      if (p[i] <=3D prime)
+        break;
+    }
+
+  if (i < 0 || p[i] !=3D prime)
+    {
+      for (int j =3D nfactors - 1; j > i; j--)
+        {
+          p[j + 1] =3D p[j];
+          e[j + 1] =3D e[j];
+        }
+      p[i + 1] =3D prime;
+      e[i + 1] =3D m;
+      factors->nfactors =3D nfactors + 1;
+    }
+  else
+    {
+      e[i] +=3D m;
+    }
+}
+
+#define factor_insert(f, p) factor_insert_multiplicity (f, p, 1)
+
+static void
+factor_insert_large (struct factors *factors,
+                     uintmax_t p1, uintmax_t p0)
+{
+  if (p1 > 0)
+    {
+      assert (factors->plarge[1] =3D=3D 0);
+      factors->plarge[0] =3D p0;
+      factors->plarge[1] =3D p1;
+    }
+  else
+    factor_insert (factors, p0);
+}
+
+#if HAVE_GMP
+static void mp_factor (mpz_t, struct mp_factors *);
+
+static void
+mp_factor_init (struct mp_factors *factors)
+{
+  factors->p =3D xmalloc (1);
+  factors->e =3D xmalloc (1);
+  factors->nfactors =3D 0;
+}
+
+static void
+mp_factor_clear (struct mp_factors *factors)
+{
+  for (unsigned int i =3D 0; i < factors->nfactors; i++)
+    mpz_clear (factors->p[i]);
+
+  free (factors->p);
+  free (factors->e);
+}
+
+static void
+mp_factor_insert (struct mp_factors *factors, mpz_t prime)
+{
+  unsigned long int nfactors =3D factors->nfactors;
+  mpz_t         *p  =3D factors->p;
+  unsigned long int *e  =3D factors->e;
+  long i;
+
+  /* Locate position for insert new or increment e.  */
+  for (i =3D nfactors - 1; i >=3D 0; i--)
+    {
+      if (mpz_cmp (p[i], prime) <=3D 0)
+        break;
+    }
+
+  if (i < 0 || mpz_cmp (p[i], prime) !=3D 0)
+    {
+      p =3D xrealloc (p, (nfactors + 1) * sizeof p[0]);
+      e =3D xrealloc (e, (nfactors + 1) * sizeof e[0]);
+
+      mpz_init (p[nfactors]);
+      for (long j =3D nfactors - 1; j > i; j--)
+        {
+          mpz_set (p[j + 1], p[j]);
+          e[j + 1] =3D e[j];
+        }
+      mpz_set (p[i + 1], prime);
+      e[i + 1] =3D 1;
+
+      factors->p =3D p;
+      factors->e =3D e;
+      factors->nfactors =3D nfactors + 1;
+    }
+  else
+    {
+      e[i] +=3D 1;
+    }
+}
+
+static void
+mp_factor_insert_ui (struct mp_factors *factors, unsigned long int prime)
+{
+  mpz_t pz;
+
+  mpz_init_set_ui (pz, prime);
+  mp_factor_insert (factors, pz);
+  mpz_clear (pz);
+}
+#endif /* HAVE_GMP */
+
+
+#define P(a,b,c,d) a,
+static const unsigned char primes_diff[] =3D {
+#include "primes.h"
+0,0,0,0,0,0,0                           /* 7 sentinels for 8-way loop */
+};
+#undef P
+
+#define PRIMES_PTAB_ENTRIES \
+  (sizeof (primes_diff) / sizeof (primes_diff[0]) - 8 + 1)
+
+#define P(a,b,c,d) b,
+static const unsigned char primes_diff8[] =3D {
+#include "primes.h"
+0,0,0,0,0,0,0                           /* 7 sentinels for 8-way loop */
+};
+#undef P
+
+struct primes_dtab
+{
+  uintmax_t binv, lim;
+};
+
+#define P(a,b,c,d) {c,d},
+static const struct primes_dtab primes_dtab[] =3D {
+#include "primes.h"
+{1,0},{1,0},{1,0},{1,0},{1,0},{1,0},{1,0} /* 7 sentinels for 8-way loop */
+};
+#undef P
+
+/* This flag is honored only in the GMP code. */
+static int verbose =3D 0;
+
+/* Prove primality or run probabilistic tests.  */
+static bool flag_prove_primality =3D true;
+
+/* Number of Miller-Rabin tests to run when not proving primality. */
+#define MR_REPS 25
+
+#ifdef __GNUC__
+# define LIKELY(cond)    __builtin_expect ((cond), 1)
+# define UNLIKELY(cond)  __builtin_expect ((cond), 0)
+#else
+# define LIKELY(cond)    (cond)
+# define UNLIKELY(cond)  (cond)
+#endif

 static void
 debug (char const *fmt, ...)
@@ -65,368 +650,1637 @@ debug (char const *fmt, ...)
 }

 static void
-emit_factor (mpz_t n)
+factor_insert_refind (struct factors *factors, uintmax_t p, unsigned int i,
+                      unsigned int off)
 {
-  if (nfactors_found =3D=3D nfactors_allocated)
-    factor =3D X2NREALLOC (factor, &nfactors_allocated);
-  mpz_init (factor[nfactors_found]);
-  mpz_set (factor[nfactors_found], n);
-  ++nfactors_found;
+  for (unsigned int j =3D 0; j < off; j++)
+    p +=3D primes_diff[i + j];
+  factor_insert (factors, p);
 }

+/* Trial division with odd primes uses the following trick.
+
+   Let p be an odd prime, and B =3D 2^{W_TYPE_SIZE}. For simplicity,
+   consider the case t < B (this is the second loop below).
+
+   From our tables we get
+
+     binv =3D p^{-1} (mod B)
+     lim =3D floor ( (B-1) / p ).
+
+   First assume that t is a multiple of p, t =3D q * p. Then 0 <=3D q <=3D=
 lim
+   (and all quotients in this range occur for some t).
+
+   Then t =3D q * p is true also (mod B), and p is invertible we get
+
+     q =3D t * binv (mod B).
+
+   Next, assume that t is *not* divisible by p. Since multiplication
+   by binv (mod B) is a one-to-one mapping,
+
+     t * binv (mod B) > lim,
+
+   because all the smaller values are already taken.
+
+   This can be summed up by saying that the function
+
+     q(t) =3D binv * t (mod B)
+
+   is a permutation of the range 0 <=3D t < B, with the curious property
+   that it maps the multiples of p onto the range 0 <=3D q <=3D lim, in
+   order, and the non-multiples of p onto the range lim < q < B.
+ */
+
+static uintmax_t
+factor_using_division (uintmax_t *t1p, uintmax_t t1, uintmax_t t0,
+                       struct factors *factors)
+{
+  if (t0 % 2 =3D=3D 0)
+    {
+      unsigned int cnt;
+
+      if (t0 =3D=3D 0)
+        {
+          count_trailing_zeros (cnt, t1);
+          t0 =3D t1 >> cnt;
+          t1 =3D 0;
+          cnt +=3D W_TYPE_SIZE;
+        }
+      else
+        {
+          count_trailing_zeros (cnt, t0);
+          rsh2 (t1, t0, t1, t0, cnt);
+        }
+
+      factor_insert_multiplicity (factors, 2, cnt);
+    }
+
+  uintmax_t p =3D 3;
+  unsigned int i;
+  for (i =3D 0; t1 > 0 && i < PRIMES_PTAB_ENTRIES; i++)
+    {
+      for (;;)
+        {
+          uintmax_t q1, q0, hi, lo;
+
+          q0 =3D t0 * primes_dtab[i].binv;
+          umul_ppmm (hi, lo, q0, p);
+          if (hi > t1)
+            break;
+          hi =3D t1 - hi;
+          q1 =3D hi * primes_dtab[i].binv;
+          if (LIKELY (q1 > primes_dtab[i].lim))
+            break;
+          t1 =3D q1; t0 =3D q0;
+          factor_insert (factors, p);
+        }
+      p +=3D primes_diff[i + 1];
+    }
+  if (t1p)
+    *t1p =3D t1;
+
+#define DIVBLOCK(I)                                                     \
+  do {                                                                  \
+    for (;;)                                                            \
+      {                                                                 \
+        q =3D t0 * pd[I].binv;                                            \
+        if (LIKELY (q > pd[I].lim))                                     \
+          break;                                                        \
+        t0 =3D q;                                                         \
+        factor_insert_refind (factors, p, i + 1, I);                    \
+      }                                                                 \
+  } while (0)
+
+  for (; i < PRIMES_PTAB_ENTRIES; i +=3D 8)
+    {
+      uintmax_t q;
+      const struct primes_dtab *pd =3D &primes_dtab[i];
+      DIVBLOCK (0);
+      DIVBLOCK (1);
+      DIVBLOCK (2);
+      DIVBLOCK (3);
+      DIVBLOCK (4);
+      DIVBLOCK (5);
+      DIVBLOCK (6);
+      DIVBLOCK (7);
+
+      p +=3D primes_diff8[i];
+      if (p * p > t0)
+        break;
+    }
+
+  return t0;
+}
+
+#if HAVE_GMP
 static void
-emit_ul_factor (unsigned long int i)
+mp_factor_using_division (mpz_t t, struct mp_factors *factors)
 {
-  mpz_t t;
-  mpz_init (t);
-  mpz_set_ui (t, i);
-  emit_factor (t);
-  mpz_clear (t);
+  mpz_t q;
+  unsigned long int p;
+
+  debug ("[trial division] ");
+
+  mpz_init (q);
+
+  p =3D mpz_scan1 (t, 0);
+  mpz_div_2exp (t, t, p);
+  while (p)
+    {
+      mp_factor_insert_ui (factors, 2);
+      --p;
+    }
+
+  p =3D 3;
+  for (unsigned int i =3D 1; i <=3D PRIMES_PTAB_ENTRIES;)
+    {
+      if (! mpz_divisible_ui_p (t, p))
+        {
+          p +=3D primes_diff[i++];
+          if (mpz_cmp_ui (t, p * p) < 0)
+            break;
+        }
+      else
+        {
+          mpz_tdiv_q_ui (t, t, p);
+          mp_factor_insert_ui (factors, p);
+        }
+    }
+
+  mpz_clear (q);
+}
+#endif
+
+/* Entry i contains (2i+1)^(-1) mod 2^8.  */
+static const unsigned char  binvert_table[128] =3D
+{
+  0x01, 0xAB, 0xCD, 0xB7, 0x39, 0xA3, 0xC5, 0xEF,
+  0xF1, 0x1B, 0x3D, 0xA7, 0x29, 0x13, 0x35, 0xDF,
+  0xE1, 0x8B, 0xAD, 0x97, 0x19, 0x83, 0xA5, 0xCF,
+  0xD1, 0xFB, 0x1D, 0x87, 0x09, 0xF3, 0x15, 0xBF,
+  0xC1, 0x6B, 0x8D, 0x77, 0xF9, 0x63, 0x85, 0xAF,
+  0xB1, 0xDB, 0xFD, 0x67, 0xE9, 0xD3, 0xF5, 0x9F,
+  0xA1, 0x4B, 0x6D, 0x57, 0xD9, 0x43, 0x65, 0x8F,
+  0x91, 0xBB, 0xDD, 0x47, 0xC9, 0xB3, 0xD5, 0x7F,
+  0x81, 0x2B, 0x4D, 0x37, 0xB9, 0x23, 0x45, 0x6F,
+  0x71, 0x9B, 0xBD, 0x27, 0xA9, 0x93, 0xB5, 0x5F,
+  0x61, 0x0B, 0x2D, 0x17, 0x99, 0x03, 0x25, 0x4F,
+  0x51, 0x7B, 0x9D, 0x07, 0x89, 0x73, 0x95, 0x3F,
+  0x41, 0xEB, 0x0D, 0xF7, 0x79, 0xE3, 0x05, 0x2F,
+  0x31, 0x5B, 0x7D, 0xE7, 0x69, 0x53, 0x75, 0x1F,
+  0x21, 0xCB, 0xED, 0xD7, 0x59, 0xC3, 0xE5, 0x0F,
+  0x11, 0x3B, 0x5D, 0xC7, 0x49, 0x33, 0x55, 0xFF
+};
+
+/* Compute n^(-1) mod B, using a Newton iteration.  */
+#define binv(inv,n)                                                     \
+  do {                                                                  \
+    uintmax_t  __n =3D (n);                                               \
+    uintmax_t  __inv;                                                   \
+                                                                        \
+    __inv =3D binvert_table[(__n / 2) & 0x7F]; /*  8 */                   \
+    if (W_TYPE_SIZE > 8)   __inv =3D 2 * __inv - __inv * __inv * __n;     \
+    if (W_TYPE_SIZE > 16)  __inv =3D 2 * __inv - __inv * __inv * __n;     \
+    if (W_TYPE_SIZE > 32)  __inv =3D 2 * __inv - __inv * __inv * __n;     \
+                                                                        \
+    if (W_TYPE_SIZE > 64)                                               \
+      {                                                                 \
+        int  __invbits =3D 64;                                            \
+        do {                                                            \
+          __inv =3D 2 * __inv - __inv * __inv * __n;                      \
+          __invbits *=3D 2;                                               \
+        } while (__invbits < W_TYPE_SIZE);                              \
+      }                                                                 \
+                                                                        \
+    (inv) =3D __inv;                                                      \
+  } while (0)
+
+/* q =3D u / d, assuming d|u.  */
+#define divexact_21(q1, q0, u1, u0, d)                                  \
+  do {                                                                  \
+    uintmax_t _di, _q0;                                                 \
+    binv (_di, (d));                                                    \
+    _q0 =3D (u0) * _di;                                                   \
+    if ((u1) >=3D (d))                                                    \
+      {                                                                 \
+        uintmax_t _p1, _p0;                                             \
+        umul_ppmm (_p1, _p0, _q0, d);                                   \
+        (q1) =3D ((u1) - _p1) * _di;                                      \
+        (q0) =3D _q0;                                                     \
+      }                                                                 \
+    else                                                                \
+      {                                                                 \
+        (q0) =3D _q0;                                                     \
+        (q1) =3D 0;                                                       \
+      }                                                                 \
+  } while (0)
+
+/* x B (mod n). */
+#define redcify(r_prim, r, n)                                           \
+  do {                                                                  \
+    uintmax_t _redcify_q ATTRIBUTE_UNUSED;                              \
+    udiv_qrnnd (_redcify_q, r_prim, r, 0, n);                           \
+  } while (0)
+
+/* x B^2 (mod n). Requires x > 0, n1 < B/2 */
+#define redcify2(r1, r0, x, n1, n0)                                     \
+  do {                                                                  \
+    uintmax_t _r1, _r0, _i;                                             \
+    if ((x) < (n1))                                                     \
+      {                                                                 \
+        _r1 =3D (x); _r0 =3D 0;                                           =
  \
+        _i =3D W_TYPE_SIZE;                                               \
+      }                                                                 \
+    else                                                                \
+      {                                                                 \
+        _r1 =3D 0; _r0 =3D (x);                                           =
  \
+        _i =3D 2*W_TYPE_SIZE;                                             \
+      }                                                                 \
+    while (_i-- > 0)                                                    \
+      {                                                                 \
+        lsh2 (_r1, _r0, _r1, _r0, 1);                                   \
+        if (ge2 (_r1, _r0, (n1), (n0)))                                 \
+          sub_ddmmss (_r1, _r0, _r1, _r0, (n1), (n0));                  \
+      }                                                                 \
+    (r1) =3D _r1;                                                         \
+    (r0) =3D _r0;                                                         \
+  } while (0)
+
+/* Modular two-word multiplication, r =3D a * b mod m, with mi =3D m^(-1) =
mod B.
+   Both a and b must be in redc form, the result will be in redc form too.=
 */
+static inline uintmax_t
+mulredc (uintmax_t a, uintmax_t b, uintmax_t m, uintmax_t mi)
+{
+  uintmax_t rh, rl, q, th, tl, xh;
+
+  umul_ppmm (rh, rl, a, b);
+  q =3D rl * mi;
+  umul_ppmm (th, tl, q, m);
+  xh =3D rh - th;
+  if (rh < th)
+    xh +=3D m;
+
+  return xh;
+}
+
+/* Modular two-word multiplication, r =3D a * b mod m, with mi =3D m^(-1) =
mod B.
+   Both a and b must be in redc form, the result will be in redc form too.
+   For performance reasons, the most significant bit of m must be clear. */
+static uintmax_t
+mulredc2 (uintmax_t *r1p,
+          uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax_t b0,
+          uintmax_t m1, uintmax_t m0, uintmax_t mi)
+{
+  uintmax_t r1, r0, q, p1, p0, t1, t0, s1, s0;
+  mi =3D -mi;
+  assert ( (a1 >> (W_TYPE_SIZE - 1)) =3D=3D 0);
+  assert ( (b1 >> (W_TYPE_SIZE - 1)) =3D=3D 0);
+  assert ( (m1 >> (W_TYPE_SIZE - 1)) =3D=3D 0);
+
+  /* First compute a0 * <b1, b0> B^{-1}
+        +-----+
+        |a0 b0|
+     +--+--+--+
+     |a0 b1|
+     +--+--+--+
+        |q0 m0|
+     +--+--+--+
+     |q0 m1|
+    -+--+--+--+
+     |r1|r0| 0|
+     +--+--+--+
+  */
+  umul_ppmm (t1, t0, a0, b0);
+  umul_ppmm (r1, r0, a0, b1);
+  q =3D mi * t0;
+  umul_ppmm (p1, p0, q, m0);
+  umul_ppmm (s1, s0, q, m1);
+  r0 +=3D (t0 !=3D 0); /* Carry */
+  add_ssaaaa (r1, r0, r1, r0, 0, p1);
+  add_ssaaaa (r1, r0, r1, r0, 0, t1);
+  add_ssaaaa (r1, r0, r1, r0, s1, s0);
+
+  /* Next, (a1 * <b1, b0> + <r1, r0> B^{-1}
+        +-----+
+        |a1 b0|
+        +--+--+
+        |r1|r0|
+     +--+--+--+
+     |a1 b1|
+     +--+--+--+
+        |q1 m0|
+     +--+--+--+
+     |q1 m1|
+    -+--+--+--+
+     |r1|r0| 0|
+     +--+--+--+
+  */
+  umul_ppmm (t1, t0, a1, b0);
+  umul_ppmm (s1, s0, a1, b1);
+  add_ssaaaa (t1, t0, t1, t0, 0, r0);
+  q =3D mi * t0;
+  add_ssaaaa (r1, r0, s1, s0, 0, r1);
+  umul_ppmm (p1, p0, q, m0);
+  umul_ppmm (s1, s0, q, m1);
+  r0 +=3D (t0 !=3D 0); /* Carry */
+  add_ssaaaa (r1, r0, r1, r0, 0, p1);
+  add_ssaaaa (r1, r0, r1, r0, 0, t1);
+  add_ssaaaa (r1, r0, r1, r0, s1, s0);
+
+  if (ge2 (r1, r0, m1, m0))
+    sub_ddmmss (r1, r0, r1, r0, m1, m0);
+
+  *r1p =3D r1;
+  return r0;
+}
+
+static uintmax_t _GL_ATTRIBUTE_CONST
+powm (uintmax_t b, uintmax_t e, uintmax_t n, uintmax_t ni, uintmax_t one)
+{
+  uintmax_t y =3D one;
+
+  if (e & 1)
+    y =3D b;
+
+  while (e !=3D 0)
+    {
+      b =3D mulredc (b, b, n, ni);
+      e >>=3D 1;
+
+      if (e & 1)
+        y =3D mulredc (y, b, n, ni);
+    }
+
+  return y;
+}
+
+static uintmax_t
+powm2 (uintmax_t *r1m,
+       const uintmax_t *bp, const uintmax_t *ep, const uintmax_t *np,
+       uintmax_t ni, const uintmax_t *one)
+{
+  uintmax_t r1, r0, b1, b0, n1, n0;
+  unsigned int i;
+  uintmax_t e;
+
+  b0 =3D bp[0];
+  b1 =3D bp[1];
+  n0 =3D np[0];
+  n1 =3D np[1];
+
+  r0 =3D one[0];
+  r1 =3D one[1];
+
+  for (e =3D ep[0], i =3D W_TYPE_SIZE; i > 0; i--, e >>=3D 1)
+    {
+      if (e & 1)
+        {
+          r0 =3D mulredc2 (r1m, r1, r0, b1, b0, n1, n0, ni);
+          r1 =3D *r1m;
+        }
+      b0 =3D mulredc2 (r1m, b1, b0, b1, b0, n1, n0, ni);
+      b1 =3D *r1m;
+    }
+  for (e =3D ep[1]; e > 0; e >>=3D 1)
+    {
+      if (e & 1)
+        {
+          r0 =3D mulredc2 (r1m, r1, r0, b1, b0, n1, n0, ni);
+          r1 =3D *r1m;
+        }
+      b0 =3D mulredc2 (r1m, b1, b0, b1, b0, n1, n0, ni);
+      b1 =3D *r1m;
+    }
+  *r1m =3D r1;
+  return r0;
+}
+
+static bool _GL_ATTRIBUTE_CONST
+millerrabin (uintmax_t n, uintmax_t ni, uintmax_t b, uintmax_t q,
+             unsigned int k, uintmax_t one)
+{
+  uintmax_t y =3D powm (b, q, n, ni, one);
+
+  uintmax_t nm1 =3D n - one;      /* -1, but in redc representation. */
+
+  if (y =3D=3D one || y =3D=3D nm1)
+    return true;
+
+  for (unsigned int i =3D 1; i < k; i++)
+    {
+      y =3D mulredc (y, y, n, ni);
+
+      if (y =3D=3D nm1)
+        return true;
+      if (y =3D=3D one)
+        return false;
+    }
+  return false;
+}
+
+static bool
+millerrabin2 (const uintmax_t *np, uintmax_t ni, const uintmax_t *bp,
+              const uintmax_t *qp, unsigned int k, const uintmax_t *one)
+{
+  uintmax_t y1, y0, nm1_1, nm1_0, r1m;
+
+  y0 =3D powm2 (&r1m, bp, qp, np, ni, one);
+  y1 =3D r1m;
+
+  if (y0 =3D=3D one[0] && y1 =3D=3D one[1])
+    return true;
+
+  sub_ddmmss (nm1_1, nm1_0, np[1], np[0], one[1], one[0]);
+
+  if (y0 =3D=3D nm1_0 && y1 =3D=3D nm1_1)
+    return true;
+
+  for (unsigned int i =3D 1; i < k; i++)
+    {
+      y0 =3D mulredc2 (&r1m, y1, y0, y1, y0, np[1], np[0], ni);
+      y1 =3D r1m;
+
+      if (y0 =3D=3D nm1_0 && y1 =3D=3D nm1_1)
+        return true;
+      if (y0 =3D=3D one[0] && y1 =3D=3D one[1])
+        return false;
+    }
+  return false;
+}
+
+#if HAVE_GMP
+static bool
+mp_millerrabin (mpz_srcptr n, mpz_srcptr nm1, mpz_ptr x, mpz_ptr y,
+                mpz_srcptr q, unsigned long int k)
+{
+  mpz_powm (y, x, q, n);
+
+  if (mpz_cmp_ui (y, 1) =3D=3D 0 || mpz_cmp (y, nm1) =3D=3D 0)
+    return true;
+
+  for (unsigned long int i =3D 1; i < k; i++)
+    {
+      mpz_powm_ui (y, y, 2, n);
+      if (mpz_cmp (y, nm1) =3D=3D 0)
+        return true;
+      if (mpz_cmp_ui (y, 1) =3D=3D 0)
+        return false;
+    }
+  return false;
+}
+#endif
+
+/* Lucas' prime test.  The number of iterations vary greatly, up to a few =
dozen
+   have been observed.  The average seem to be about 2.  */
+static bool
+prime_p (uintmax_t n)
+{
+  int k;
+  bool is_prime;
+  uintmax_t a_prim, one, ni;
+  struct factors factors;
+
+  if (n <=3D 1)
+    return false;
+
+  /* We have already casted out small primes. */
+  if (n < (uintmax_t) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME)
+    return true;
+
+  /* Precomputation for Miller-Rabin.  */
+  uintmax_t q =3D n - 1;
+  for (k =3D 0; (q & 1) =3D=3D 0; k++)
+    q >>=3D 1;
+
+  uintmax_t a =3D 2;
+  binv (ni, n);                 /* ni <- 1/n mod B */
+  redcify (one, 1, n);
+  addmod (a_prim, one, one, n); /* i.e., redcify a =3D 2 */
+
+  /* Perform a Miller-Rabin test, finds most composites quickly.  */
+  if (!millerrabin (n, ni, a_prim, q, k, one))
+    return false;
+
+  if (flag_prove_primality)
+    {
+      /* Factor n-1 for Lucas.  */
+      factor (0, n - 1, &factors);
+    }
+
+  /* Loop until Lucas proves our number prime, or Miller-Rabin proves our
+     number composite.  */
+  for (unsigned int r =3D 0; r < PRIMES_PTAB_ENTRIES; r++)
+    {
+      if (flag_prove_primality)
+        {
+          is_prime =3D true;
+          for (unsigned int i =3D 0; i < factors.nfactors && is_prime; i++)
+            {
+              is_prime
+                =3D powm (a_prim, (n - 1) / factors.p[i], n, ni, one) !=3D=
 one;
+            }
+        }
+      else
+        {
+          /* After enough Miller-Rabin runs, be content. */
+          is_prime =3D (r =3D=3D MR_REPS - 1);
+        }
+
+      if (is_prime)
+        return true;
+
+      a +=3D primes_diff[r];      /* Establish new base.  */
+
+      /* The following is equivalent to redcify (a_prim, a, n).  It runs f=
aster
+         on most processors, since it avoids udiv_qrnnd.  If we go down the
+         udiv_qrnnd_preinv path, this code should be replaced.  */
+      {
+        uintmax_t s1, s0;
+        umul_ppmm (s1, s0, one, a);
+        if (LIKELY (s1 =3D=3D 0))
+          a_prim =3D s0 % n;
+        else
+          {
+            uintmax_t dummy ATTRIBUTE_UNUSED;
+            udiv_qrnnd (dummy, a_prim, s1, s0, n);
+          }
+      }
+
+      if (!millerrabin (n, ni, a_prim, q, k, one))
+        return false;
+    }
+
+  error (0, 0, _("Lucas prime test failure.  This should not happen"));
+  abort ();
+}
+
+static bool
+prime2_p (uintmax_t n1, uintmax_t n0)
+{
+  uintmax_t q[2], nm1[2];
+  uintmax_t a_prim[2];
+  uintmax_t one[2];
+  uintmax_t na[2];
+  uintmax_t ni;
+  unsigned int k;
+  struct factors factors;
+
+  if (n1 =3D=3D 0)
+    return prime_p (n0);
+
+  nm1[1] =3D n1 - (n0 =3D=3D 0);
+  nm1[0] =3D n0 - 1;
+  if (nm1[0] =3D=3D 0)
+    {
+      count_trailing_zeros (k, nm1[1]);
+
+      q[0] =3D nm1[1] >> k;
+      q[1] =3D 0;
+      k +=3D W_TYPE_SIZE;
+    }
+  else
+    {
+      count_trailing_zeros (k, nm1[0]);
+      rsh2 (q[1], q[0], nm1[1], nm1[0], k);
+    }
+
+  uintmax_t a =3D 2;
+  binv (ni, n0);
+  redcify2 (one[1], one[0], 1, n1, n0);
+  addmod2 (a_prim[1], a_prim[0], one[1], one[0], one[1], one[0], n1, n0);
+
+  /* FIXME: Use scalars or pointers in arguments? Some consistency needed.=
 */
+  na[0] =3D n0;
+  na[1] =3D n1;
+
+  if (!millerrabin2 (na, ni, a_prim, q, k, one))
+    return false;
+
+  if (flag_prove_primality)
+    {
+      /* Factor n-1 for Lucas.  */
+      factor (nm1[1], nm1[0], &factors);
+    }
+
+  /* Loop until Lucas proves our number prime, or Miller-Rabin proves our
+     number composite.  */
+  for (unsigned int r =3D 0; r < PRIMES_PTAB_ENTRIES; r++)
+    {
+      bool is_prime;
+      uintmax_t e[2], y[2];
+
+      if (flag_prove_primality)
+        {
+          is_prime =3D true;
+          if (factors.plarge[1])
+            {
+              uintmax_t pi;
+              binv (pi, factors.plarge[0]);
+              e[0] =3D pi * nm1[0];
+              e[1] =3D 0;
+              y[0] =3D powm2 (&y[1], a_prim, e, na, ni, one);
+              is_prime =3D (y[0] !=3D one[0] || y[1] !=3D one[1]);
+            }
+          for (unsigned int i =3D 0; i < factors.nfactors && is_prime; i++)
+            {
+              /* FIXME: We always have the factor 2. Do we really need to
+                 handle it here? We have done the same powering as part
+                 of millerrabin. */
+              if (factors.p[i] =3D=3D 2)
+                rsh2 (e[1], e[0], nm1[1], nm1[0], 1);
+              else
+                divexact_21 (e[1], e[0], nm1[1], nm1[0], factors.p[i]);
+              y[0] =3D powm2 (&y[1], a_prim, e, na, ni, one);
+              is_prime =3D (y[0] !=3D one[0] || y[1] !=3D one[1]);
+            }
+        }
+      else
+        {
+          /* After enough Miller-Rabin runs, be content. */
+          is_prime =3D (r =3D=3D MR_REPS - 1);
+        }
+
+      if (is_prime)
+        return true;
+
+      a +=3D primes_diff[r];      /* Establish new base.  */
+      redcify2 (a_prim[1], a_prim[0], a, n1, n0);
+
+      if (!millerrabin2 (na, ni, a_prim, q, k, one))
+        return false;
+    }
+
+  error (0, 0, _("Lucas prime test failure.  This should not happen"));
+  abort ();
+}
+
+#if HAVE_GMP
+static bool
+mp_prime_p (mpz_t n)
+{
+  bool is_prime;
+  mpz_t q, a, nm1, tmp;
+  struct mp_factors factors;
+
+  if (mpz_cmp_ui (n, 1) <=3D 0)
+    return false;
+
+  /* We have already casted out small primes. */
+  if (mpz_cmp_ui (n, (long) FIRST_OMITTED_PRIME * FIRST_OMITTED_PRIME) < 0)
+    return true;
+
+  mpz_inits (q, a, nm1, tmp, NULL);
+
+  /* Precomputation for Miller-Rabin.  */
+  mpz_sub_ui (nm1, n, 1);
+
+  /* Find q and k, where q is odd and n =3D 1 + 2**k * q.  */
+  unsigned long int k =3D mpz_scan1 (nm1, 0);
+  mpz_tdiv_q_2exp (q, nm1, k);
+
+  mpz_set_ui (a, 2);
+
+  /* Perform a Miller-Rabin test, finds most composites quickly.  */
+  if (!mp_millerrabin (n, nm1, a, tmp, q, k))
+    {
+      is_prime =3D false;
+      goto ret2;
+    }
+
+  if (flag_prove_primality)
+    {
+      /* Factor n-1 for Lucas.  */
+      mpz_set (tmp, nm1);
+      mp_factor (tmp, &factors);
+    }
+
+  /* Loop until Lucas proves our number prime, or Miller-Rabin proves our
+     number composite.  */
+  for (unsigned int r =3D 0; r < PRIMES_PTAB_ENTRIES; r++)
+    {
+      if (flag_prove_primality)
+        {
+          is_prime =3D true;
+          for (unsigned long int i =3D 0; i < factors.nfactors && is_prime=
; i++)
+            {
+              mpz_divexact (tmp, nm1, factors.p[i]);
+              mpz_powm (tmp, a, tmp, n);
+              is_prime =3D mpz_cmp_ui (tmp, 1) !=3D 0;
+            }
+        }
+      else
+        {
+          /* After enough Miller-Rabin runs, be content. */
+          is_prime =3D (r =3D=3D MR_REPS - 1);
+        }
+
+      if (is_prime)
+        goto ret1;
+
+      mpz_add_ui (a, a, primes_diff[r]);        /* Establish new base.  */
+
+      if (!mp_millerrabin (n, nm1, a, tmp, q, k))
+        {
+          is_prime =3D false;
+          goto ret1;
+        }
+    }
+
+  error (0, 0, _("Lucas prime test failure.  This should not happen"));
+  abort ();
+
+ ret1:
+  if (flag_prove_primality)
+    mp_factor_clear (&factors);
+ ret2:
+  mpz_clears (q, a, nm1, tmp, NULL);
+
+  return is_prime;
 }
+#endif
+
+static void
+factor_using_pollard_rho (uintmax_t n, unsigned long int a,
+                          struct factors *factors)
+{
+  uintmax_t x, z, y, P, t, ni, g;
+
+  unsigned long int k =3D 1;
+  unsigned long int l =3D 1;
+
+  redcify (P, 1, n);
+  addmod (x, P, P, n);          /* i.e., redcify(2) */
+  y =3D z =3D x;
+
+  while (n !=3D 1)
+    {
+      assert (a < n);
+
+      binv (ni, n);             /* FIXME: when could we use old 'ni' value=
? */
+
+      for (;;)
+        {
+          do
+            {
+              x =3D mulredc (x, x, n, ni);
+              addmod (x, x, a, n);
+
+              submod (t, z, x, n);
+              P =3D mulredc (P, t, n, ni);
+
+              if (k % 32 =3D=3D 1)
+                {
+                  if (gcd_odd (P, n) !=3D 1)
+                    goto factor_found;
+                  y =3D x;
+                }
+            }
+          while (--k !=3D 0);
+
+          z =3D x;
+          k =3D l;
+          l =3D 2 * l;
+          for (unsigned long int i =3D 0; i < k; i++)
+            {
+              x =3D mulredc (x, x, n, ni);
+              addmod (x, x, a, n);
+            }
+          y =3D x;
+        }
+
+    factor_found:
+      do
+        {
+          y =3D mulredc (y, y, n, ni);
+          addmod (y, y, a, n);
+
+          submod (t, z, y, n);
+          g =3D gcd_odd (t, n);
+        }
+      while (g =3D=3D 1);
+
+      n =3D n / g;
+
+      if (!prime_p (g))
+        factor_using_pollard_rho (g, a + 1, factors);
+      else
+        factor_insert (factors, g);
+
+      if (prime_p (n))
+        {
+          factor_insert (factors, n);
+          break;
+        }
+
+      x =3D x % n;
+      z =3D z % n;
+      y =3D y % n;
+    }
+}
+
+static void
+factor_using_pollard_rho2 (uintmax_t n1, uintmax_t n0, unsigned long int a,
+                           struct factors *factors)
+{
+  uintmax_t x1, x0, z1, z0, y1, y0, P1, P0, t1, t0, ni, g1, g0, r1m;
+
+  unsigned long int k =3D 1;
+  unsigned long int l =3D 1;
+
+  redcify2 (P1, P0, 1, n1, n0);
+  addmod2 (x1, x0, P1, P0, P1, P0, n1, n0); /* i.e., redcify(2) */
+  y1 =3D z1 =3D x1;
+  y0 =3D z0 =3D x0;
+
+  while (n1 !=3D 0 || n0 !=3D 1)
+    {
+      binv (ni, n0);
+
+      for (;;)
+        {
+          do
+            {
+              x0 =3D mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
+              x1 =3D r1m;
+              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
+
+              submod2 (t1, t0, z1, z0, x1, x0, n1, n0);
+              P0 =3D mulredc2 (&r1m, P1, P0, t1, t0, n1, n0, ni);
+              P1 =3D r1m;
+
+              if (k % 32 =3D=3D 1)
+                {
+                  g0 =3D gcd2_odd (&g1, P1, P0, n1, n0);
+                  if (g1 !=3D 0 || g0 !=3D 1)
+                    goto factor_found;
+                  y1 =3D x1; y0 =3D x0;
+                }
+            }
+          while (--k !=3D 0);
+
+          z1 =3D x1; z0 =3D x0;
+          k =3D l;
+          l =3D 2 * l;
+          for (unsigned long int i =3D 0; i < k; i++)
+            {
+              x0 =3D mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
+              x1 =3D r1m;
+              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
+            }
+          y1 =3D x1; y0 =3D x0;
+        }

-static void
-factor_using_division (mpz_t t, unsigned int limit)
-{
-  mpz_t q, r;
-  unsigned long int f;
-  int ai;
-  static unsigned int const add[] =3D {4, 2, 4, 2, 4, 6, 2, 6};
-  unsigned int const *addv =3D add;
-  unsigned int failures;
+    factor_found:
+      do
+        {
+          y0 =3D mulredc2 (&r1m, y1, y0, y1, y0, n1, n0, ni);
+          y1 =3D r1m;
+          addmod2 (y1, y0, y1, y0, 0, a, n1, n0);

-  debug ("[trial division (%u)] ", limit);
+          submod2 (t1, t0, z1, z0, y1, y0, n1, n0);
+          g0 =3D gcd2_odd (&g1, t1, t0, n1, n0);
+        }
+      while (g1 =3D=3D 0 && g0 =3D=3D 1);

-  mpz_init (q);
-  mpz_init (r);
+      if (g1 =3D=3D 0)
+        {
+          /* The found factor is one word. */
+          divexact_21 (n1, n0, n1, n0, g0);     /* n =3D n / g */

-  f =3D mpz_scan1 (t, 0);
-  mpz_div_2exp (t, t, f);
-  while (f)
-    {
-      emit_ul_factor (2);
-      --f;
-    }
+          if (!prime_p (g0))
+            factor_using_pollard_rho (g0, a + 1, factors);
+          else
+            factor_insert (factors, g0);
+        }
+      else
+        {
+          /* The found factor is two words.  This is highly unlikely, thus=
 hard
+             to trigger.  Please be careful before you change this code!  =
*/
+          uintmax_t ginv;

-  while (true)
-    {
-      mpz_tdiv_qr_ui (q, r, t, 3);
-      if (mpz_cmp_ui (r, 0) !=3D 0)
-        break;
-      mpz_set (t, q);
-      emit_ul_factor (3);
-    }
+          binv (ginv, g0);      /* Compute n =3D n / g.  Since the result =
will */
+          n0 =3D ginv * n0;       /* fit one word, we can compute the quot=
ient */
+          n1 =3D 0;               /* modulo B, ignoring the high divisor w=
ord. */

-  while (true)
-    {
-      mpz_tdiv_qr_ui (q, r, t, 5);
-      if (mpz_cmp_ui (r, 0) !=3D 0)
-        break;
-      mpz_set (t, q);
-      emit_ul_factor (5);
-    }
+          if (!prime2_p (g1, g0))
+            factor_using_pollard_rho2 (g1, g0, a + 1, factors);
+          else
+            factor_insert_large (factors, g1, g0);
+        }

-  failures =3D 0;
-  f =3D 7;
-  ai =3D 0;
-  while (mpz_cmp_ui (t, 1) !=3D 0)
-    {
-      mpz_tdiv_qr_ui (q, r, t, f);
-      if (mpz_cmp_ui (r, 0) !=3D 0)
+      if (n1 =3D=3D 0)
         {
-          f +=3D addv[ai];
-          if (mpz_cmp_ui (q, f) < 0)
-            break;
-          ai =3D (ai + 1) & 7;
-          failures++;
-          if (failures > limit)
-            break;
+          if (prime_p (n0))
+            {
+              factor_insert (factors, n0);
+              break;
+            }
+
+          factor_using_pollard_rho (n0, a, factors);
+          return;
         }
-      else
+
+      if (prime2_p (n1, n0))
         {
-          mpz_swap (t, q);
-          emit_ul_factor (f);
-          failures =3D 0;
+          factor_insert_large (factors, n1, n0);
+          break;
         }
-    }

-  mpz_clear (q);
-  mpz_clear (r);
+      x0 =3D mod2 (&x1, x1, x0, n1, n0);
+      z0 =3D mod2 (&z1, z1, z0, n1, n0);
+      y0 =3D mod2 (&y1, y1, y0, n1, n0);
+    }
 }

-/* The number of Miller-Rabin tests we require.  */
-enum { MR_REPS =3D 25 };
-
+#if HAVE_GMP
 static void
-factor_using_pollard_rho (mpz_t n, int a_int)
+mp_factor_using_pollard_rho (mpz_t n, unsigned long int a,
+                             struct mp_factors *factors)
 {
-  mpz_t x, x1, y, P;
-  mpz_t a;
-  mpz_t g;
-  mpz_t t1, t2;
-  int k, l, c;
-
-  debug ("[pollard-rho (%d)] ", a_int);
+  mpz_t x, z, y, P;
+  mpz_t t, t2;

-  mpz_init (g);
-  mpz_init (t1);
-  mpz_init (t2);
+  debug ("[pollard-rho (%lu)] ", a);

-  mpz_init_set_si (a, a_int);
+  mpz_inits (t, t2, NULL);
   mpz_init_set_si (y, 2);
   mpz_init_set_si (x, 2);
-  mpz_init_set_si (x1, 2);
-  k =3D 1;
-  l =3D 1;
+  mpz_init_set_si (z, 2);
   mpz_init_set_ui (P, 1);
-  c =3D 0;
+
+  unsigned long long int k =3D 1;
+  unsigned long long int l =3D 1;

   while (mpz_cmp_ui (n, 1) !=3D 0)
     {
-S2:
-      mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n);
-
-      mpz_sub (t1, x1, x); mpz_mul (t2, P, t1); mpz_mod (P, t2, n);
-      c++;
-      if (c =3D=3D 20)
+      for (;;)
         {
-          c =3D 0;
-          mpz_gcd (g, P, n);
-          if (mpz_cmp_ui (g, 1) !=3D 0)
-            goto S4;
+          do
+            {
+              mpz_mul (t, x, x);
+              mpz_mod (x, t, n);
+              mpz_add_ui (x, x, a);
+
+              mpz_sub (t, z, x);
+              mpz_mul (t2, P, t);
+              mpz_mod (P, t2, n);
+
+              if (k % 32 =3D=3D 1)
+                {
+                  mpz_gcd (t, P, n);
+                  if (mpz_cmp_ui (t, 1) !=3D 0)
+                    goto factor_found;
+                  mpz_set (y, x);
+                }
+            }
+          while (--k !=3D 0);
+
+          mpz_set (z, x);
+          k =3D l;
+          l =3D 2 * l;
+          for (unsigned long long int i =3D 0; i < k; i++)
+            {
+              mpz_mul (t, x, x);
+              mpz_mod (x, t, n);
+              mpz_add_ui (x, x, a);
+            }
           mpz_set (y, x);
         }

-      k--;
-      if (k > 0)
-        goto S2;
-
-      mpz_gcd (g, P, n);
-      if (mpz_cmp_ui (g, 1) !=3D 0)
-        goto S4;
-
-      mpz_set (x1, x);
-      k =3D l;
-      l =3D 2 * l;
-      unsigned int i;
-      for (i =3D 0; i < k; i++)
-        {
-          mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n);
-        }
-      mpz_set (y, x);
-      c =3D 0;
-      goto S2;
-S4:
+    factor_found:
       do
         {
-          mpz_mul (y, y, y); mpz_add (y, y, a); mpz_mod (y, y, n);
-          mpz_sub (t1, x1, y); mpz_gcd (g, t1, n);
+          mpz_mul (t, y, y);
+          mpz_mod (y, t, n);
+          mpz_add_ui (y, y, a);
+
+          mpz_sub (t, z, y);
+          mpz_gcd (t, t, n);
         }
-      while (mpz_cmp_ui (g, 1) =3D=3D 0);
+      while (mpz_cmp_ui (t, 1) =3D=3D 0);

-      mpz_div (n, n, g);	/* divide by g, before g is overwritten */
+      mpz_divexact (n, n, t);   /* divide by t, before t is overwritten */

-      if (!mpz_probab_prime_p (g, MR_REPS))
+      if (!mp_prime_p (t))
         {
-          do
-            {
-              mp_limb_t a_limb;
-              mpn_random (&a_limb, (mp_size_t) 1);
-              a_int =3D (int) a_limb;
-            }
-          while (a_int =3D=3D -2 || a_int =3D=3D 0);
-
           debug ("[composite factor--restarting pollard-rho] ");
-          factor_using_pollard_rho (g, a_int);
+          mp_factor_using_pollard_rho (t, a + 1, factors);
         }
       else
         {
-          emit_factor (g);
+          mp_factor_insert (factors, t);
         }
-      mpz_mod (x, x, n);
-      mpz_mod (x1, x1, n);
-      mpz_mod (y, y, n);
-      if (mpz_probab_prime_p (n, MR_REPS))
+
+      if (mp_prime_p (n))
         {
-          emit_factor (n);
+          mp_factor_insert (factors, n);
           break;
         }
+
+      mpz_mod (x, x, n);
+      mpz_mod (z, z, n);
+      mpz_mod (y, y, n);
     }

-  mpz_clear (g);
-  mpz_clear (P);
-  mpz_clear (t2);
-  mpz_clear (t1);
-  mpz_clear (a);
-  mpz_clear (x1);
-  mpz_clear (x);
-  mpz_clear (y);
+  mpz_clears (P, t2, t, z, x, y, NULL);
 }
+#endif

-#else
-
-static void
-debug (char const *fmt ATTRIBUTE_UNUSED, ...)
+/* FIXME: Maybe better to use an iteration converging to 1/sqrt(n)?  If
+   algorithm is replaced, consider also returning the remainder. */
+static uintmax_t _GL_ATTRIBUTE_CONST
+isqrt (uintmax_t n)
 {
+  uintmax_t x;
+  unsigned c;
+  if (n =3D=3D 0)
+    return 0;
+
+  count_leading_zeros (c, n);
+
+  /* Make x > sqrt(n). This will be invariant through the loop. */
+  x =3D (uintmax_t) 1 << ((W_TYPE_SIZE + 1 - c) / 2);
+
+  for (;;)
+    {
+      uintmax_t y =3D (x + n/x) / 2;
+      if (y >=3D x)
+        return x;
+
+      x =3D y;
+    }
 }

-#endif
+static uintmax_t _GL_ATTRIBUTE_CONST
+isqrt2 (uintmax_t nh, uintmax_t nl)
+{
+  unsigned int shift;
+  uintmax_t x;
+
+  /* Ensures the remainder fits in an uintmax_t. */
+  assert (nh < ((uintmax_t) 1 << (W_TYPE_SIZE - 2)));
+
+  if (nh =3D=3D 0)
+    return isqrt (nl);
+
+  count_leading_zeros (shift, nh);
+  shift &=3D ~1;
+
+  /* Make x > sqrt(n) */
+  x =3D isqrt ( (nh << shift) + (nl >> (W_TYPE_SIZE - shift))) + 1;
+  x <<=3D (W_TYPE_SIZE - shift) / 2;

-/* The maximum number of factors, including -1, for negative numbers.  */
-#define MAX_N_FACTORS (sizeof (uintmax_t) * CHAR_BIT)
+  /* Do we need more than one iteration? */
+  for (;;)
+    {
+      uintmax_t r ATTRIBUTE_UNUSED;
+      uintmax_t q, y;
+      udiv_qrnnd (q, r, nh, nl, x);
+      y =3D (x + q) / 2;
+
+      if (y >=3D x)
+        {
+          uintmax_t hi, lo;
+          umul_ppmm (hi, lo, x + 1, x + 1);
+          assert (gt2 (hi, lo, nh, nl));
+
+          umul_ppmm (hi, lo, x, x);
+          assert (ge2 (nh, nl, hi, lo));
+          sub_ddmmss (hi, lo, nh, nl, hi, lo);
+          assert (hi =3D=3D 0);
+
+          return x;
+        }
+
+      x =3D y;
+    }
+}
+
+/* MAGIC[N] has a bit i set iff i is a quadratic residue mod N. */
+#define MAGIC64 ((uint64_t) 0x0202021202030213ULL)
+#define MAGIC63 ((uint64_t) 0x0402483012450293ULL)
+#define MAGIC65 ((uint64_t) 0x218a019866014613ULL)
+#define MAGIC11 0x23b

-/* The trial divisor increment wheel.  Use it to skip over divisors that
-   are composites of 2, 3, 5, 7, or 11.  The part from WHEEL_START up to
-   WHEEL_END is reused periodically, while the "lead in" is used to test
-   for those primes and to jump onto the wheel.  For more information, see
-   http://www.utm.edu/research/primes/glossary/WheelFactorization.html  */
+/* Returns the square root if the input is a square, otherwise 0. */
+static uintmax_t _GL_ATTRIBUTE_CONST
+is_square (uintmax_t x)
+{
+  /* Uses the tests suggested by Cohen. Excludes 99% of the non-squares be=
fore
+     computing the square root. */
+  if (((MAGIC64 >> (x & 63)) & 1)
+      && ((MAGIC63 >> (x % 63)) & 1)
+      /* Both 0 and 64 are squares mod (65) */
+      && ((MAGIC65 >> ((x % 65) & 63)) & 1)
+      && ((MAGIC11 >> (x % 11) & 1)))
+    {
+      uintmax_t r =3D isqrt (x);
+      if (r*r =3D=3D x)
+        return r;
+    }
+  return 0;
+}

-#include "wheel-size.h"  /* For the definition of WHEEL_SIZE.  */
-static const unsigned char wheel_tab[] =3D
+/* invtab[i] =3D floor(0x10000 / (0x100 + i) */
+static const unsigned short invtab[0x81] =3D
   {
-#include "wheel.h"
+    0x200,
+    0x1fc, 0x1f8, 0x1f4, 0x1f0, 0x1ec, 0x1e9, 0x1e5, 0x1e1,
+    0x1de, 0x1da, 0x1d7, 0x1d4, 0x1d0, 0x1cd, 0x1ca, 0x1c7,
+    0x1c3, 0x1c0, 0x1bd, 0x1ba, 0x1b7, 0x1b4, 0x1b2, 0x1af,
+    0x1ac, 0x1a9, 0x1a6, 0x1a4, 0x1a1, 0x19e, 0x19c, 0x199,
+    0x197, 0x194, 0x192, 0x18f, 0x18d, 0x18a, 0x188, 0x186,
+    0x183, 0x181, 0x17f, 0x17d, 0x17a, 0x178, 0x176, 0x174,
+    0x172, 0x170, 0x16e, 0x16c, 0x16a, 0x168, 0x166, 0x164,
+    0x162, 0x160, 0x15e, 0x15c, 0x15a, 0x158, 0x157, 0x155,
+    0x153, 0x151, 0x150, 0x14e, 0x14c, 0x14a, 0x149, 0x147,
+    0x146, 0x144, 0x142, 0x141, 0x13f, 0x13e, 0x13c, 0x13b,
+    0x139, 0x138, 0x136, 0x135, 0x133, 0x132, 0x130, 0x12f,
+    0x12e, 0x12c, 0x12b, 0x129, 0x128, 0x127, 0x125, 0x124,
+    0x123, 0x121, 0x120, 0x11f, 0x11e, 0x11c, 0x11b, 0x11a,
+    0x119, 0x118, 0x116, 0x115, 0x114, 0x113, 0x112, 0x111,
+    0x10f, 0x10e, 0x10d, 0x10c, 0x10b, 0x10a, 0x109, 0x108,
+    0x107, 0x106, 0x105, 0x104, 0x103, 0x102, 0x101, 0x100,
   };

-#define WHEEL_START (wheel_tab + WHEEL_SIZE)
-#define WHEEL_END (wheel_tab + ARRAY_CARDINALITY (wheel_tab))
+/* Compute q =3D [u/d], r =3D u mod d.  Avoids slow hardware division for =
the case
+   that q < 0x40; here it instead uses a table of (Euclidian) inverses.  */
+#define div_smallq(q, r, u, d)                                          \
+  do {                                                                  \
+    if ((u) / 0x40 < (d))                                               \
+      {                                                                 \
+        int _cnt;                                                       \
+        uintmax_t _dinv, _mask, _q, _r;                                 \
+        count_leading_zeros (_cnt, (d));                                \
+        _r =3D (u);                                                       \
+        if (UNLIKELY (_cnt > (W_TYPE_SIZE - 8)))                        \
+          {                                                             \
+            _dinv =3D invtab[((d) << (_cnt + 8 - W_TYPE_SIZE)) - 0x80];   \
+            _q =3D _dinv * _r >> (8 + W_TYPE_SIZE - _cnt);                \
+          }                                                             \
+        else                                                            \
+          {                                                             \
+            _dinv =3D invtab[((d) >> (W_TYPE_SIZE - 8 - _cnt)) - 0x7f];   \
+            _q =3D _dinv * (_r >> (W_TYPE_SIZE - 3 - _cnt)) >> 11;        \
+          }                                                             \
+        _r -=3D _q*(d);                                                   \
+                                                                        \
+        _mask =3D -(uintmax_t) (_r >=3D (d));                             =
  \
+        (r) =3D _r - (_mask & (d));                                       \
+        (q) =3D _q - _mask;                                               \
+        assert ( (q) * (d) + (r) =3D=3D u);                               =
  \
+      }                                                                 \
+    else                                                                \
+      {                                                                 \
+        uintmax_t _q =3D (u) / (d);                                       \
+        (r) =3D (u) - _q * (d);                                           \
+        (q) =3D _q;                                                       \
+      }                                                                 \
+  } while (0)
+
+/* Notes: Example N =3D 22117019. After first phase we find Q1 =3D 6314, Q
+   =3D 3025, P =3D 1737, representing F_{18} =3D (-6314, 2* 1737, 3025),
+   with 3025 =3D 55^2.
+
+   Constructing the square root, we get Q1 =3D 55, Q =3D 8653, P =3D 4652,
+   representing G_0 =3D (-55, 2*4652, 8653).
+
+   In the notation of the paper:
+
+   S_{-1} =3D 55, S_0 =3D 8653, R_0 =3D 4652
+
+   Put
+
+     t_0 =3D floor([q_0 + R_0] / S0) =3D 1
+     R_1 =3D t_0 * S_0 - R_0 =3D 4001
+     S_1 =3D S_{-1} +t_0 (R_0 - R_1) =3D 706
+*/
+
+/* Multipliers, in order of efficiency:
+   0.7268  3*5*7*11 =3D 1155 =3D 3 (mod 4)
+   0.7317  3*5*7    =3D  105 =3D 1
+   0.7820  3*5*11   =3D  165 =3D 1
+   0.7872  3*5      =3D   15 =3D 3
+   0.8101  3*7*11   =3D  231 =3D 3
+   0.8155  3*7      =3D   21 =3D 1
+   0.8284  5*7*11   =3D  385 =3D 1
+   0.8339  5*7      =3D   35 =3D 3
+   0.8716  3*11     =3D   33 =3D 1
+   0.8774  3        =3D    3 =3D 3
+   0.8913  5*11     =3D   55 =3D 3
+   0.8972  5        =3D    5 =3D 1
+   0.9233  7*11     =3D   77 =3D 1
+   0.9295  7        =3D    7 =3D 3
+   0.9934  11       =3D   11 =3D 3
+*/
+#define QUEUE_SIZE 50

-/* FIXME: comment */
+#if STAT_SQUFOF
+# define Q_FREQ_SIZE 50
+/* Element 0 keeps the total */
+static unsigned int q_freq[Q_FREQ_SIZE + 1];
+# define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif

-static size_t
-factor_wheel (uintmax_t n0, size_t max_n_factors, uintmax_t *factors)
+/* Return true on success.  Expected to fail only for numbers
+   >=3D 2^{2*W_TYPE_SIZE - 2}, or close to that limit. */
+static bool
+factor_using_squfof (uintmax_t n1, uintmax_t n0, struct factors *factors)
 {
-  uintmax_t n =3D n0, d, q;
-  size_t n_factors =3D 0;
-  unsigned char const *w =3D wheel_tab;
+  /* Uses algorithm and notation from

-  if (n <=3D 1)
-    return n_factors;
+     SQUARE FORM FACTORIZATION
+     JASON E. GOWER AND SAMUEL S. WAGSTAFF, JR.
+
+     http://homes.cerias.purdue.edu/~ssw/squfof.pdf
+   */
+
+  static const unsigned int multipliers_1[] =3D
+    { /* =3D 1 (mod 4) */
+      105, 165, 21, 385, 33, 5, 77, 1, 0
+    };
+  static const unsigned int multipliers_3[] =3D
+    { /* =3D 3 (mod 4) */
+      1155, 15, 231, 35, 3, 55, 7, 11, 0
+    };
+
+  const unsigned int *m;
+
+  struct { uintmax_t Q; uintmax_t P; } queue[QUEUE_SIZE];

-  /* The exit condition in the following loop is correct because
-     any time it is tested one of these 3 conditions holds:
-      (1) d divides n
-      (2) n is prime
-      (3) n is composite but has no factors less than d.
-     If (1) or (2) obviously the right thing happens.
-     If (3), then since n is composite it is >=3D d^2. */
+  if (n1 >=3D ((uintmax_t) 1 << (W_TYPE_SIZE - 2)))
+    return false;

-  d =3D 2;
-  do
+  uintmax_t sqrt_n =3D isqrt2 (n1, n0);
+
+  if (n0 =3D=3D sqrt_n * sqrt_n)
     {
-      q =3D n / d;
-      while (n =3D=3D q * d)
+      uintmax_t p1, p0;
+
+      umul_ppmm (p1, p0, sqrt_n, sqrt_n);
+      assert (p0 =3D=3D n0);
+
+      if (n1 =3D=3D p1)
         {
-          assert (n_factors < max_n_factors);
-          factors[n_factors++] =3D d;
-          n =3D q;
-          q =3D n / d;
+          if (prime_p (sqrt_n))
+            factor_insert_multiplicity (factors, sqrt_n, 2);
+          else
+            {
+              struct factors f;
+
+              f.nfactors =3D 0;
+              if (!factor_using_squfof (0, sqrt_n, &f))
+                {
+                  /* Try pollard rho instead */
+                  factor_using_pollard_rho (sqrt_n, 1, &f);
+                }
+              /* Duplicate the new factors */
+              for (unsigned int i =3D 0; i < f.nfactors; i++)
+                factor_insert_multiplicity (factors, f.p[i], 2*f.e[i]);
+            }
+          return true;
         }
-      d +=3D *(w++);
-      if (w =3D=3D WHEEL_END)
-        w =3D WHEEL_START;
     }
-  while (d <=3D q);

-  if (n !=3D 1 || n0 =3D=3D 1)
+  /* Select multipliers so we always get n * mu =3D 3 (mod 4) */
+  for (m =3D (n0 % 4 =3D=3D 1) ? multipliers_3 : multipliers_1;
+       *m; m++)
     {
-      assert (n_factors < max_n_factors);
-      factors[n_factors++] =3D n;
-    }
+      uintmax_t S, Dh, Dl, Q1, Q, P, L, L1, B;
+      unsigned int i;
+      unsigned int mu =3D *m;
+      unsigned int qpos =3D 0;
+
+      assert (mu * n0 % 4 =3D=3D 3);
+
+      /* In the notation of the paper, with mu * n =3D=3D 3 (mod 4), we
+         get \Delta =3D 4 mu * n, and the paper's \mu is 2 mu. As far as
+         I understand it, the necessary bound is 4 \mu^3 < n, or 32
+         mu^3 < n.
+
+         However, this seems insufficient: With n =3D 37243139 and mu =3D
+         105, we get a trivial factor, from the square 38809 =3D 197^2,
+         without any corresponding Q earlier in the iteration.
+
+         Requiring 64 mu^3 < n seems sufficient. */
+      if (n1 =3D=3D 0)
+        {
+          if ((uintmax_t) mu*mu*mu >=3D n0 / 64)
+            continue;
+        }
+      else
+        {
+          if (n1 > ((uintmax_t) 1 << (W_TYPE_SIZE - 2)) / mu)
+            continue;
+        }
+      umul_ppmm (Dh, Dl, n0, mu);
+      Dh +=3D n1 * mu;
+
+      assert (Dl % 4 !=3D 1);
+      assert (Dh < (uintmax_t) 1 << (W_TYPE_SIZE - 2));
+
+      S =3D isqrt2 (Dh, Dl);
+
+      Q1 =3D 1;
+      P =3D S;
+
+      /* Square root remainder fits in one word, so ignore high part. */
+      Q =3D Dl - P*P;
+      /* FIXME: When can this differ from floor(sqrt(2 sqrt(D)))? */
+      L =3D isqrt (2*S);
+      B =3D 2*L;
+      L1 =3D mu * 2 * L;
+
+      /* The form is (+/- Q1, 2P, -/+ Q), of discriminant 4 (P^2 + Q Q1) =
=3D
+         4 D. */
+
+      for (i =3D 0; i <=3D B; i++)
+        {
+          uintmax_t q, P1, t, rem;
+
+          div_smallq (q, rem, S+P, Q);
+          P1 =3D S - rem; /* P1 =3D q*Q - P */
+
+#if STAT_SQUFOF
+          assert (q > 0);
+          q_freq[0]++;
+          q_freq[MIN (q, Q_FREQ_SIZE)]++;
+#endif
+
+          if (Q <=3D L1)
+            {
+              uintmax_t g =3D Q;
+
+              if ( (Q & 1) =3D=3D 0)
+                g /=3D 2;
+
+              g /=3D gcd_odd (g, mu);

-  return n_factors;
+              if (g <=3D L)
+                {
+                  if (qpos >=3D QUEUE_SIZE)
+                    error (EXIT_FAILURE, 0, _("squfof queue overflow"));
+                  queue[qpos].Q =3D g;
+                  queue[qpos].P =3D P % g;
+                  qpos++;
+                }
+            }
+
+          /* I think the difference can be either sign, but mod
+             2^W_TYPE_SIZE arithmetic should be fine. */
+          t =3D Q1 + q * (P - P1);
+          Q1 =3D Q;
+          Q =3D t;
+          P =3D P1;
+
+          if ( (i & 1) =3D=3D 0)
+            {
+              uintmax_t r =3D is_square (Q);
+              if (r)
+                {
+                  for (unsigned int j =3D 0; j < qpos; j++)
+                    {
+                      if (queue[j].Q =3D=3D r)
+                        {
+                          if (r =3D=3D 1)
+                            /* Traversed entire cycle. */
+                            goto next_multiplier;
+
+                          /* Need the absolute value for divisibility test=
. */
+                          if (P >=3D queue[j].P)
+                            t =3D P - queue[j].P;
+                          else
+                            t =3D queue[j].P - P;
+                          if (t % r =3D=3D 0)
+                            {
+                              /* Delete entries up to and including entry
+                                 j, which matched. */
+                              memmove (queue, queue + j + 1,
+                                       (qpos - j - 1) * sizeof (queue[0]));
+                              qpos -=3D (j + 1);
+                            }
+                          goto next_i;
+                        }
+                    }
+
+                  /* We have found a square form, which should give a
+                     factor. */
+                  Q1 =3D r;
+                  assert (S >=3D P); /* What signs are possible? */
+                  P +=3D r * ((S - P) / r);
+
+                  /* Note: Paper says (N - P*P) / Q1, that seems incorrect
+                     for the case D =3D 2N. */
+                  /* Compute Q =3D (D - P*P) / Q1, but we need double
+                     precision. */
+                  uintmax_t hi, lo;
+                  umul_ppmm (hi, lo, P, P);
+                  sub_ddmmss (hi, lo, Dh, Dl, hi, lo);
+                  udiv_qrnnd (Q, rem, hi, lo, Q1);
+                  assert (rem =3D=3D 0);
+
+                  for (;;)
+                    {
+                      /* Note: There appears to by a typo in the paper,
+                         Step 4a in the algorithm description says q <--
+                         floor([S+P]/\hat Q), but looking at the equations
+                         in Sec. 3.1, it should be q <-- floor([S+P] / Q).
+                         (In this code, \hat Q is Q1). */
+                      div_smallq (q, rem, S+P, Q);
+                      P1 =3D S - rem;     /* P1 =3D q*Q - P */
+
+#if STAT_SQUFOF
+                      q_freq[0]++;
+                      q_freq[MIN (q, Q_FREQ_SIZE)]++;
+#endif
+                      if (P =3D=3D P1)
+                        break;
+                      t =3D Q1 + q * (P - P1);
+                      Q1 =3D Q;
+                      Q =3D t;
+                      P =3D P1;
+                    }
+
+                  if ( (Q & 1) =3D=3D 0)
+                    Q /=3D 2;
+                  Q /=3D gcd_odd (Q, mu);
+
+                  assert (Q > 1 && (n1 || Q < n0));
+
+                  if (prime_p (Q))
+                    factor_insert (factors, Q);
+                  else if (!factor_using_squfof (0, Q, factors))
+                    factor_using_pollard_rho (Q, 2, factors);
+
+                  divexact_21 (n1, n0, n1, n0, Q);
+
+                  if (prime2_p (n1, n0))
+                    factor_insert_large (factors, n1, n0);
+                  else
+                    {
+                      if (!factor_using_squfof (n1, n0, factors))
+                        {
+                          if (n1 =3D=3D 0)
+                            factor_using_pollard_rho (n0, 1, factors);
+                          else
+                            factor_using_pollard_rho2 (n1, n0, 1, factors);
+                        }
+                    }
+
+                  return true;
+                }
+            }
+        next_i:;
+        }
+    next_multiplier:;
+    }
+  return false;
 }

-/* Single-precision factoring */
 static void
-print_factors_single (uintmax_t n)
+factor (uintmax_t t1, uintmax_t t0, struct factors *factors)
 {
-  uintmax_t factors[MAX_N_FACTORS];
-  size_t n_factors =3D factor_wheel (n, MAX_N_FACTORS, factors);
-  size_t i;
-  char buf[INT_BUFSIZE_BOUND (uintmax_t)];
+  factors->nfactors =3D 0;
+  factors->plarge[1] =3D 0;

-  printf ("%s:", umaxtostr (n, buf));
-  for (i =3D 0; i < n_factors; i++)
-    printf (" %s", umaxtostr (factors[i], buf));
-  putchar ('\n');
-}
+  if (t1 =3D=3D 0 && t0 < 2)
+    return;

-#if HAVE_GMP
-static int
-mpcompare (const void *av, const void *bv)
-{
-  mpz_t *const *a =3D av;
-  mpz_t *const *b =3D bv;
-  return mpz_cmp (**a, **b);
+  t0 =3D factor_using_division (&t1, t1, t0, factors);
+
+  if (t1 =3D=3D 0 && t0 < 2)
+    return;
+
+  if (prime2_p (t1, t0))
+    factor_insert_large (factors, t1, t0);
+  else
+    {
+      if (alg =3D=3D ALG_SQUFOF)
+        if (factor_using_squfof (t1, t0, factors))
+          return;
+
+      if (t1 =3D=3D 0)
+        factor_using_pollard_rho (t0, 1, factors);
+      else
+        factor_using_pollard_rho2 (t1, t0, 1, factors);
+    }
 }

+#if HAVE_GMP
 static void
-sort_and_print_factors (void)
+mp_factor (mpz_t t, struct mp_factors *factors)
 {
-  mpz_t **faclist;
-  size_t i;
+  mp_factor_init (factors);

-  faclist =3D xcalloc (nfactors_found, sizeof *faclist);
-  for (i =3D 0; i < nfactors_found; ++i)
+  if (mpz_sgn (t) !=3D 0)
     {
-      faclist[i] =3D &factor[i];
+      mp_factor_using_division (t, factors);
+
+      if (mpz_cmp_ui (t, 1) !=3D 0)
+        {
+          debug ("[is number prime?] ");
+          if (mp_prime_p (t))
+            mp_factor_insert (factors, t);
+          else
+            mp_factor_using_pollard_rho (t, 1, factors);
+        }
     }
-  qsort (faclist, nfactors_found, sizeof *faclist, mpcompare);
+}
+#endif
+
+static strtol_error
+strto2uintmax (uintmax_t *hip, uintmax_t *lop, const char *s)
+{
+  unsigned int lo_carry;
+  uintmax_t hi, lo;

-  for (i =3D 0; i < nfactors_found; ++i)
+  strtol_error err;
+
+  hi =3D lo =3D 0;
+  for (;;)
     {
-      fputc (' ', stdout);
-      mpz_out_str (stdout, 10, *faclist[i]);
+      unsigned int c =3D *s++;
+      if (c =3D=3D 0)
+        break;
+
+      if (UNLIKELY (!ISDIGIT (c)))
+        {
+          err =3D LONGINT_INVALID;
+          break;
+        }
+      c -=3D '0';
+
+      err =3D LONGINT_OK;           /* we've seen at least one valid digit=
 */
+
+      if (UNLIKELY (hi > ~(uintmax_t)0 / 10))
+        {
+          err =3D LONGINT_OVERFLOW;
+          break;
+        }
+      hi =3D 10 * hi;
+
+      lo_carry =3D (lo >> (W_TYPE_SIZE - 3)) + (lo >> (W_TYPE_SIZE - 1));
+      lo_carry +=3D 10 * lo < 2 * lo;
+
+      lo =3D 10 * lo;
+      lo +=3D c;
+
+      lo_carry +=3D lo < c;
+      hi +=3D lo_carry;
+      if (UNLIKELY (hi < lo_carry))
+        {
+          err =3D LONGINT_OVERFLOW;
+          break;
+        }
     }
-  putchar ('\n');
-  free (faclist);
+
+  *hip =3D hi;
+  *lop =3D lo;
+
+  return err;
 }

 static void
-free_factors (void)
+print_uintmaxes (uintmax_t t1, uintmax_t t0)
 {
-  size_t i;
+  uintmax_t q, r;

-  for (i =3D 0; i < nfactors_found; ++i)
+  if (t1 =3D=3D 0)
+    printf ("%ju", t0);
+  else
     {
-      mpz_clear (factor[i]);
+      /* Use very plain code here since it seems hard to write fast code
+         without assuming a specific word size.  */
+      q =3D t1 / 1000000000;
+      r =3D t1 % 1000000000;
+      udiv_qrnnd (t0, r, r, t0, 1000000000);
+      print_uintmaxes (q, t0);
+      printf ("%09u", (int) r);
     }
-  /* Don't actually free factor[] because in the case where we are
-     reading numbers from stdin, we may be about to use it again.  */
-  nfactors_found =3D 0;
 }

-/* Arbitrary-precision factoring */
+/* Single-precision factoring */
 static void
-print_factors_multi (mpz_t t)
+print_factors_single (uintmax_t t1, uintmax_t t0)
 {
-  mpz_out_str (stdout, 10, t);
+  struct factors factors;
+
+  print_uintmaxes (t1, t0);
   putchar (':');

-  if (mpz_sgn (t) !=3D 0)
-    {
-      /* Set the trial division limit according to the size of t.  */
-      size_t n_bits =3D mpz_sizeinbase (t, 2);
-      unsigned int division_limit =3D MIN (n_bits, 1000);
-      division_limit *=3D division_limit;
+  factor (t1, t0, &factors);

-      factor_using_division (t, division_limit);
+  for (unsigned int j =3D 0; j < factors.nfactors; j++)
+    for (unsigned int k =3D 0; k < factors.e[j]; k++)
+      printf (" %ju", factors.p[j]);

-      if (mpz_cmp_ui (t, 1) !=3D 0)
-        {
-          debug ("[is number prime?] ");
-          if (mpz_probab_prime_p (t, MR_REPS))
-            emit_factor (t);
-          else
-            factor_using_pollard_rho (t, 1);
-        }
+  if (factors.plarge[1])
+    {
+      putchar (' ');
+      print_uintmaxes (factors.plarge[1], factors.plarge[0]);
     }
-
-  mpz_clear (t);
-  sort_and_print_factors ();
-  free_factors ();
+  putchar ('\n');
 }
-#endif
-

 /* Emit the factors of the indicated number.  If we have the option of usi=
ng
    either algorithm, we select on the basis of the length of the number.
@@ -434,58 +2288,55 @@ print_factors_multi (mpz_t t)
    has enough digits, because the algorithm is better.  The turnover point
    depends on the value.  */
 static bool
-print_factors (char const *s)
+print_factors (const char *input)
 {
-  uintmax_t n;
-  strtol_error err =3D xstrtoumax (s, NULL, 10, &n, "");
+  uintmax_t t1, t0;

-#if HAVE_GMP
-  enum { GMP_TURNOVER_POINT =3D 100000 };
+  /* Try converting the number to one or two words.  If it fails, use GMP =
or
+     print an error message.  The 2nd condition checks that the most
+     significant bit of the two-word number is clear, in a typesize neutral
+     way.  */
+  strtol_error err =3D strto2uintmax (&t1, &t0, input);

-  if (err =3D=3D LONGINT_OVERFLOW
-      || (err =3D=3D LONGINT_OK && GMP_TURNOVER_POINT <=3D n))
+  switch (err)
     {
-      mpz_t t;
-      mpz_init (t);
-      if (gmp_sscanf (s, "%Zd", t) =3D=3D 1)
+    case LONGINT_OK:
+      if (((t1 << 1) >> 1) =3D=3D t1)
         {
-          debug ("[%s]", _("using arbitrary-precision arithmetic"));
-          print_factors_multi (t);
+          debug ("[%s]", _("using single-precision arithmetic"));
+          print_factors_single (t1, t0);
           return true;
         }
-      err =3D LONGINT_INVALID;
-    }
-#endif
-
-  switch (err)
-    {
-    case LONGINT_OK:
-      debug ("[%s]", _("using single-precision arithmetic"));
-      print_factors_single (n);
-      return true;
-
-    case LONGINT_OVERFLOW:
-      error (0, 0, _("%s is too large"), quote (s));
-      return false;
+      break;

     default:
-      error (0, 0, _("%s is not a valid positive integer"), quote (s));
+      error (0, 0, _("%s is not a valid positive integer"), quote (input));
       return false;
     }
-}

-enum
-{
-  VERBOSE_OPTION =3D CHAR_MAX + 1
-};
+#if HAVE_GMP
+  debug ("[%s]", _("using arbitrary-precision arithmetic"));
+  mpz_t t;
+  struct mp_factors factors;

-static struct option const long_options[] =3D
-{
-  {"verbose", no_argument, NULL, VERBOSE_OPTION},
-  {GETOPT_HELP_OPTION_DECL},
-  {GETOPT_VERSION_OPTION_DECL},
-  {NULL, 0, NULL, 0}
-};
+  mpz_init_set_str (t, input, 10);
+
+  gmp_printf ("%Zd:", t);
+  mp_factor (t, &factors);
+
+  for (unsigned int j =3D 0; j < factors.nfactors; j++)
+    for (unsigned int k =3D 0; k < factors.e[j]; k++)
+      gmp_printf (" %Zd", factors.p[j]);
+
+  mp_factor_clear (&factors);
+  mpz_clear (t);
+  putchar ('\n');
+  return true;
+#else
+  error (0, 0, _("%s is too large"), quote (input));
+  return false;
+#endif
+}

 void
 usage (int status)
@@ -535,9 +2386,6 @@ do_stdin (void)
 int
 main (int argc, char **argv)
 {
-  bool ok;
-  int c;
-
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
   setlocale (LC_ALL, "");
@@ -546,12 +2394,23 @@ main (int argc, char **argv)

   atexit (close_stdout);

+  alg =3D ALG_POLLARD_RHO;        /* Default to Pollard rho */
+
+  int c;
   while ((c =3D getopt_long (argc, argv, "", long_options, NULL)) !=3D -1)
     {
       switch (c)
         {
         case VERBOSE_OPTION:
-          verbose =3D true;
+          verbose =3D 1;
+          break;
+
+        case 's':
+          alg =3D ALG_SQUFOF;
+          break;
+
+        case 'w':
+          flag_prove_primality =3D false;
           break;

         case_GETOPT_HELP_CHAR;
@@ -563,18 +2422,36 @@ main (int argc, char **argv)
         }
     }

+#if STAT_SQUFOF
+  if (alg =3D=3D ALG_SQUFOF)
+    memset (q_freq, 0, sizeof (q_freq));
+#endif
+
+  bool ok;
   if (argc <=3D optind)
     ok =3D do_stdin ();
   else
     {
-      int i;
       ok =3D true;
-      for (i =3D optind; i < argc; i++)
+      for (int i =3D optind; i < argc; i++)
         if (! print_factors (argv[i]))
           ok =3D false;
     }
-#if HAVE_GMP
-  free (factor);
+
+#if STAT_SQUFOF
+  if (alg =3D=3D ALG_SQUFOF && q_freq[0] > 0)
+    {
+      double acc_f;
+      printf ("q  freq.  cum. freq.(total: %d)\n", q_freq[0]);
+      for (unsigned int i =3D 1, acc_f =3D 0.0; i <=3D Q_FREQ_SIZE; i++)
+        {
+          double f =3D (double) q_freq[i] / q_freq[0];
+          acc_f +=3D f;
+          printf ("%s%d %.2f%% %.2f%%\n", i =3D=3D Q_FREQ_SIZE ? ">=3D" : =
"", i,
+                  100.0 * f, 100.0 * acc_f);
+        }
+    }
 #endif
+
   exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
diff --git a/src/local.mk b/src/local.mk
index 98259fa..6a01ef1 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -35,7 +35,10 @@ bin_PROGRAMS =3D @bin_PROGRAMS@
 pkglibexec_PROGRAMS =3D @pkglibexec_PROGRAMS@

 # Needed by the testsuite.
-noinst_PROGRAMS =3D src/setuidgid src/getlimits
+noinst_PROGRAMS =3D		\
+  src/getlimits			\
+  src/make-prime-list		\
+  src/setuidgid

 noinst_HEADERS =3D		\
   src/chown-core.h		\
@@ -48,20 +51,18 @@ noinst_HEADERS =3D		\
   src/fs-is-local.h		\
   src/group-list.h		\
   src/ioblksize.h		\
+  src/longlong.h		\
   src/ls.h			\
   src/operand2sig.h		\
   src/prog-fprintf.h		\
   src/remove.h			\
   src/system.h			\
-  src/wheel-size.h		\
-  src/wheel.h			\
   src/uname.h

 EXTRA_DIST +=3D		\
   src/dcgen		\
   src/dircolors.hin	\
   src/tac-pipe.c	\
-  src/wheel-gen.pl	\
   src/extract-magic	\
   src/c99-to-c89.diff

@@ -134,6 +135,12 @@ src_link_LDADD =3D $(LDADD)
 src_ln_LDADD =3D $(LDADD)
 src_logname_LDADD =3D $(LDADD)
 src_ls_LDADD =3D $(LDADD)
+
+# This must *not* depend on anything in lib/, since it is used to generate
+# src/primes.h.  If it depended on libcoreutils.a, that would pull all lib=
/*.c
+# into BUILT_SOURCES.
+src_make_prime_list_LDADD =3D
+
 src_md5sum_LDADD =3D $(LDADD)
 src_mkdir_LDADD =3D $(LDADD)
 src_mkfifo_LDADD =3D $(LDADD)
@@ -371,19 +378,11 @@ src/dircolors.h: src/dcgen src/dircolors.hin
 	$(AM_V_at)chmod a-w $@-t
 	$(AM_V_at)mv $@-t $@

-wheel_size =3D 5
-
-BUILT_SOURCES +=3D src/wheel-size.h
-src/wheel-size.h: Makefile.am
-	$(AM_V_GEN)rm -f $@ $@-t
-	$(AM_V_at)echo '#define WHEEL_SIZE $(wheel_size)' > $@-t
-	$(AM_V_at)chmod a-w $@-t
-	$(AM_V_at)mv $@-t $@
-
-BUILT_SOURCES +=3D src/wheel.h
-src/wheel.h: src/wheel-gen.pl Makefile.am
+BUILT_SOURCES +=3D src/primes.h
+CLEANFILES +=3D src/primes.h
+src/primes.h: src/make-prime-list
 	$(AM_V_GEN)rm -f $@ $@-t
-	$(AM_V_at)$(srcdir)/src/wheel-gen.pl $(wheel_size) > $@-t
+	$(AM_V_at)src/make-prime-list 5000 > $@-t
 	$(AM_V_at)chmod a-w $@-t
 	$(AM_V_at)mv $@-t $@

diff --git a/src/longlong.h b/src/longlong.h
index 84e32ee..510f40e 100644
--- a/src/longlong.h
+++ b/src/longlong.h
@@ -1,7 +1,7 @@
 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.

 Copyright 1991, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001, 2002, 2003,
-2004, 2005, 2007, 2008, 2009, 2011 Free Software Foundation, Inc.
+2004, 2005, 2007, 2008, 2009, 2011, 2012 Free Software Foundation, Inc.

 This file is free software; you can redistribute it and/or modify it under=
 the
 terms of the GNU Lesser General Public License as published by the Free
@@ -2055,6 +2055,10 @@ extern UWtype mpn_udiv_qrnnd_r (UWtype, UWtype, UWty=
pe, UWtype *);
 __GMP_DECLSPEC UWtype __MPN(udiv_w_sdiv) (UWtype *, UWtype, UWtype, UWtype=
);
 #endif

+#ifndef __GMP_DECLSPEC
+#define __GMP_DECLSPEC /* empty */
+#endif
+
 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  =
*/
 #if !defined (udiv_qrnnd)
 #define UDIV_NEEDS_NORMALIZATION 1
diff --git a/src/wheel-gen.pl b/src/wheel-gen.pl
deleted file mode 100755
index 65b60d1..0000000
--- a/src/wheel-gen.pl
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/usr/bin/perl -w
-# Generate the spokes of a wheel, for wheel factorization.
-
-# Copyright (C) 2001-2012 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 <http://www.gnu.org/licenses/>.
-
-eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
-  if 0;
-
-use strict;
-(my $ME =3D $0) =3D~ s|.*/||;
-
-# A global destructor to close standard output with error checking.
-sub END
-{
-  defined fileno STDOUT
-    or return;
-  close STDOUT
-    and return;
-  warn "$ME: closing standard output: $!\n";
-  $? ||=3D 1;
-}
-
-sub is_prime ($)
-{
-  my ($n) =3D @_;
-  use integer;
-
-  $n =3D=3D 2
-    and return 1;
-
-  my $d =3D 2;
-  my $w =3D 1;
-  while (1)
-    {
-      my $q =3D $n / $d;
-      $n =3D=3D $q * $d
-        and return 0;
-      $d +=3D $w;
-      $q < $d
-        and last;
-      $w =3D 2;
-    }
-  return 1;
-}
-
-{
-  @ARGV =3D=3D 1
-    or die "$ME: missing argument\n";
-
-  my $wheel_size =3D $ARGV[0];
-
-  my @primes =3D (2);
-  my $product =3D $primes[0];
-  my $n_primes =3D 1;
-  for (my $i =3D 3; ; $i +=3D 2)
-    {
-      if (is_prime $i)
-        {
-          push @primes, $i;
-          $product *=3D $i;
-          ++$n_primes =3D=3D $wheel_size
-            and last;
-        }
-    }
-
-  my $ws_m1 =3D $wheel_size - 1;
-  print <<EOF;
-/* The first $ws_m1 elements correspond to the incremental offsets of the
-   first $wheel_size primes (@primes).  The $wheel_size(th) element is the
-   difference between that last prime and the next largest integer
-   that is not a multiple of those primes.  The remaining numbers
-   define the wheel.  For more information, see
-   http://www.utm.edu/research/primes/glossary/WheelFactorization.html.  */
-EOF
-
-  my @increments;
-  my $prev =3D 2;
-  for (my $i =3D 3; ; $i +=3D 2)
-    {
-      my $rel_prime =3D 1;
-      foreach my $divisor (@primes)
-        {
-          $i !=3D $divisor && $i % $divisor =3D=3D 0
-            and $rel_prime =3D 0;
-        }
-
-      if ($rel_prime)
-        {
-          #warn $i, ' ', $i - $prev, "\n";
-          push @increments, $i - $prev;
-          $prev =3D $i;
-
-          $product + 1 < $i
-            and last;
-        }
-    }
-
-  print join (",\n", @increments), "\n";
-
-  exit 0;
-}
diff --git a/tests/factor/run.sh b/tests/factor/run.sh
new file mode 100755
index 0000000..6ff24c3
--- /dev/null
+++ b/tests/factor/run.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Test the factor rewrite.
+# Expect to be invoked via a file whose basename matches
+# /^(\d+)\-(\d+)\-([\da-f]{40})\.sh$/
+# The test is to run this command
+# seq $1 $2 | factor | shasum -c --status <(echo $3  -)
+# I.e., to ensure that the factorizations of integers $1..$2
+# match what we expect.
+
+# Copyright (C) 2012 Free Software Foundation, Inc.
+
+. "${srcdir=3D.}/tests/init.sh"; path_prepend_ ./src
+
+# Don't run these tests by default.
+very_expensive_
+
+print_ver_ factor seq
+
+# Remove the ".sh" suffix:
+t=3D${ME_%.sh}
+
+# Make IFS include "-", so that a simple "set" will separate the args:
+IFS=3D-$IFS
+set $t
+echo "$3  -" > exp
+
+f=3D1
+seq $1 $2 | factor | shasum -c --status exp && f=3D0
+
+Exit $f
diff --git a/tests/local.mk b/tests/local.mk
index 0b6d576..486bf31 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -16,9 +16,9 @@
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.

 # Indirections required so that we'll still be able to know the
-# complete list of our tests even if the user override TESTS from the
-# command line (which he's allowed to do by the test harness API).
-TESTS =3D $(all_tests)
+# complete list of our tests even if the user overrides TESTS
+# from the command line (as permitted by the test harness API).
+TESTS =3D $(all_tests) $(factor_tests)
 root_tests =3D $(all_root_tests)

 EXTRA_DIST +=3D $(all_tests)
@@ -89,14 +89,15 @@ TESTS_ENVIRONMENT =3D				\
 VERBOSE =3D yes

 EXTRA_DIST +=3D			\
+  init.cfg			\
   tests/Coreutils.pm		\
   tests/CuSkip.pm		\
   tests/CuTmpdir.pm		\
   tests/d_type-check		\
   tests/envvar-check		\
+  tests/factor/run.sh		\
   tests/filefrag-extent-compare \
   tests/fiemap-capable		\
-  init.cfg			\
   tests/init.sh			\
   tests/lang-default		\
   tests/no-perl			\
@@ -624,6 +625,68 @@ all_tests =3D					\
   tests/touch/trailing-slash.sh			\
   $(all_root_tests)

+# prefix of 2^64
+p =3D 184467440737
+# prefix of 2^96
+q =3D 79228162514264337593543
+
+# Each of these numbers has a Pollard rho factor larger than 2^64,
+# and thus exercises some hard-to-reach code in factor.c.
+t1 =3D 170141183460469225450570946617781744489
+t2 =3D 170141183460469229545748130981302223887
+# Factors of the above:
+# t1: 9223372036854775421 18446744073709551709
+# t2: 9223372036854775643 18446744073709551709
+
+# Each tests is a triple: lo, hi, sha1 of result.
+# The test script, run.sh, runs seq lo hi|factor|sha1sum
+# and verifies that the actual and expected checksums are the same.
+tf =3D tests/factor
+factor_tests =3D \
+  $(tf)/0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0.sh \
+  $(tf)/10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016.sh \
+  $(tf)/20000000-30000000-8115e8dff97d1674134ec054598d939a2a5f6113.sh \
+  $(tf)/30000000-40000000-fe7b832c8e0ed55035152c0f9ebd59de73224a60.sh \
+  $(tf)/40000000-50000000-b8786d66c432e48bc5b342ee3c6752b7f096f206.sh \
+  $(tf)/50000000-60000000-a74fe518c5f79873c2b9016745b88b42c8fd3ede.sh \
+  $(tf)/60000000-70000000-689bc70d681791e5d1b8ac1316a05d0c4473d6db.sh \
+  $(tf)/70000000-80000000-d370808f2ab8c865f64c2ff909c5722db5b7d58d.sh \
+  $(tf)/80000000-90000000-7978aa66bf2bdb446398336ea6f02605e9a77581.sh \
+  $(tf)/$(t1)-$(t1)-4622287c5f040cdb7b3bbe4d19d29a71ab277827.sh \
+  $(tf)/$(t2)-$(t2)-dea308253708b57afad357e8c0d2a111460ef50e.sh \
+  $(tf)/$(p)08551616-$(p)08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1=
.sh \
+  $(tf)/$(p)08651616-$(p)08751615-729228e693b1a568ecc85b199927424c7d16d410=
.sh \
+  $(tf)/$(p)08751616-$(p)08851615-5a0c985017c2d285e4698f836f5a059e0b684563=
.sh \
+  $(tf)/$(p)08851616-$(p)08951615-0482295c514e371c98ce9fd335deed0c9c44a4f4=
.sh \
+  $(tf)/$(p)08951616-$(p)09051615-9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71=
.sh \
+  $(tf)/$(p)09051616-$(p)09151615-604366d2b1d75371d0679e6a68962d66336cd383=
.sh \
+  $(tf)/$(p)09151616-$(p)09251615-9192d2bdee930135b28d7160e6d395a7027871da=
.sh \
+  $(tf)/$(p)09251616-$(p)09351615-bcf56ae55d20d700690cff4d3327b78f83fc01bf=
.sh \
+  $(tf)/$(p)09351616-$(p)09451615-16b106398749e5f24d278ba7c58229ae43f650ac=
.sh \
+  $(tf)/$(p)09451616-$(p)09551615-ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c=
.sh \
+  $(tf)/$(p)09551616-$(p)09651615-2b6f9c11742d9de045515a6627c27a042c49f8ba=
.sh \
+  $(tf)/$(p)09651616-$(p)09751615-54851acd51c4819beb666e26bc0100dc9adbc310=
.sh \
+  $(tf)/$(p)09751616-$(p)09851615-6939c2a7afd2d81f45f818a159b7c5226f83a50b=
.sh \
+  $(tf)/$(p)09851616-$(p)09951615-0f2c8bc011d2a45e2afa01459391e68873363c6c=
.sh \
+  $(tf)/$(p)09951616-$(p)10051615-630dc2ad72f4c222bad1405e6c5bea590f92a98c=
.sh \
+  $(tf)/$(q)940336-$(q)942335-63cbd6313d78247b04d63bbbac50cb8f8d33ff71.sh \
+  $(tf)/$(q)942336-$(q)944335-0d03d63653767173182491b86fa18f8f680bb036.sh \
+  $(tf)/$(q)944336-$(q)946335-ca43bd38cd9f97cc5bb63613cb19643578640f0b.sh \
+  $(tf)/$(q)946336-$(q)948335-86d59545a0c13567fa96811821ea5cde950611b1.sh \
+  $(tf)/$(q)948336-$(q)950335-c3740e702fa9c97e6cf00150860e0b936a141a6b.sh \
+  $(tf)/$(q)950336-$(q)952335-551c3c4c4640d86fda311b5c3006dac45505c0ce.sh \
+  $(tf)/$(q)952336-$(q)954335-b1b0b00463c2f853d70ef9c4f7a96de5cb614156.sh \
+  $(tf)/$(q)954336-$(q)956335-8938a484a9ef6bb16478091d294fcde9f8ecea69.sh \
+  $(tf)/$(q)956336-$(q)958335-d1ae6bc712d994f35edf55c785d71ddf31f16535.sh \
+  $(tf)/$(q)958336-$(q)960335-2374919a89196e1fce93adfe779cb4664556d4b6.sh \
+  $(tf)/$(q)960336-$(q)962335-569e4363e8d9e8830a187d9ab27365eef08abde1.sh
+
+$(factor_tests): tests/factor/run.sh
+	$(AM_V_GEN)$(MKDIR_P) $(tf)
+	$(AM_V_at)ln -f $(srcdir)/tests/factor/run.sh $@
+
+CLEANFILES +=3D $(factor_tests)
+
 pr_data =3D					\
   tests/pr/0F					\
   tests/pr/0FF					\
--=20
1.8.0.rc0.18.gf84667d


>From 06b7ed8051d07677572e074d3d45007f1282ed56 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Tue, 18 Sep 2012 08:26:17 +0200
Subject: [PATCH 8/8] factor: 25% speed-up, on output

* src/factor.c (print_factors_single): Use fputs and umaxtostr
rather than printf with "%ju".  This reduced the time required
to compute and print the factors of the first 10^7 integers from
over 8 seconds to 5.75s.  Run this command:
seq $((10**7)) | env time factor > /dev/null
---
 src/factor.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/factor.c b/src/factor.c
index 84d9721..1ca5812 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -2272,7 +2272,11 @@ print_factors_single (uintmax_t t1, uintmax_t t0)

   for (unsigned int j =3D 0; j < factors.nfactors; j++)
     for (unsigned int k =3D 0; k < factors.e[j]; k++)
-      printf (" %ju", factors.p[j]);
+      {
+        char buf[INT_BUFSIZE_BOUND (uintmax_t)];
+        putchar (' ');
+        fputs (umaxtostr (factors.p[j], buf), stdout);
+      }

   if (factors.plarge[1])
     {
--=20
1.8.0.rc0.18.gf84667d


--=-=-=--


From MAILER-DAEMON Fri Oct 05 11:10:26 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TK9Xm-0001Qg-6o
	for mharc-coreutils@gnu.org; Fri, 05 Oct 2012 11:10:26 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58059)
	by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <pth@suse.de>)
	id 1TK9Xj-0001Q7-Nd
	for coreutils@gnu.org; Fri, 05 Oct 2012 11:10:24 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <pth@suse.de>) id 1TK9XZ-0001Nl-Nf
	for coreutils@gnu.org; Fri, 05 Oct 2012 11:10:23 -0400
Received: from cantor2.suse.de ([195.135.220.15]:33305 helo=mx2.suse.de)
	by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <pth@suse.de>)
	id 1TK9XZ-0001KM-HL
	for coreutils@gnu.org; Fri, 05 Oct 2012 11:10:13 -0400
Received: from relay2.suse.de (unknown [195.135.220.254])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx2.suse.de (Postfix) with ESMTP id 31E9AA0FF6;
	Fri,  5 Oct 2012 17:10:11 +0200 (CEST)
Date: Fri, 5 Oct 2012 17:10:10 +0200
From: Philipp Thomas <pth@suse.de>
To: coreutils@gnu.org
Subject: Re: Supporting reflinked/cow files in coreutils
Message-ID: <20121005151010.GB1041@paradies.suse.de>
References: <20110414143352.GC5231@paradies.suse.de>
	<4DA71296.8040000@draigBrady.com>
	<20110418133444.GE28014@paradies.suse.de>
	<6AA787AA-590D-4C24-A7C0-18A8C17E74BC@oracle.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <6AA787AA-590D-4C24-A7C0-18A8C17E74BC@oracle.com>
X-Operating-System: openSUSE - Kernel Linux 3.4.6-2.10-desktop x86_64
Organization: SUSE LINUX Products GmbH, =?iso-8859-1?Q?G?=
	=?iso-8859-1?Q?F=3A_Jeff_Hawn=2C_Jennifer_Guild=2C_Felix_Imend=F6rffer=2C?=
	=?iso-8859-1?Q?_HRB_21284_=28AG_N=FCrnberg=29?=
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6
X-Received-From: 195.135.220.15
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 05 Oct 2012 15:10:24 -0000

Jim,

* Jeff liu (jeff.liu@oracle.com) [20110418 15:54]:

> FYI, I once implemented a similar patch to teach du(1) to show the disk
> footprint with reflinked stuff for OCFS2 only.
> 
> It is make use of rb-tree to figure out the shared extents and calculate the exactly used space eventually.
> http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007293.html
> http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007288.html
> http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007287.html
> 
> I have not submited the patch set to Coreutils since I guess it is hard to
> accept by upstream as reflink and FIEMAP_EXTENT_SHARED flag are not spread
> over the general filesystems.

in this thread Jeff asked you on your opinions regarding such a patch set
but somehow you never responded. Could you possibly do so now as I would
still like something like this to be included upstream.

regards
Philipp


From MAILER-DAEMON Fri Oct 05 11:26:58 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TK9nm-0001lY-2s
	for mharc-coreutils@gnu.org; Fri, 05 Oct 2012 11:26:58 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37527)
	by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <pth@suse.de>)
	id 1TK9nk-0001lH-Ec
	for coreutils@gnu.org; Fri, 05 Oct 2012 11:26:57 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <pth@suse.de>) id 1TK9nj-0007zg-4E
	for coreutils@gnu.org; Fri, 05 Oct 2012 11:26:56 -0400
Received: from cantor2.suse.de ([195.135.220.15]:33765 helo=mx2.suse.de)
	by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <pth@suse.de>)
	id 1TK9ni-0007yK-Tu
	for coreutils@gnu.org; Fri, 05 Oct 2012 11:26:55 -0400
Received: from relay2.suse.de (unknown [195.135.220.254])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx2.suse.de (Postfix) with ESMTP id 15F39A0FED
	for <coreutils@gnu.org>; Fri,  5 Oct 2012 17:26:54 +0200 (CEST)
Date: Fri, 5 Oct 2012 17:26:53 +0200
From: Philipp Thomas <pth@suse.de>
To: coreutils@gnu.org
Subject: Re: Some question regarding tail and option "-c"
Message-ID: <20121005152653.GC1041@paradies.suse.de>
References: <20121003155121.325b3f88@viper.suse.cz>
	<20121003171859.GA18334@hysteria.proulx.com>
	<20121003200145.3d5a4cd8@coolcat.suse.cz>
	<877gr7fmw9.fsf@rho.meyering.net>
	<20121004093247.00eb36fc@viper.suse.cz>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20121004093247.00eb36fc@viper.suse.cz>
X-Operating-System: openSUSE - Kernel Linux 3.4.6-2.10-desktop x86_64
Organization: SUSE LINUX Products GmbH, =?iso-8859-1?Q?G?=
	=?iso-8859-1?Q?F=3A_Jeff_Hawn=2C_Jennifer_Guild=2C_Felix_Imend=F6rffer=2C?=
	=?iso-8859-1?Q?_HRB_21284_=28AG_N=FCrnberg=29?=
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6
X-Received-From: 195.135.220.15
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 05 Oct 2012 15:26:57 -0000

* Robert Milasan (rmilasan@suse.com) [20121004 09:33]:

> I don't think we are using some old POSIX standard.

We're not using it but have been defining it. Our spec file for coreutils
passes DEFAULT_POSIX2_VERSION=199209 to configure.

This has been carried over from back when we needed it to make the
coretutils in SLES not change behaviour and nobody ever since changed it. 
IMO it should never have been used for the openSUSE coreutils and I'll
change it for openSUSE factory with the update to 8.19.

Philipp


From MAILER-DAEMON Fri Oct 05 12:21:06 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TKAeA-0004UW-Bh
	for mharc-coreutils@gnu.org; Fri, 05 Oct 2012 12:21:06 -0400
Received: from eggs.gnu.org ([208.118.235.92]:34738)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TKAe4-0004UA-91
	for coreutils@gnu.org; Fri, 05 Oct 2012 12:21:04 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TKAe2-0004Fg-MR
	for coreutils@gnu.org; Fri, 05 Oct 2012 12:20:59 -0400
Received: from mx.meyering.net ([88.168.87.75]:46551)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TKAe2-0004FZ-F4
	for coreutils@gnu.org; Fri, 05 Oct 2012 12:20:58 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 2B7AA600BD;
	Fri,  5 Oct 2012 18:20:57 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Philipp Thomas <pth@suse.de>
Subject: Re: Supporting reflinked/cow files in coreutils
In-Reply-To: <20121005151010.GB1041@paradies.suse.de> (Philipp Thomas's
	message of "Fri, 5 Oct 2012 17:10:10 +0200")
References: <20110414143352.GC5231@paradies.suse.de>
	<4DA71296.8040000@draigBrady.com>
	<20110418133444.GE28014@paradies.suse.de>
	<6AA787AA-590D-4C24-A7C0-18A8C17E74BC@oracle.com>
	<20121005151010.GB1041@paradies.suse.de>
Date: Fri, 05 Oct 2012 18:20:57 +0200
Message-ID: <87wqz43n6e.fsf@rho.meyering.net>
Lines: 70
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 05 Oct 2012 16:21:04 -0000

Philipp Thomas wrote:
> Jim,
>
> * Jeff liu (jeff.liu@oracle.com) [20110418 15:54]:
>
>> FYI, I once implemented a similar patch to teach du(1) to show the disk
>> footprint with reflinked stuff for OCFS2 only.
>>
>> It is make use of rb-tree to figure out the shared extents and
>> calculate the exactly used space eventually.
>> http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007293.html
>> http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007288.html
>> http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007287.html
>>
>> I have not submited the patch set to Coreutils since I guess it is hard to
>> accept by upstream as reflink and FIEMAP_EXTENT_SHARED flag are not spread
>> over the general filesystems.
>
> in this thread Jeff asked you on your opinions regarding such a patch set
> but somehow you never responded. Could you possibly do so now as I would
> still like something like this to be included upstream.

Hi Philipp,

Glancing through the patch in the first message,

    http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007293.html

I have a hard time justifying the addition of so much code for a
relatively small feature that will be useful only for OCFS2 file systems:

  coreutils-6.9/src/du.c |  479 +++++++++++++++++++++++++++++++++++++++++++++++-
  1 files changed, 473 insertions(+), 6 deletions(-)

That's a lot of new always-compiled code that will be used only by a
very small fraction of users.  And to add insult to injury, it extends
the ugly tentacles of FIEMAP into du.c.  It was bad enough to have to
use it in copy.c, and we're all impatient for something better, but
SEEK_HOLE and SEEK_DATA aren't yet widely available.

That's a lot of new code, not even counting these:

  * lib/rbtree.c: Source file of rbtree.
  * lib/rbtree.h: Header file of rbtree.
  * lib/Makefile.am (libcoreutils_a_SOURCES): Add both of them.
  ---
   coreutils-6.9/lib/Makefile.am |    3 +-
   coreutils-6.9/lib/Makefile.in |    4 +-
   coreutils-6.9/lib/rbtree.c    |  403 +++++++++++++++++++++++++++++++++++++++++
   coreutils-6.9/lib/rbtree.h    |  143 +++++++++++++++
   4 files changed, 550 insertions(+), 3 deletions(-)

Besides which, there is no reason to add new rbtree.[ch] code
when there is already plenty of rbtree code in gnulib.

If it can be made to work cleanly with BTRFS as well, and preferably
*without* FIEMAP (if possible, though I fear that FIEMAP is the only
interface we have for now), that would be even better.

If you and/or Jeff are motivated enough, a good first step would be to
post a rebased patch to bug-coreutils, preferably after you've switched
out that rbtree.[ch] for gnulib's code.  I hesitate even to suggest
that you rebase, because we might end up deciding it's not yet worth
the cost, but let's hear what others have to say.  Maybe enough people
use du and are bothered because the space used by their reflinked files
is over-reported.

A final question: why use an rbtree rather than a hash table?
du is already using hash tables at the required scale, and new code
would be required at all.


From MAILER-DAEMON Fri Oct 05 14:43:17 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TKCrl-0004tU-07
	for mharc-coreutils@gnu.org; Fri, 05 Oct 2012 14:43:17 -0400
Received: from eggs.gnu.org ([208.118.235.92]:47884)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <philipp@thogro.org>) id 1TKCri-0004tK-Tg
	for coreutils@gnu.org; Fri, 05 Oct 2012 14:43:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <philipp@thogro.org>) id 1TKCrg-0000op-Sv
	for coreutils@gnu.org; Fri, 05 Oct 2012 14:43:14 -0400
Received: from mailout-de.gmx.net ([213.165.64.22]:59736)
	by eggs.gnu.org with smtp (Exim 4.71)
	(envelope-from <philipp@thogro.org>) id 1TKCrg-0000og-J6
	for coreutils@gnu.org; Fri, 05 Oct 2012 14:43:12 -0400
Received: (qmail invoked by alias); 05 Oct 2012 18:43:10 -0000
Received: from dslb-188-098-226-117.pools.arcor-ip.net (EHLO Sisko)
	[188.98.226.117]
	by mail.gmx.net (mp012) with SMTP; 05 Oct 2012 20:43:10 +0200
X-Authenticated: #46577751
X-Provags-ID: V01U2FsdGVkX1/oZIACtY3oyCzm8PkBYnEgl9GwZvAj1/O7uZuAik
	sVseDPbHZ1+hBR
From: Philipp Thomas <philipp@thogro.org>
To: Jim Meyering <jim@meyering.net>
Subject: Re: Supporting reflinked/cow files in coreutils
Date: Fri, 05 Oct 2012 20:43:12 +0200
Message-ID: <k2au68likd7mjdculhsgphtm3c0tikdtpb@4ax.com>
References: <20110414143352.GC5231@paradies.suse.de>
	<4DA71296.8040000@draigBrady.com>
	<20110418133444.GE28014@paradies.suse.de>
	<6AA787AA-590D-4C24-A7C0-18A8C17E74BC@oracle.com>
	<20121005151010.GB1041@paradies.suse.de>
	<87wqz43n6e.fsf@rho.meyering.net>
In-Reply-To: <87wqz43n6e.fsf@rho.meyering.net>
User-Agent: ForteAgent/7.00.32.1200
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Y-GMX-Trusted: 0
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 213.165.64.22
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 05 Oct 2012 18:43:16 -0000

[Quoting in nearly full as to give Jeff enough context]

On Fri, 05 Oct 2012 18:20:57 +0200, <jim@meyering.net> wrote:

>Glancing through the patch in the first message,
>
>    =
http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007293.html
>
>I have a hard time justifying the addition of so much code for a
>relatively small feature that will be useful only for OCFS2 file =
systems:
>
>  coreutils-6.9/src/du.c |  479 =
+++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 473 insertions(+), 6 deletions(-)
>
>That's a lot of new always-compiled code that will be used only by a
>very small fraction of users.  And to add insult to injury, it extends
>the ugly tentacles of FIEMAP into du.c.  It was bad enough to have to
>use it in copy.c, and we're all impatient for something better, but
>SEEK_HOLE and SEEK_DATA aren't yet widely available.
>
>That's a lot of new code, not even counting these:
>
>  * lib/rbtree.c: Source file of rbtree.
>  * lib/rbtree.h: Header file of rbtree.
>  * lib/Makefile.am (libcoreutils_a_SOURCES): Add both of them.
>  ---
>   coreutils-6.9/lib/Makefile.am |    3 +-
>   coreutils-6.9/lib/Makefile.in |    4 +-
>   coreutils-6.9/lib/rbtree.c    |  403 =
+++++++++++++++++++++++++++++++++++++++++
>   coreutils-6.9/lib/rbtree.h    |  143 +++++++++++++++
>   4 files changed, 550 insertions(+), 3 deletions(-)
>
>Besides which, there is no reason to add new rbtree.[ch] code
>when there is already plenty of rbtree code in gnulib.
>
>If it can be made to work cleanly with BTRFS as well, and preferably
>*without* FIEMAP (if possible, though I fear that FIEMAP is the only
>interface we have for now), that would be even better.

I'd agree with you that It'd be much better if it would work with
OCFS2 and BTRFS.

>If you and/or Jeff are motivated enough, a good first step would be to
>post a rebased patch to bug-coreutils, preferably after you've switched
>out that rbtree.[ch] for gnulib's code.  I hesitate even to suggest
>that you rebase, because we might end up deciding it's not yet worth
>the cost, but let's hear what others have to say.  Maybe enough people
>use du and are bothered because the space used by their reflinked files
>is over-reported.

Jeff wrote last year that he'd post a rebased patch but hasn't done so
in the year that's passed. Maybe he will come forth and even use the
gnulib rbtree code.

>A final question: why use an rbtree rather than a hash table?
>du is already using hash tables at the required scale, and new code
>would be required at all.

That's up to Jeff to answer as I have nothing to do (yet) with that
code. I'm only an interested person who'd like such support in du.

Philipp


From MAILER-DAEMON Fri Oct 05 16:36:18 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TKEd8-00068A-3Z
	for mharc-coreutils@gnu.org; Fri, 05 Oct 2012 16:36:18 -0400
Received: from eggs.gnu.org ([208.118.235.92]:45073)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TKEd6-000682-72
	for coreutils@gnu.org; Fri, 05 Oct 2012 16:36:17 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TKEd5-0002jl-37
	for coreutils@gnu.org; Fri, 05 Oct 2012 16:36:16 -0400
Received: from mx.meyering.net ([88.168.87.75]:47216)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TKEd4-0002jc-T0
	for coreutils@gnu.org; Fri, 05 Oct 2012 16:36:15 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 74001602F4
	for <coreutils@gnu.org>; Fri,  5 Oct 2012 22:36:13 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: coreutils@gnu.org
Subject: [PATCH] build: avoid link failure when strerror is replaced
Date: Fri, 05 Oct 2012 22:36:13 +0200
Message-ID: <878vbk1wsi.fsf@rho.meyering.net>
Lines: 36
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 05 Oct 2012 20:36:17 -0000

FYI,

>From f947735d3c4036703e03bf6970784430db1355f7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Fri, 5 Oct 2012 22:35:27 +0200
Subject: [PATCH] build: avoid link failure when strerror is replaced

When building the new make-prime-list program on a system for which
strerror is defined to rpl_strerror, we'd get a link failure.
The problem is that we're including <config.h> for some definitions,
but do not want the rpl_ ones, since this particular program must
not be linked against gnulib (aka libcoreutils.a).  This did not
arise on Fedora 17 or 18, but did on Debian wheezy/sid.
* src/make-prime-list.c (strerror): #undef.
Build failure introduced by commit v8.19-152-gcf67e4c.
---
 src/make-prime-list.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/make-prime-list.c b/src/make-prime-list.c
index 49db2ba..e0d9b81 100644
--- a/src/make-prime-list.c
+++ b/src/make-prime-list.c
@@ -24,7 +24,10 @@ this program.  If not, see http://www.gnu.org/licenses/.  */
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
+
+/* Deactivate config.h's "rpl_"-prefixed definitions of these symbols.  */
 #undef fclose
+#undef strerror

 struct prime
 {
--
1.8.0.rc0.18.gf84667d


From MAILER-DAEMON Sun Oct 07 04:42:19 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TKmRH-0005OU-Tt
	for mharc-coreutils@gnu.org; Sun, 07 Oct 2012 04:42:19 -0400
Received: from eggs.gnu.org ([208.118.235.92]:42576)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TKmRE-0005OM-S0
	for coreutils@gnu.org; Sun, 07 Oct 2012 04:42:17 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TKmRD-0003AQ-TZ
	for coreutils@gnu.org; Sun, 07 Oct 2012 04:42:16 -0400
Received: from mx.meyering.net ([88.168.87.75]:51989)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TKmRD-0003AB-M7
	for coreutils@gnu.org; Sun, 07 Oct 2012 04:42:15 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 4C56F600B3
	for <coreutils@gnu.org>; Sun,  7 Oct 2012 10:42:14 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: coreutils@gnu.org
Subject: [PATCH] maint: avoid warning from gcc's -Wunused-macros
Date: Sun, 07 Oct 2012 10:42:14 +0200
Message-ID: <878vbiy8pl.fsf@rho.meyering.net>
Lines: 43
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 07 Oct 2012 08:42:17 -0000

Building with --enable-gcc-warnings on e.g., Fedora 18,
I would get this:

  src/factor.c:148:0: error: macro "__clz_tab" is not used [-Werror=unused-macros]
  src/factor.c:126:0: error: macro "UHWtype" is not used [-Werror=unused-macros]
  cc1: all warnings being treated as errors
  make[2]: *** [src/factor.o] Error 1

I'm sure there's a cleaner way to fix it, but this is
good enough for now.

>From 231e40a6ba29b892daca1e4a2e464c315874e155 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Sun, 7 Oct 2012 10:37:25 +0200
Subject: [PATCH] maint: avoid warning from gcc's -Wunused-macros

On some systems, -Wunused-macros would warn about two macros:
src/factor.c:148:0: warning: macro "__clz_tab" is not used
src/factor.c:126:0: warning: macro "UHWtype" is not used
* src/factor.c: Add a use to placate gcc.
---
 src/factor.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/factor.c b/src/factor.c
index 1ca5812..5bfbfdc 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -173,6 +173,12 @@ const unsigned char factor_clz_tab[129] =

 #endif

+#if !defined __clz_tab && !defined UHWtype
+/* Without this seemingly useless conditional, gcc -Wunused-macros
+   warns that each of the two tested macros is unused on Fedora 18.
+   FIXME: this is just an ugly band-aid.  Fix it properly.  */
+#endif
+
 enum alg_type { ALG_POLLARD_RHO = 1, ALG_SQUFOF = 2 };

 static enum alg_type alg;
--
1.8.0.rc0.18.gf84667d


From MAILER-DAEMON Mon Oct 08 09:11:17 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLD77-0007ty-L7
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 09:11:17 -0400
Received: from eggs.gnu.org ([208.118.235.92]:44799)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jeff.liu@oracle.com>) id 1TLD6w-0007py-D3
	for coreutils@gnu.org; Mon, 08 Oct 2012 09:11:16 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jeff.liu@oracle.com>) id 1TLD6p-0005rV-B0
	for coreutils@gnu.org; Mon, 08 Oct 2012 09:11:06 -0400
Received: from rcsinet15.oracle.com ([148.87.113.117]:48509)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jeff.liu@oracle.com>) id 1TLD6p-0005qP-42
	for coreutils@gnu.org; Mon, 08 Oct 2012 09:10:59 -0400
Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238])
	by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with
	ESMTP id q98DAuTk004819
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Mon, 8 Oct 2012 13:10:57 GMT
Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156])
	by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id
	q98DAthf021765
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Mon, 8 Oct 2012 13:10:56 GMT
Received: from abhmt102.oracle.com (abhmt102.oracle.com [141.146.116.54])
	by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id
	q98DAt6R010474; Mon, 8 Oct 2012 08:10:55 -0500
Received: from [192.168.1.102] (/114.248.204.213)
	by default (Oracle Beehive Gateway v4.0)
	with ESMTP ; Mon, 08 Oct 2012 06:10:55 -0700
Subject: Re: Supporting reflinked/cow files in coreutils
Mime-Version: 1.0 (Apple Message framework v1084)
Content-Type: text/plain; charset=us-ascii
From: Jeff liu <jeff.liu@oracle.com>
In-Reply-To: <87wqz43n6e.fsf@rho.meyering.net>
Date: Mon, 8 Oct 2012 21:10:44 +0800
Content-Transfer-Encoding: quoted-printable
Message-Id: <26D4FA9A-A9F3-4E44-9305-23866CE83DC5@oracle.com>
References: <20110414143352.GC5231@paradies.suse.de>
	<4DA71296.8040000@draigBrady.com>
	<20110418133444.GE28014@paradies.suse.de>
	<6AA787AA-590D-4C24-A7C0-18A8C17E74BC@oracle.com>
	<20121005151010.GB1041@paradies.suse.de>
	<87wqz43n6e.fsf@rho.meyering.net>
To: Jim Meyering <jim@meyering.net>
X-Mailer: Apple Mail (2.1084)
X-Source-IP: acsinet22.oracle.com [141.146.126.238]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1)
X-Received-From: 148.87.113.117
Cc: Philipp Thomas <pth@suse.de>, bo.li.liu@oracle.com,
	Coreutils <coreutils@gnu.org>, james.l.morris@oracle.com
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 13:11:16 -0000


Hi Philipp,

Thanks for taking a look at this feature, and sorry for my late =
response!

Hi Jim,

Recently, I have discussed with a colleague(Bo Liu CC-ed) who is focus =
on Btrfs development, and we
decided to teach Btrfs aware of reflinked extents per file for du(1) =
purpose. :)


> Philipp Thomas wrote:
>> Jim,
>>=20
>> * Jeff liu (jeff.liu@oracle.com) [20110418 15:54]:
>>=20
>>> FYI, I once implemented a similar patch to teach du(1) to show the =
disk
>>> footprint with reflinked stuff for OCFS2 only.
>>>=20
>>> It is make use of rb-tree to figure out the shared extents and
>>> calculate the exactly used space eventually.
>>> =
http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007293.html
>>> =
http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007288.html
>>> =
http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007287.html
>>>=20
>>> I have not submited the patch set to Coreutils since I guess it is =
hard to
>>> accept by upstream as reflink and FIEMAP_EXTENT_SHARED flag are not =
spread
>>> over the general filesystems.
>>=20
>> in this thread Jeff asked you on your opinions regarding such a patch =
set
>> but somehow you never responded. Could you possibly do so now as I =
would
>> still like something like this to be included upstream.
>=20
> Hi Philipp,
>=20
> Glancing through the patch in the first message,
>=20
>    =
http://oss.oracle.com/pipermail/ocfs2-devel/2010-September/007293.html
>=20
> I have a hard time justifying the addition of so much code for a
> relatively small feature that will be useful only for OCFS2 file =
systems:
>=20
>  coreutils-6.9/src/du.c |  479 =
+++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 473 insertions(+), 6 deletions(-)
>=20
> That's a lot of new always-compiled code that will be used only by a
> very small fraction of users.  And to add insult to injury, it extends
> the ugly tentacles of FIEMAP into du.c.  It was bad enough to have to
> use it in copy.c, and we're all impatient for something better, but
> SEEK_HOLE and SEEK_DATA aren't yet widely available.
>=20
> That's a lot of new code, not even counting these:
>=20
>  * lib/rbtree.c: Source file of rbtree.
>  * lib/rbtree.h: Header file of rbtree.
>  * lib/Makefile.am (libcoreutils_a_SOURCES): Add both of them.
>  ---
>   coreutils-6.9/lib/Makefile.am |    3 +-
>   coreutils-6.9/lib/Makefile.in |    4 +-
>   coreutils-6.9/lib/rbtree.c    |  403 =
+++++++++++++++++++++++++++++++++++++++++
>   coreutils-6.9/lib/rbtree.h    |  143 +++++++++++++++
>   4 files changed, 550 insertions(+), 3 deletions(-)
>=20
> Besides which, there is no reason to add new rbtree.[ch] code
> when there is already plenty of rbtree code in gnulib.
Yes. Originally, I wrote this patch set for a shared-du utility which =
only available on our Oracle Linux release for OCFS2 purpose, so I
didn't make use of rbtree code in gnulib at that time.

>=20
> If it can be made to work cleanly with BTRFS as well, and preferably
> *without* FIEMAP (if possible, though I fear that FIEMAP is the only
> interface we have for now), that would be even better.
I also hate FIEMAP, however, for BTRFS, we have to make it works through =
FIEMAP as well...

>=20
> If you and/or Jeff are motivated enough, a good first step would be to
> post a rebased patch to bug-coreutils, preferably after you've =
switched
> out that rbtree.[ch] for gnulib's code.  I hesitate even to suggest
> that you rebase, because we might end up deciding it's not yet worth
> the cost, but let's hear what others have to say.  Maybe enough people
> use du and are bothered because the space used by their reflinked =
files
> is over-reported.
=20
We can find time to rebase it according to your suggestions if you like.=20=


>=20
> A final question: why use an rbtree rather than a hash table?
> du is already using hash tables at the required scale, and new code
> would be required at all.

Consider scalability, I think we can use hash table, but rbtree is also =
works well, except bitmap.


Thanks,
-Jeff



From MAILER-DAEMON Mon Oct 08 11:30:16 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLFHc-0005UZ-9t
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 11:30:16 -0400
Received: from eggs.gnu.org ([208.118.235.92]:35014)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tw33dl3.dee@gmail.com>) id 1TL98p-0005pG-Uz
	for coreutils@gnu.org; Mon, 08 Oct 2012 04:56:53 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <tw33dl3.dee@gmail.com>) id 1TL98k-0003CJ-5c
	for coreutils@gnu.org; Mon, 08 Oct 2012 04:56:47 -0400
Received: from mail-qc0-f169.google.com ([209.85.216.169]:49777)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tw33dl3.dee@gmail.com>) id 1TL98k-0003Ba-0t
	for coreutils@gnu.org; Mon, 08 Oct 2012 04:56:42 -0400
Received: by mail-qc0-f169.google.com with SMTP id t2so3860042qcq.0
	for <coreutils@gnu.org>; Mon, 08 Oct 2012 01:56:41 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=mime-version:from:date:message-id:subject:to:cc:content-type;
	bh=lpkZcLmI5EeWzvKgtS7FN2v+wV4GPZUmAAGBM8Ke2U8=;
	b=WEzQkIaa37XPLJQ8lTemPM+LDSQORKiNwJwRvdk0gJ9noYvUozijN3H+OTPyXZgrsS
	5HMQxi8kjXfC/WQap5BnHAcCoGV/phReOxGJtTHhrDrJeHNWT3EGJl0C6JuBCgEVTuMU
	mfDV5gP7o3U+tgfhVr0r0EDGDpNW+bvLdeFaFr3WbUSSEQD1xuTL9j2lMSsv7gDYujcv
	ZFtmjbGarctSdIYyDyOU+M8z4baR6eoiGH7A+QqK34H2hRyksVz2PlBTlp4XCtH2ZRvB
	CSNKFrJzIIIAk286n65p/LouM2SINFuR8GSKBRyoj4wVEZHPm16IovnFBjIFNARvlDw+
	2Dzg==
Received: by 10.49.127.115 with SMTP id nf19mr40112307qeb.36.1349686601294;
	Mon, 08 Oct 2012 01:56:41 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.49.132.39 with HTTP; Mon, 8 Oct 2012 01:56:25 -0700 (PDT)
From: Ivan Korotkov <tw33dl3.dee@gmail.com>
Date: Mon, 8 Oct 2012 12:56:25 +0400
Message-ID: <CADiVe7MgEgjzmigb76eR318=9yxxRdzAF4qNFZRa9NM+zRHPpQ@mail.gmail.com>
Subject: Using sendfile in cp since Linux 2.6.33
To: coreutils@gnu.org
Content-Type: multipart/alternative; boundary=047d7b5d58d26da22604cb8866ca
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.85.216.169
X-Mailman-Approved-At: Mon, 08 Oct 2012 11:30:14 -0400
Cc: Vsevolod Krishenko <mstu@sevik.ru>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 08:56:53 -0000

--047d7b5d58d26da22604cb8866ca
Content-Type: text/plain; charset=UTF-8

Hello folks,

this is an enhancement proposal to use sendfile instead of read/write loop
in cp(1) on Linux 2.6.33 and above to speed up copying. WDYT?

-- 
Ivan

--047d7b5d58d26da22604cb8866ca
Content-Type: text/html; charset=UTF-8

Hello folks,<div><br></div><div>this is an enhancement proposal to use sendfile instead of read/write loop in cp(1) on Linux 2.6.33 and above to speed up copying. WDYT?<br clear="all"><div><br></div>-- <br>Ivan<br>
</div>

--047d7b5d58d26da22604cb8866ca--


From MAILER-DAEMON Mon Oct 08 11:41:01 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLFS1-00079b-6F
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 11:41:01 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58290)
	by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <pth@suse.de>)
	id 1TLFRz-000792-NY
	for coreutils@gnu.org; Mon, 08 Oct 2012 11:41:00 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <pth@suse.de>) id 1TLFRy-0004k1-Py
	for coreutils@gnu.org; Mon, 08 Oct 2012 11:40:59 -0400
Received: from cantor2.suse.de ([195.135.220.15]:33315 helo=mx2.suse.de)
	by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <pth@suse.de>)
	id 1TLFRy-0004js-JM
	for coreutils@gnu.org; Mon, 08 Oct 2012 11:40:58 -0400
Received: from relay2.suse.de (unknown [195.135.220.254])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx2.suse.de (Postfix) with ESMTP id ADA84A2FD7;
	Mon,  8 Oct 2012 17:40:54 +0200 (CEST)
Date: Mon, 8 Oct 2012 17:40:54 +0200
From: Philipp Thomas <pth@suse.de>
To: Jim Meyering <jim@meyering.net>
Subject: Re: Some question regarding tail and option "-c"
Message-ID: <20121008154054.GB11900@paradies.suse.de>
References: <20121003155121.325b3f88@viper.suse.cz>
	<20121003171859.GA18334@hysteria.proulx.com>
	<20121003200145.3d5a4cd8@coolcat.suse.cz>
	<877gr7fmw9.fsf@rho.meyering.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
In-Reply-To: <877gr7fmw9.fsf@rho.meyering.net>
X-Operating-System: openSUSE - Kernel Linux 3.4.6-2.10-desktop x86_64
Organization: SUSE LINUX Products GmbH, =?iso-8859-1?Q?G?=
	=?iso-8859-1?Q?F=3A_Jeff_Hawn=2C_Jennifer_Guild=2C_Felix_Imend=F6rffer=2C?=
	=?iso-8859-1?Q?_HRB_21284_=28AG_N=FCrnberg=29?=
User-Agent: Mutt/1.5.21 (2010-09-15)
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6
X-Received-From: 195.135.220.15
Cc: Robert Milasan <rmilasan@suse.com>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 15:41:00 -0000

* Jim Meyering (jim@meyering.net) [20121003 20:09]:

> I can reproduce that by specifying an older version of POSIX:
>=20
>     $ : | _POSIX2_VERSION=3D0 tail -c 10
>     tail: cannot open '10' for reading: No such file or directory

But AFAICS both 1003.2-1992 and 1003.2-2001 define the syntax as being =BB=
-c
number=AB i.e, with a blank between -c and the number but for 1003.2-1992=
 tail
only accepts -c<number> .  With POSIX2_VERSION=3D199209 tail accepts =BB-=
n 10=AB,
so why doesn't -c accept a blank between option and number?

Philipp


From MAILER-DAEMON Mon Oct 08 11:57:58 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLFiQ-0003QF-Mo
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 11:57:58 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49065)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLFiM-0003Oj-Qn
	for coreutils@gnu.org; Mon, 08 Oct 2012 11:57:56 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLFiJ-0001ym-CQ
	for coreutils@gnu.org; Mon, 08 Oct 2012 11:57:54 -0400
Received: from mx1.redhat.com ([209.132.183.28]:60222)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLFiJ-0001yP-3H
	for coreutils@gnu.org; Mon, 08 Oct 2012 11:57:51 -0400
Received: from int-mx11.intmail.prod.int.phx2.redhat.com
	(int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q98FvlWg015103
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Mon, 8 Oct 2012 11:57:47 -0400
Received: from pb-n5110.redhat.com (ovpn-116-94.ams2.redhat.com [10.36.116.94])
	by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q98Fvjbc031611; Mon, 8 Oct 2012 11:57:46 -0400
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
To: coreutils@gnu.org
Subject: [PATCH] factor: fix integer validation and GMP fallback
Date: Mon,  8 Oct 2012 16:57:42 +0100
Message-Id: <1349711862-6296-1-git-send-email-P@draigBrady.com>
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 15:57:57 -0000

In the recent factor rewrite, the GMP code
wasn't actually used; just an error was printed
on integer overflow.  While fixing that it was noticed
that correct input validation wasn't done in all cases
when falling back to the GMP code.

* src/factor.c (print_factors) Fallback to GMP on overflow.
(strto2uintmax): Scan the string for invalid characters,
so that can be detected independently of overflow.
Return an error when an empty string is passed.
---
 src/factor.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/factor.c b/src/factor.c
index 843542b..ce36581 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -2221,14 +2221,15 @@ static strtol_error
 strto2uintmax (uintmax_t *hip, uintmax_t *lop, const char *s)
 {
   unsigned int lo_carry;
-  uintmax_t hi, lo;
+  uintmax_t hi = 0, lo = 0;
 
-  strtol_error err;
+  strtol_error err = LONGINT_INVALID;
 
-  hi = lo = 0;
+  /* Initial scan for invalid digits.  */
+  const char *p = s;
   for (;;)
     {
-      unsigned int c = *s++;
+      unsigned int c = *p++;
       if (c == 0)
         break;
 
@@ -2237,9 +2238,17 @@ strto2uintmax (uintmax_t *hip, uintmax_t *lop, const char *s)
           err = LONGINT_INVALID;
           break;
         }
-      c -= '0';
 
       err = LONGINT_OK;           /* we've seen at least one valid digit */
+    }
+
+  for (;err == LONGINT_OK;)
+    {
+      unsigned int c = *s++;
+      if (c == 0)
+        break;
+
+      c -= '0';
 
       if (UNLIKELY (hi > ~(uintmax_t)0 / 10))
         {
@@ -2342,6 +2351,10 @@ print_factors (const char *input)
         }
       break;
 
+    case LONGINT_OVERFLOW:
+      /* Try GMP.  */
+      break;
+
     default:
       error (0, 0, _("%s is not a valid positive integer"), quote (input));
       return false;
-- 
1.7.6.4



From MAILER-DAEMON Mon Oct 08 12:02:19 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLFmd-00074h-0b
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 12:02:19 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58965)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLFmT-0006Zm-Ci
	for coreutils@gnu.org; Mon, 08 Oct 2012 12:02:16 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLFmH-0003mO-Cg
	for coreutils@gnu.org; Mon, 08 Oct 2012 12:02:06 -0400
Received: from mx1.redhat.com ([209.132.183.28]:59422)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLFmH-0003m9-3C
	for coreutils@gnu.org; Mon, 08 Oct 2012 12:01:57 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q98G1txX011216
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Mon, 8 Oct 2012 12:01:55 -0400
Received: from [10.36.116.94] (ovpn-116-94.ams2.redhat.com [10.36.116.94])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q98G1qX8022581
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO)
	for <coreutils@gnu.org>; Mon, 8 Oct 2012 12:01:55 -0400
Message-ID: <5072F8EE.90006@draigBrady.com>
Date: Mon, 08 Oct 2012 17:01:50 +0100
From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Coreutils <coreutils@gnu.org>
Subject: factor: new GMP slow down?
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 16:02:17 -0000

With the new factor rewrite I've noticed a large slowdown,
with the GMP path.  No time to investigate at present...

$ time ~/git/coreutils/src/factor '44444444444444444444444444444444444444444444444444444444444444444444444444444'
gmp
44444444444444444444444444444444444444444444444444444444444444444444444444444: 2 2 239 4649 5237 21649 42043 513239 29920507 136614668576002329371496447555915740910181043

real	0m0.385s
user	0m0.381s
sys	0m0.002s

$ time factor '44444444444444444444444444444444444444444444444444444444444444444444444444444'
44444444444444444444444444444444444444444444444444444444444444444444444444444: 2 2 239 4649 5237 21649 42043 513239 29920507 136614668576002329371496447555915740910181043

real	0m0.019s
user	0m0.016s
sys	0m0.003s


From MAILER-DAEMON Mon Oct 08 12:25:35 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLG99-0006rL-SQ
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 12:25:35 -0400
Received: from eggs.gnu.org ([208.118.235.92]:38879)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLG97-0006rC-RX
	for coreutils@gnu.org; Mon, 08 Oct 2012 12:25:34 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLG96-0003iE-RW
	for coreutils@gnu.org; Mon, 08 Oct 2012 12:25:33 -0400
Received: from mx.meyering.net ([88.168.87.75]:56442)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLG96-0003fj-Jx
	for coreutils@gnu.org; Mon, 08 Oct 2012 12:25:32 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 082D66014F;
	Mon,  8 Oct 2012 18:25:31 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: [PATCH] factor: fix integer validation and GMP fallback
In-Reply-To: <1349711862-6296-1-git-send-email-P@draigBrady.com>
	(=?iso-8859-1?Q?=22P=E1draig?=
	Brady"'s message of "Mon, 8 Oct 2012 16:57:42 +0100")
References: <1349711862-6296-1-git-send-email-P@draigBrady.com>
Date: Mon, 08 Oct 2012 18:25:31 +0200
Message-ID: <87wqz1q6bo.fsf@rho.meyering.net>
Lines: 15
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 16:25:34 -0000

P=E1draig Brady wrote:
> In the recent factor rewrite, the GMP code
> wasn't actually used; just an error was printed
> on integer overflow.  While fixing that it was noticed
> that correct input validation wasn't done in all cases
> when falling back to the GMP code.
>
> * src/factor.c (print_factors) Fallback to GMP on overflow.
> (strto2uintmax): Scan the string for invalid characters,
> so that can be detected independently of overflow.
> Return an error when an empty string is passed.

Oh, wow.  I'm sure glad you caught that.  Thanks!
I could have sworn there was a test that used GMP when possible.
I'll add one ASAP.


From MAILER-DAEMON Mon Oct 08 13:10:34 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLGqg-0002LN-LA
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 13:10:34 -0400
Received: from eggs.gnu.org ([208.118.235.92]:39420)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLGqd-0002Iv-RM
	for coreutils@gnu.org; Mon, 08 Oct 2012 13:10:32 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLGqb-0005iG-5h
	for coreutils@gnu.org; Mon, 08 Oct 2012 13:10:31 -0400
Received: from mx.meyering.net ([88.168.87.75]:56546)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLGqa-0005he-UT
	for coreutils@gnu.org; Mon, 08 Oct 2012 13:10:29 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 637DC6014F;
	Mon,  8 Oct 2012 19:10:27 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: [PATCH] factor: fix integer validation and GMP fallback
In-Reply-To: <87wqz1q6bo.fsf@rho.meyering.net> (Jim Meyering's message of
	"Mon, 08 Oct 2012 18:25:31 +0200")
References: <1349711862-6296-1-git-send-email-P@draigBrady.com>
	<87wqz1q6bo.fsf@rho.meyering.net>
Date: Mon, 08 Oct 2012 19:10:27 +0200
Message-ID: <87mwzwrit8.fsf@rho.meyering.net>
Lines: 42
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 17:10:33 -0000

Jim Meyering wrote:
> P=E1draig Brady wrote:
>> In the recent factor rewrite, the GMP code
>> wasn't actually used; just an error was printed
>> on integer overflow.  While fixing that it was noticed
>> that correct input validation wasn't done in all cases
>> when falling back to the GMP code.
>>
>> * src/factor.c (print_factors) Fallback to GMP on overflow.
>> (strto2uintmax): Scan the string for invalid characters,
>> so that can be detected independently of overflow.
>> Return an error when an empty string is passed.
>
> Oh, wow.  I'm sure glad you caught that.  Thanks!
> I could have sworn there was a test that used GMP when possible.
> I'll add one ASAP.

Thanks again.
You're welcome to merge this into your patch.
Don't bother with attribution.

diff --git a/tests/misc/factor.pl b/tests/misc/factor.pl
index 38a5037..bfd48d1 100755
--- a/tests/misc/factor.pl
+++ b/tests/misc/factor.pl
@@ -74,6 +74,16 @@ my @Tests =3D
      ['bug-2012-e', '17754345703', {OUT =3D> '94219 188437'}],
     );

+# If we have GMP support, append tests to exercise it.
+system "grep -w HAVE_GMP $ENV{CONFIG_HEADER} > /dev/null" =3D=3D 0
+  and push (@Tests,
+            ['bug-gmp-2_sup_128', '340282366920938463463374607431768211456=
',
+             {OUT =3D> '2 'x127 . '2'}],
+            ['bug-gmp-2_sup_256',
+             '115792089237316195423570985008687907853'
+             . '269984665640564039457584007913129639936',
+             {OUT =3D> '2 'x255 . '2'}]);
+
 # Prepend the command line argument and append a newline to end
 # of each expected 'OUT' string.
 my $t;


From MAILER-DAEMON Mon Oct 08 14:25:10 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLI0s-0000tv-Dm
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 14:25:10 -0400
Received: from eggs.gnu.org ([208.118.235.92]:59391)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TLI0q-0000sa-2B
	for coreutils@gnu.org; Mon, 08 Oct 2012 14:25:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TLI0o-0007Sb-Hb
	for coreutils@gnu.org; Mon, 08 Oct 2012 14:25:07 -0400
Received: from joseki.proulx.com ([216.17.153.58]:36410)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TLI0o-0007Ow-Aw
	for coreutils@gnu.org; Mon, 08 Oct 2012 14:25:06 -0400
Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119])
	by joseki.proulx.com (Postfix) with ESMTP id 7A663211E3;
	Mon,  8 Oct 2012 12:25:04 -0600 (MDT)
Received: by hysteria.proulx.com (Postfix, from userid 1000)
	id 483422DC7B; Mon,  8 Oct 2012 12:25:04 -0600 (MDT)
Date: Mon, 8 Oct 2012 12:25:04 -0600
From: Bob Proulx <bob@proulx.com>
To: Ivan Korotkov <tw33dl3.dee@gmail.com>
Subject: Re: Using sendfile in cp since Linux 2.6.33
Message-ID: <20121008182504.GA3720@hysteria.proulx.com>
Mail-Followup-To: Ivan Korotkov <tw33dl3.dee@gmail.com>, coreutils@gnu.org,
	Vsevolod Krishenko <mstu@sevik.ru>
References: <CADiVe7MgEgjzmigb76eR318=9yxxRdzAF4qNFZRa9NM+zRHPpQ@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <CADiVe7MgEgjzmigb76eR318=9yxxRdzAF4qNFZRa9NM+zRHPpQ@mail.gmail.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 216.17.153.58
Cc: coreutils@gnu.org, Vsevolod Krishenko <mstu@sevik.ru>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 18:25:09 -0000

Ivan Korotkov wrote:
> this is an enhancement proposal to use sendfile instead of read/write loop
> in cp(1) on Linux 2.6.33 and above to speed up copying. WDYT?

The feature is very new.  It think it is too new to use in a coreutils
command like cp.  For anyone who uses a single binary on multiple
different kernels (not that uncommon) this could cause the program to
use the new sendfile(2) api on the older kernel which does not support
it causing pain to those users.  In order to use it the program would
need to dynamically determine at runtime if the feature was available
and only use it then.  That adds too much complexity for a simple
program like cp should be.

Do you have any benchmarks which would show what type of performance
improvement can be expected of a change from read(2)-write(2) to
sendfile(2) between descriptors?  Benchmark data would be most useful
in determining the worth of such feature changes.

Bob



From MAILER-DAEMON Mon Oct 08 16:27:25 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLJvB-0002iR-Be
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 16:27:25 -0400
Received: from eggs.gnu.org ([208.118.235.92]:52739)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TLJrz-0001Ba-V7
	for coreutils@gnu.org; Mon, 08 Oct 2012 16:24:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TLJry-0007nI-S5
	for coreutils@gnu.org; Mon, 08 Oct 2012 16:24:07 -0400
Received: from mx1.redhat.com ([209.132.183.28]:6870)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TLJry-0007nE-Jn
	for coreutils@gnu.org; Mon, 08 Oct 2012 16:24:06 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q98KO5AV010375
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Mon, 8 Oct 2012 16:24:06 -0400
Received: from [10.11.8.67] (vpn-8-67.rdu.redhat.com [10.11.8.67])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q98KO5vs030032
	for <coreutils@gnu.org>; Mon, 8 Oct 2012 16:24:05 -0400
Message-ID: <50733664.5000503@redhat.com>
Date: Mon, 08 Oct 2012 16:24:04 -0400
From: Daniel J Walsh <dwalsh@redhat.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:15.0) Gecko/20120918 Thunderbird/15.0.1
MIME-Version: 1.0
To: coreutils@gnu.org
Subject: Make mv work better with SELinux.
X-Enigmail-Version: 1.4.4
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-Mailman-Approved-At: Mon, 08 Oct 2012 16:27:24 -0400
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 20:24:09 -0000

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

One of if not the most common problem people hit with SELinux is the mv
command, which maintains the file context of the source destination.

mv /home/dwalsh/index.html /var/www/html/

This blows up on everybody and then the users have no idea why.

I was thinking about adding -Z (--restorecon) to mv and having it basically do a
internal restorecon on the destination.

Then we could suggest people who get burnt by this to:

alias mv="mv -Z"

In Fedora 18 we have greatly enhanced matchpathcon, by pre-compiling the
regex, so there should be very little slow down in doing this.

I will work on the patch, if people agree with the idea.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlBzNmQACgkQrlYvE4MpobPLZgCgn6ljo61yzh5U70OuYEsPXEjn
awcAn3s4ecnqqGAGT+J/DMO11MGMEfNs
=qA+g
-----END PGP SIGNATURE-----


From MAILER-DAEMON Mon Oct 08 16:51:21 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLKIL-0001Dt-CL
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 16:51:21 -0400
Received: from eggs.gnu.org ([208.118.235.92]:40094)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLKIK-0001Dn-5Y
	for coreutils@gnu.org; Mon, 08 Oct 2012 16:51:21 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLKIJ-0000kJ-5h
	for coreutils@gnu.org; Mon, 08 Oct 2012 16:51:20 -0400
Received: from mx1.redhat.com ([209.132.183.28]:51199)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLKII-0000k4-Sj
	for coreutils@gnu.org; Mon, 08 Oct 2012 16:51:19 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q98KpHJG020556
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Mon, 8 Oct 2012 16:51:17 -0400
Received: from [10.36.116.28] (ovpn-116-28.ams2.redhat.com [10.36.116.28])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q98KpD8R020690
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Mon, 8 Oct 2012 16:51:16 -0400
Message-ID: <50733CC1.9000506@draigBrady.com>
Date: Mon, 08 Oct 2012 21:51:13 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Daniel J Walsh <dwalsh@redhat.com>
Subject: Re: Make mv work better with SELinux.
References: <50733664.5000503@redhat.com>
In-Reply-To: <50733664.5000503@redhat.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q98KpHJG020556
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 20:51:21 -0000

On 10/08/2012 09:24 PM, Daniel J Walsh wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> One of if not the most common problem people hit with SELinux is the mv
> command, which maintains the file context of the source destination.
>
> mv /home/dwalsh/index.html /var/www/html/
>
> This blows up on everybody and then the users have no idea why.
>
> I was thinking about adding -Z (--restorecon) to mv and having it basic=
ally do a
> internal restorecon on the destination.
>
> Then we could suggest people who get burnt by this to:
>
> alias mv=3D"mv -Z"
>
> In Fedora 18 we have greatly enhanced matchpathcon, by pre-compiling th=
e
> regex, so there should be very little slow down in doing this.
>
> I will work on the patch, if people agree with the idea.

I like the idea.
Now cp and install should behave similarly,
and they already have the -Z option.
So I would suggest that cp, mv and install
support the -Z option without an argument,
which means auto set the context based on the destination.

The caveat with that is that short options
with optional args are very problematic.
So I'd just have the long --context have
an optional arg, while -Z would require an arg.

cheers,
P=E1draig.


From MAILER-DAEMON Mon Oct 08 18:06:06 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLLSg-00056c-LP
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 18:06:06 -0400
Received: from eggs.gnu.org ([208.118.235.92]:52158)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLLSe-00056R-UW
	for coreutils@gnu.org; Mon, 08 Oct 2012 18:06:05 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLLSd-0002Tu-An
	for coreutils@gnu.org; Mon, 08 Oct 2012 18:06:04 -0400
Received: from mx1.redhat.com ([209.132.183.28]:10102)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLLSd-0002Tf-2h
	for coreutils@gnu.org; Mon, 08 Oct 2012 18:06:03 -0400
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q98M61h2010892
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Mon, 8 Oct 2012 18:06:01 -0400
Received: from [10.36.116.28] (ovpn-116-28.ams2.redhat.com [10.36.116.28])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q98M5wZV009858
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Mon, 8 Oct 2012 18:06:00 -0400
Message-ID: <50734E46.8040803@draigBrady.com>
Date: Mon, 08 Oct 2012 23:05:58 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Daniel J Walsh <dwalsh@redhat.com>
Subject: Re: Make mv work better with SELinux.
References: <50733664.5000503@redhat.com> <50733CC1.9000506@draigBrady.com>
In-Reply-To: <50733CC1.9000506@draigBrady.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q98M61h2010892
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 22:06:05 -0000

On 10/08/2012 09:51 PM, P=E1draig Brady wrote:
> On 10/08/2012 09:24 PM, Daniel J Walsh wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> One of if not the most common problem people hit with SELinux is the m=
v
>> command, which maintains the file context of the source destination.
>>
>> mv /home/dwalsh/index.html /var/www/html/
>>
>> This blows up on everybody and then the users have no idea why.
>>
>> I was thinking about adding -Z (--restorecon) to mv and having it basi=
cally do a
>> internal restorecon on the destination.
>>
>> Then we could suggest people who get burnt by this to:
>>
>> alias mv=3D"mv -Z"
>>
>> In Fedora 18 we have greatly enhanced matchpathcon, by pre-compiling t=
he
>> regex, so there should be very little slow down in doing this.
>>
>> I will work on the patch, if people agree with the idea.
>
> I like the idea.
> Now cp and install should behave similarly,
> and they already have the -Z option.
> So I would suggest that cp, mv and install
> support the -Z option without an argument,
> which means auto set the context based on the destination.
>
> The caveat with that is that short options
> with optional args are very problematic.
> So I'd just have the long --context have
> an optional arg, while -Z would require an arg.

Thinking further, --context without an option,
is not too clear to the user. They might think
they were copying the original context rather
than setting a new context.

Pity the long option wasn't called --new-context.
I suppose we could have that as an alias for --context
and deprecate the former?

cheers,
P=E1draig.


From MAILER-DAEMON Mon Oct 08 18:18:27 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLLed-0007O7-2O
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 18:18:27 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37599)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLLea-0007O1-Hc
	for coreutils@gnu.org; Mon, 08 Oct 2012 18:18:25 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLLeZ-0006rk-F5
	for coreutils@gnu.org; Mon, 08 Oct 2012 18:18:24 -0400
Received: from mx1.redhat.com ([209.132.183.28]:4265)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLLeZ-0006re-5t
	for coreutils@gnu.org; Mon, 08 Oct 2012 18:18:23 -0400
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q98MIMgx023433
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Mon, 8 Oct 2012 18:18:22 -0400
Received: from [10.36.116.28] (ovpn-116-28.ams2.redhat.com [10.36.116.28])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q98MIKS6014093
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO)
	for <coreutils@gnu.org>; Mon, 8 Oct 2012 18:18:21 -0400
Message-ID: <5073512C.1020403@draigBrady.com>
Date: Mon, 08 Oct 2012 23:18:20 +0100
From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Coreutils <coreutils@gnu.org>
Subject: Re: factor: new GMP slow down?
References: <5072F8EE.90006@draigBrady.com>
In-Reply-To: <5072F8EE.90006@draigBrady.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q98MIMgx023433
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 22:18:25 -0000

On 10/08/2012 21:46 PM, Torbj=C3=B6rn Granlund wrote:
 > On 10/08/2012 05:01 PM, P=C3=A1draig Brady wrote:
> > With the new factor rewrite I've noticed a large slowdown,
> > with the GMP path.  No time to investigate at present...
> >
> > $ time ~/git/coreutils/src/factor '4444444444444444444444444444444444=
4444444444444444444444444444444444444444444'
> > gmp
> > 444444444444444444444444444444444444444444444444444444444444444444444=
44444444: 2 2 239 4649 5237 21649 42043 513239 29920507 13661466857600232=
9371496447555915740910181043
> >
> > real    0m0.385s
> > user    0m0.381s
> > sys    0m0.002s
> >
> > $ time factor '444444444444444444444444444444444444444444444444444444=
44444444444444444444444'
> > 444444444444444444444444444444444444444444444444444444444444444444444=
44444444: 2 2 239 4649 5237 21649 42043 513239 29920507 13661466857600232=
9371496447555915740910181043
> >
> > real    0m0.019s
> > user    0m0.016s
> > sys    0m0.003s
 >
 > Please try disabling prime proving, using the new -w switch.
 > I feel pretty confident it will then beat the old code.
 >
 > Prime proving sometimes takes a lot of time.  It needs to factor p-1 f=
or
 > each factor p found.  Each factor of p-1 is also proven prime,
 > recursively.
 >
 > One might take a more optimistic path, and rely on probabilitic tests.
 >
 > We have written Quadratic Sieve code that will at some point probably =
be
 > adapted to GNU factor use.  It will make factoring speed much less
 > varying, and furthermore allow practical factoring of much larger
 > numbers.

Yep you're right.
Note -w is not currently exposed in the new GNU version.
Tweaking that manually we have:

$ time ~/git/coreutils/src/factor -w '44444444444444444444444444444444444=
444444444444444444444444444444444444444444'
4444444444444444444444444444444444444444444444444444444444444444444444444=
4444: 2 2 239 4649 5237 21649 42043 513239 29920507 136614668576002329371=
496447555915740910181043

real	0m0.013s
user	0m0.010s
sys	0m0.003s
pb-n5110:primes$ time ~/git/coreutils/src/factor '44444444444444444444444=
444444444444444444444444444444444444444444444444444444'
4444444444444444444444444444444444444444444444444444444444444444444444444=
4444: 2 2 239 4649 5237 21649 42043 513239 29920507 136614668576002329371=
496447555915740910181043

real	0m0.387s
user	0m0.383s
sys	0m0.002s

thanks!
P=C3=A1draig.


From MAILER-DAEMON Mon Oct 08 18:35:47 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLLvP-0002Oc-4E
	for mharc-coreutils@gnu.org; Mon, 08 Oct 2012 18:35:47 -0400
Received: from eggs.gnu.org ([208.118.235.92]:52123)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLLvM-0002Nm-IS
	for coreutils@gnu.org; Mon, 08 Oct 2012 18:35:46 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLLvK-0005Cg-Ep
	for coreutils@gnu.org; Mon, 08 Oct 2012 18:35:44 -0400
Received: from mx1.redhat.com ([209.132.183.28]:31403)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLLvJ-0005Bv-Vh
	for coreutils@gnu.org; Mon, 08 Oct 2012 18:35:42 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q98MZebj031531
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Mon, 8 Oct 2012 18:35:40 -0400
Received: from [10.36.116.28] (ovpn-116-28.ams2.redhat.com [10.36.116.28])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q98MZc9B030514
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Mon, 8 Oct 2012 18:35:39 -0400
Message-ID: <50735536.4030908@draigBrady.com>
Date: Mon, 08 Oct 2012 23:35:34 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: [PATCH] factor: fix integer validation and GMP fallback
References: <1349711862-6296-1-git-send-email-P@draigBrady.com>
	<87wqz1q6bo.fsf@rho.meyering.net> <87mwzwrit8.fsf@rho.meyering.net>
In-Reply-To: <87mwzwrit8.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q98MZebj031531
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Oct 2012 22:35:46 -0000

On 10/08/2012 06:10 PM, Jim Meyering wrote:
> Jim Meyering wrote:
>> P=E1draig Brady wrote:
>>> In the recent factor rewrite, the GMP code
>>> wasn't actually used; just an error was printed
>>> on integer overflow.  While fixing that it was noticed
>>> that correct input validation wasn't done in all cases
>>> when falling back to the GMP code.
>>>
>>> * src/factor.c (print_factors) Fallback to GMP on overflow.
>>> (strto2uintmax): Scan the string for invalid characters,
>>> so that can be detected independently of overflow.
>>> Return an error when an empty string is passed.
>>
>> Oh, wow.  I'm sure glad you caught that.  Thanks!
>> I could have sworn there was a test that used GMP when possible.
>> I'll add one ASAP.
>
> Thanks again.
> You're welcome to merge this into your patch.
> Don't bother with attribution.
>
> diff --git a/tests/misc/factor.pl b/tests/misc/factor.pl
> index 38a5037..bfd48d1 100755
> --- a/tests/misc/factor.pl
> +++ b/tests/misc/factor.pl
> @@ -74,6 +74,16 @@ my @Tests =3D
>        ['bug-2012-e', '17754345703', {OUT =3D> '94219 188437'}],
>       );
>
> +# If we have GMP support, append tests to exercise it.
> +system "grep -w HAVE_GMP $ENV{CONFIG_HEADER} > /dev/null" =3D=3D 0
> +  and push (@Tests,
> +            ['bug-gmp-2_sup_128', '34028236692093846346337460743176821=
1456',
> +             {OUT =3D> '2 'x127 . '2'}],
> +            ['bug-gmp-2_sup_256',
> +             '115792089237316195423570985008687907853'
> +             . '269984665640564039457584007913129639936',
> +             {OUT =3D> '2 'x255 . '2'}]);
> +
>   # Prepend the command line argument and append a newline to end
>   # of each expected 'OUT' string.
>   my $t;
>

Thanks for that.
I also notice that the old factor code
allowed leading spaces and an optional '+'
for input numbers.

I'll tweak to allow those too and add a test.

cheers,
P=E1draig.


From MAILER-DAEMON Tue Oct 09 02:50:44 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLTeO-00029b-S0
	for mharc-coreutils@gnu.org; Tue, 09 Oct 2012 02:50:44 -0400
Received: from eggs.gnu.org ([208.118.235.92]:50054)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLTeM-00029M-JX
	for coreutils@gnu.org; Tue, 09 Oct 2012 02:50:43 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLTeK-0000mT-WD
	for coreutils@gnu.org; Tue, 09 Oct 2012 02:50:42 -0400
Received: from mx.meyering.net ([88.168.87.75]:58433)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLTeK-0000mN-Ou
	for coreutils@gnu.org; Tue, 09 Oct 2012 02:50:40 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id D8C08601EB;
	Tue,  9 Oct 2012 08:50:39 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Philipp Thomas <pth@suse.de>
Subject: Re: Some question regarding tail and option "-c"
In-Reply-To: <20121008154054.GB11900@paradies.suse.de> (Philipp Thomas's
	message of "Mon, 8 Oct 2012 17:40:54 +0200")
References: <20121003155121.325b3f88@viper.suse.cz>
	<20121003171859.GA18334@hysteria.proulx.com>
	<20121003200145.3d5a4cd8@coolcat.suse.cz>
	<877gr7fmw9.fsf@rho.meyering.net>
	<20121008154054.GB11900@paradies.suse.de>
Date: Tue, 09 Oct 2012 08:50:39 +0200
Message-ID: <87sj9op29s.fsf@rho.meyering.net>
Lines: 20
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Robert Milasan <rmilasan@suse.com>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 09 Oct 2012 06:50:43 -0000

Philipp Thomas wrote:

> * Jim Meyering (jim@meyering.net) [20121003 20:09]:
>
>> I can reproduce that by specifying an older version of POSIX:
>>
>>     $ : | _POSIX2_VERSION=3D0 tail -c 10
>>     tail: cannot open '10' for reading: No such file or directory
>
> But AFAICS both 1003.2-1992 and 1003.2-2001 define the syntax as being =
=BB-c
> number=AB i.e, with a blank between -c and the number but for 1003.2-1992=
 tail
> only accepts -c<number> .  With POSIX2_VERSION=3D199209 tail accepts =BB-=
n 10=AB,
> so why doesn't -c accept a blank between option and number?

The behavior of "tail -c N" changed between those two years (1992,2001),
yet the -n option was not recognized in the 1992 version, so it is treated
consistently regardless of _POSIX2_VERSION.  Fortunately for users (less
so for you with your question, and for me taking time to answer it),
-n is not consistent with the obsolescent rules that determine how tail
treats -c and -l.


From MAILER-DAEMON Tue Oct 09 03:05:33 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLTsj-0004iV-BI
	for mharc-coreutils@gnu.org; Tue, 09 Oct 2012 03:05:33 -0400
Received: from eggs.gnu.org ([208.118.235.92]:48877)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLTsc-0004Tt-IX
	for coreutils@gnu.org; Tue, 09 Oct 2012 03:05:32 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLTsZ-0005hi-En
	for coreutils@gnu.org; Tue, 09 Oct 2012 03:05:26 -0400
Received: from mx.meyering.net ([88.168.87.75]:58473)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLTsZ-0005gp-6p
	for coreutils@gnu.org; Tue, 09 Oct 2012 03:05:23 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 7E25D60215;
	Tue,  9 Oct 2012 09:05:22 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Jeff liu <jeff.liu@oracle.com>
Subject: Re: Supporting reflinked/cow files in coreutils
In-Reply-To: <26D4FA9A-A9F3-4E44-9305-23866CE83DC5@oracle.com> (Jeff liu's
	message of "Mon, 8 Oct 2012 21:10:44 +0800")
References: <20110414143352.GC5231@paradies.suse.de>
	<4DA71296.8040000@draigBrady.com>
	<20110418133444.GE28014@paradies.suse.de>
	<6AA787AA-590D-4C24-A7C0-18A8C17E74BC@oracle.com>
	<20121005151010.GB1041@paradies.suse.de>
	<87wqz43n6e.fsf@rho.meyering.net>
	<26D4FA9A-A9F3-4E44-9305-23866CE83DC5@oracle.com>
Date: Tue, 09 Oct 2012 09:05:22 +0200
Message-ID: <87mwzwp1l9.fsf@rho.meyering.net>
Lines: 28
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Philipp Thomas <pth@suse.de>, bo.li.liu@oracle.com,
	Coreutils <coreutils@gnu.org>, james.l.morris@oracle.com
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 09 Oct 2012 07:05:32 -0000

Jeff liu wrote:
> Hi Philipp,
>
> Thanks for taking a look at this feature, and sorry for my late response!
>
> Hi Jim,
>
> Recently, I have discussed with a colleague(Bo Liu CC-ed) who is focus
> on Btrfs development, and we
> decided to teach Btrfs aware of reflinked extents per file for du(1) purpose. :)

Hi Jeff,

When do you expect that support to be in upstream kernels?

...
>> If you and/or Jeff are motivated enough, a good first step would be to
>> post a rebased patch to bug-coreutils, preferably after you've switched
>> out that rbtree.[ch] for gnulib's code.  I hesitate even to suggest
>> that you rebase, because we might end up deciding it's not yet worth
>> the cost, but let's hear what others have to say.  Maybe enough people
>> use du and are bothered because the space used by their reflinked files
>> is over-reported.
>
> We can find time to rebase it according to your suggestions if you like.

Depending on when btrfs support is expected, you may want to wait.
I would want to be able to test against both file system types.


From MAILER-DAEMON Tue Oct 09 06:17:31 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLWsV-0000ht-G8
	for mharc-coreutils@gnu.org; Tue, 09 Oct 2012 06:17:31 -0400
Received: from eggs.gnu.org ([208.118.235.92]:33096)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jeff.liu@oracle.com>) id 1TLWsO-0000g3-I6
	for coreutils@gnu.org; Tue, 09 Oct 2012 06:17:30 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jeff.liu@oracle.com>) id 1TLWsI-0007iJ-N2
	for coreutils@gnu.org; Tue, 09 Oct 2012 06:17:24 -0400
Received: from rcsinet15.oracle.com ([148.87.113.117]:43623)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jeff.liu@oracle.com>) id 1TLWsI-0007iD-GT
	for coreutils@gnu.org; Tue, 09 Oct 2012 06:17:18 -0400
Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93])
	by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with
	ESMTP id q99AHGAs008280
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 9 Oct 2012 10:17:16 GMT
Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156])
	by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id
	q99AHElE000762
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Tue, 9 Oct 2012 10:17:15 GMT
Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58])
	by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id
	q99AHEM4028170; Tue, 9 Oct 2012 05:17:14 -0500
Received: from [192.168.1.101] (/123.119.96.149)
	by default (Oracle Beehive Gateway v4.0)
	with ESMTP ; Tue, 09 Oct 2012 03:17:13 -0700
Message-ID: <5073F980.60909@oracle.com>
Date: Tue, 09 Oct 2012 18:16:32 +0800
From: Jie Liu <jeff.liu@oracle.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:14.0) Gecko/20120714 Thunderbird/14.0
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: Supporting reflinked/cow files in coreutils
References: <20110414143352.GC5231@paradies.suse.de>
	<4DA71296.8040000@draigBrady.com>
	<20110418133444.GE28014@paradies.suse.de>
	<6AA787AA-590D-4C24-A7C0-18A8C17E74BC@oracle.com>
	<20121005151010.GB1041@paradies.suse.de>
	<87wqz43n6e.fsf@rho.meyering.net>
	<26D4FA9A-A9F3-4E44-9305-23866CE83DC5@oracle.com>
	<87mwzwp1l9.fsf@rho.meyering.net>
In-Reply-To: <87mwzwp1l9.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Source-IP: ucsinet21.oracle.com [156.151.31.93]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1)
X-Received-From: 148.87.113.117
Cc: Philipp Thomas <pth@suse.de>, bo.li.liu@oracle.com,
	Coreutils <coreutils@gnu.org>, james.l.morris@oracle.com
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 09 Oct 2012 10:17:30 -0000

On 10/09/12 15:05, Jim Meyering wrote:
> Jeff liu wrote:
>> Hi Philipp,
>>
>> Thanks for taking a look at this feature, and sorry for my late response!
>>
>> Hi Jim,
>>
>> Recently, I have discussed with a colleague(Bo Liu CC-ed) who is focus
>> on Btrfs development, and we
>> decided to teach Btrfs aware of reflinked extents per file for du(1) purpose. :)
Hi Jim,

> Hi Jeff,
>
> When do you expect that support to be in upstream kernels?
It depends on Bo's time as well as whether we can get a quick review
from Btrfs upstream folks or not.
>
> ...
>>> If you and/or Jeff are motivated enough, a good first step would be to
>>> post a rebased patch to bug-coreutils, preferably after you've switched
>>> out that rbtree.[ch] for gnulib's code.  I hesitate even to suggest
>>> that you rebase, because we might end up deciding it's not yet worth
>>> the cost, but let's hear what others have to say.  Maybe enough people
>>> use du and are bothered because the space used by their reflinked files
>>> is over-reported.
>> We can find time to rebase it according to your suggestions if you like.
> Depending on when btrfs support is expected, you may want to wait.
It's better to me.
> I would want to be able to test against both file system types.
Ok, I'll submit a test case ogether with du(1) patches.


Thanks,
-Jeff


From MAILER-DAEMON Tue Oct 09 08:55:11 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLZL5-0007Au-6c
	for mharc-coreutils@gnu.org; Tue, 09 Oct 2012 08:55:11 -0400
Received: from eggs.gnu.org ([208.118.235.92]:52356)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLZKy-00075l-Id
	for coreutils@gnu.org; Tue, 09 Oct 2012 08:55:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLZKt-0000Ih-Nu
	for coreutils@gnu.org; Tue, 09 Oct 2012 08:55:04 -0400
Received: from mx.meyering.net ([88.168.87.75]:59320)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TLZKt-0000IU-Fy
	for coreutils@gnu.org; Tue, 09 Oct 2012 08:54:59 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 690A7600BB;
	Tue,  9 Oct 2012 14:54:58 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: Make mv work better with SELinux.
In-Reply-To: <50733CC1.9000506@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?=
	=?iso-8859-1?Q?g?= Brady"'s message of
	"Mon, 08 Oct 2012 21:51:13 +0100")
References: <50733664.5000503@redhat.com> <50733CC1.9000506@draigBrady.com>
Date: Tue, 09 Oct 2012 14:54:58 +0200
Message-ID: <87626jolel.fsf@rho.meyering.net>
Lines: 54
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Daniel J Walsh <dwalsh@redhat.com>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 09 Oct 2012 12:55:09 -0000

P=E1draig Brady wrote:

> On 10/08/2012 09:24 PM, Daniel J Walsh wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> One of if not the most common problem people hit with SELinux is the mv
>> command, which maintains the file context of the source destination.
>>
>> mv /home/dwalsh/index.html /var/www/html/
>>
>> This blows up on everybody and then the users have no idea why.
>>
>> I was thinking about adding -Z (--restorecon) to mv and having it basica=
lly do a
>> internal restorecon on the destination.
>>
>> Then we could suggest people who get burnt by this to:
>>
>> alias mv=3D"mv -Z"
>>
>> In Fedora 18 we have greatly enhanced matchpathcon, by pre-compiling the
>> regex, so there should be very little slow down in doing this.
>>
>> I will work on the patch, if people agree with the idea.
>
> I like the idea.
> Now cp and install should behave similarly,
> and they already have the -Z option.

Upstream cp does not have -Z.
I agree that this seems like the right time to add it.

> So I would suggest that cp, mv and install
> support the -Z option without an argument,
> which means auto set the context based on the destination.
>
> The caveat with that is that short options
> with optional args are very problematic.
> So I'd just have the long --context have
> an optional arg, while -Z would require an arg.

[in a follow-up]
> Thinking further, --context without an option,
> is not too clear to the user. They might think
> they were copying the original context rather
> than setting a new context.

> Pity the long option wasn't called --new-context.
> I suppose we could have that as an alias for --context
> and deprecate the former?

Sounds reasonable.
Adjust the other --context=3DCTX commands, mkdir, mkfifo, mknod
at the same time.


From MAILER-DAEMON Tue Oct 09 09:48:47 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLaAx-0003aE-OT
	for mharc-coreutils@gnu.org; Tue, 09 Oct 2012 09:48:47 -0400
Received: from eggs.gnu.org ([208.118.235.92]:38363)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TLaAq-0003Mo-MV
	for coreutils@gnu.org; Tue, 09 Oct 2012 09:48:46 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TLaAj-0001mI-Nc
	for coreutils@gnu.org; Tue, 09 Oct 2012 09:48:40 -0400
Received: from mx1.redhat.com ([209.132.183.28]:48119)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TLaAj-0001lK-ES
	for coreutils@gnu.org; Tue, 09 Oct 2012 09:48:33 -0400
Received: from int-mx01.intmail.prod.int.phx2.redhat.com
	(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q99DmUdk032560
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 9 Oct 2012 09:48:30 -0400
Received: from [10.16.60.53] (redsox.boston.devel.redhat.com [10.16.60.53])
	by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q99DmTdH014460; Tue, 9 Oct 2012 09:48:30 -0400
Message-ID: <50742B2D.9070504@redhat.com>
Date: Tue, 09 Oct 2012 09:48:29 -0400
From: Daniel J Walsh <dwalsh@redhat.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:15.0) Gecko/20120918 Thunderbird/15.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: Make mv work better with SELinux.
References: <50733664.5000503@redhat.com> <50733CC1.9000506@draigBrady.com>
	<87626jolel.fsf@rho.meyering.net>
In-Reply-To: <87626jolel.fsf@rho.meyering.net>
X-Enigmail-Version: 1.4.4
Content-Type: text/plain; charset=ISO-8859-1
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q99DmUdk032560
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 09 Oct 2012 13:48:46 -0000

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/09/2012 08:54 AM, Jim Meyering wrote:
> P=E1draig Brady wrote:
>=20
>> On 10/08/2012 09:24 PM, Daniel J Walsh wrote:
>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>>>=20
>>> One of if not the most common problem people hit with SELinux is the
>>> mv command, which maintains the file context of the source
>>> destination.
>>>=20
>>> mv /home/dwalsh/index.html /var/www/html/
>>>=20
>>> This blows up on everybody and then the users have no idea why.
>>>=20
>>> I was thinking about adding -Z (--restorecon) to mv and having it
>>> basically do a internal restorecon on the destination.
>>>=20
>>> Then we could suggest people who get burnt by this to:
>>>=20
>>> alias mv=3D"mv -Z"
>>>=20
>>> In Fedora 18 we have greatly enhanced matchpathcon, by pre-compiling
>>> the regex, so there should be very little slow down in doing this.
>>>=20
>>> I will work on the patch, if people agree with the idea.
>>=20
>> I like the idea. Now cp and install should behave similarly, and they
>> already have the -Z option.
>=20
> Upstream cp does not have -Z. I agree that this seems like the right ti=
me
> to add it.
>=20
>> So I would suggest that cp, mv and install support the -Z option witho=
ut
>> an argument, which means auto set the context based on the destination.
>>=20
>> The caveat with that is that short options with optional args are very
>> problematic. So I'd just have the long --context have an optional arg,
>> while -Z would require an arg.
>=20
> [in a follow-up]
>> Thinking further, --context without an option, is not too clear to the
>> user. They might think they were copying the original context rather t=
han
>> setting a new context.
>=20
>> Pity the long option wasn't called --new-context. I suppose we could h=
ave
>> that as an alias for --context and deprecate the former?
>=20
> Sounds reasonable. Adjust the other --context=3DCTX commands, mkdir, mk=
fifo,
> mknod at the same time.
>=20

The sad thing is I would bet that no one ever uses any of these options.
Since they all involve people understanding what the default labeling sho=
uld
be.  Allowing users to just say when I create a new file, make sure the t=
ool
does the right thing as far as labeling, would be a huge advance.  I real=
ly do
not care what option you guys choose to use.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlB0Ky0ACgkQrlYvE4MpobN/2QCgld4aXuw/jme30u8x5GXQSuTw
avYAn2FXPsN6yXEgWmeFc30W7KUQQPeg
=3DGKaL
-----END PGP SIGNATURE-----


From MAILER-DAEMON Tue Oct 09 10:41:45 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TLb0D-0008Fh-RI
	for mharc-coreutils@gnu.org; Tue, 09 Oct 2012 10:41:45 -0400
Received: from eggs.gnu.org ([208.118.235.92]:57353)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLb06-0008Eu-5Z
	for coreutils@gnu.org; Tue, 09 Oct 2012 10:41:43 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLazz-0000mf-8e
	for coreutils@gnu.org; Tue, 09 Oct 2012 10:41:38 -0400
Received: from mx1.redhat.com ([209.132.183.28]:13822)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TLazy-0000jt-V1
	for coreutils@gnu.org; Tue, 09 Oct 2012 10:41:31 -0400
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q99EfTWb021768
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 9 Oct 2012 10:41:29 -0400
Received: from [10.36.116.82] (ovpn-116-82.ams2.redhat.com [10.36.116.82])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q99EfQsU028124
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Tue, 9 Oct 2012 10:41:28 -0400
Message-ID: <50743795.7070101@draigBrady.com>
Date: Tue, 09 Oct 2012 15:41:25 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Daniel J Walsh <dwalsh@redhat.com>
Subject: Re: Make mv work better with SELinux.
References: <50733664.5000503@redhat.com> <50733CC1.9000506@draigBrady.com>
	<87626jolel.fsf@rho.meyering.net> <50742B2D.9070504@redhat.com>
In-Reply-To: <50742B2D.9070504@redhat.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q99EfTWb021768
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 09 Oct 2012 14:41:44 -0000

On 10/09/2012 02:48 PM, Daniel J Walsh wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 10/09/2012 08:54 AM, Jim Meyering wrote:
>> P=E1draig Brady wrote:
>>
>>> On 10/08/2012 09:24 PM, Daniel J Walsh wrote:
>>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>>>>
>>>> One of if not the most common problem people hit with SELinux is the
>>>> mv command, which maintains the file context of the source
>>>> destination.
>>>>
>>>> mv /home/dwalsh/index.html /var/www/html/
>>>>
>>>> This blows up on everybody and then the users have no idea why.
>>>>
>>>> I was thinking about adding -Z (--restorecon) to mv and having it
>>>> basically do a internal restorecon on the destination.
>>>>
>>>> Then we could suggest people who get burnt by this to:
>>>>
>>>> alias mv=3D"mv -Z"
>>>>
>>>> In Fedora 18 we have greatly enhanced matchpathcon, by pre-compiling
>>>> the regex, so there should be very little slow down in doing this.
>>>>
>>>> I will work on the patch, if people agree with the idea.
>>>
>>> I like the idea. Now cp and install should behave similarly, and they
>>> already have the -Z option.
>>
>> Upstream cp does not have -Z. I agree that this seems like the right t=
ime
>> to add it.
>>
>>> So I would suggest that cp, mv and install support the -Z option with=
out
>>> an argument, which means auto set the context based on the destinatio=
n.
>>>
>>> The caveat with that is that short options with optional args are ver=
y
>>> problematic. So I'd just have the long --context have an optional arg=
,
>>> while -Z would require an arg.
>>
>> [in a follow-up]
>>> Thinking further, --context without an option, is not too clear to th=
e
>>> user. They might think they were copying the original context rather =
than
>>> setting a new context.
>>
>>> Pity the long option wasn't called --new-context. I suppose we could =
have
>>> that as an alias for --context and deprecate the former?
>>
>> Sounds reasonable. Adjust the other --context=3DCTX commands, mkdir, m=
kfifo,
>> mknod at the same time.
>>
>
> The sad thing is I would bet that no one ever uses any of these options.
> Since they all involve people understanding what the default labeling s=
hould
> be.

http://searchco.de/?q=3D/cp.*Z/%20ext:sh&cs=3Dtrue concurs

> Allowing users to just say when I create a new file, make sure the tool
> does the right thing as far as labeling, would be a huge advance.  I re=
ally do
> not care what option you guys choose to use.

Cool. So moving all tools to supporting --new-context is a plan.

For my own reference, I was wondering how easy it is
to specify the common operation of copying files,
maintaining metadata, but set SELinux labels with restorecon.
To do that you would need:

   cp -a --no-preserve=3Dcontext --new-context

Not the cleanest, but not too bad.
Also -a implies --preserve=3Dxattrs which copies SELinux labels,
and so they would be copied before being reset with --new-context.

cheers,
P=E1draig.


From MAILER-DAEMON Wed Oct 10 14:02:33 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TM0c5-0002FH-Kp
	for mharc-coreutils@gnu.org; Wed, 10 Oct 2012 14:02:33 -0400
Received: from eggs.gnu.org ([208.118.235.92]:35935)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bnorling@silverspringnet.com>) id 1TM0ZP-0008Mg-Ey
	for coreutils@gnu.org; Wed, 10 Oct 2012 13:59:49 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <bnorling@silverspringnet.com>) id 1TM0ZJ-0000fq-LQ
	for coreutils@gnu.org; Wed, 10 Oct 2012 13:59:47 -0400
Received: from it-ipcorp-01.silverspringnet.com ([74.121.22.25]:38101)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bnorling@silverspringnet.com>) id 1TM0ZJ-0000fd-F8
	for coreutils@gnu.org; Wed, 10 Oct 2012 13:59:41 -0400
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: Ap0EAFC2dVAKOQxz/2dsb2JhbABEgku9boIiBS1eAQwJFVYmAQQbv2yRB2ADm3CNGYIX
X-IronPort-AV: E=Sophos;i="4.80,566,1344236400"; d="scan'208,217";a="14974512"
Received: from unknown (HELO SFO-EXCA-01.silverspringnet.com) ([10.57.12.115])
	by it-ipcorp-01.silverspringnet.com with ESMTP/TLS/AES128-SHA;
	10 Oct 2012 10:59:38 -0700
Received: from SFO-EXMB-01.silverspringnet.com ([fe80::fdb4:fa8c:9a07:be02])
	by SFO-EXCA-01.silverspringnet.com ([::1]) with mapi id 14.01.0355.002;
	Wed, 10 Oct 2012 10:59:38 -0700
From: Brad Norling <bnorling@silverspringnet.com>
To: "coreutils@gnu.org" <coreutils@gnu.org>
Subject: Problem the TEE command
Thread-Topic: Problem the TEE command
Thread-Index: Ac2nEI+itFWssplfRH6R9NBkffs8dw==
Date: Wed, 10 Oct 2012 17:59:37 +0000
Message-ID: <59FF87295F47044F9A3BC6A3E73B3C0306E89667@SFO-EXMB-01.silverspringnet.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-originating-ip: [10.57.12.115]
Content-Type: multipart/alternative;
	boundary="_000_59FF87295F47044F9A3BC6A3E73B3C0306E89667SFOEXMB01silver_"
MIME-Version: 1.0
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 74.121.22.25
X-Mailman-Approved-At: Wed, 10 Oct 2012 14:02:32 -0400
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 10 Oct 2012 17:59:49 -0000

--_000_59FF87295F47044F9A3BC6A3E73B3C0306E89667SFOEXMB01silver_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

I'm running the gnu tee command under windows 7.  It doesn't appear to work=
.

For example,  from the cmd screen, I type: [dir | tee "out.txt"],  the outp=
ut appears in the standard output (screen), but 'out.txt' is not created.

Am I doing something wrong?


--_000_59FF87295F47044F9A3BC6A3E73B3C0306E89667SFOEXMB01silver_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
<meta name=3D"Generator" content=3D"Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri","sans-serif";}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal">I&#8217;m running the gnu tee command under windows =
7.&nbsp; It doesn&#8217;t appear to work.<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">For example,&nbsp; from the cmd screen, I type: [dir=
 | tee &#8220;out.txt&#8221;],&nbsp; the output appears in the standard out=
put (screen), but &#8216;out.txt&#8217; is not created.<o:p></o:p></p>
<p class=3D"MsoNormal"><span style=3D"font-family:&quot;Arial&quot;,&quot;s=
ans-serif&quot;"><o:p>&nbsp;</o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-family:&quot;Arial&quot;,&quot;s=
ans-serif&quot;">Am I doing something wrong?<o:p></o:p></span></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body>
</html>

--_000_59FF87295F47044F9A3BC6A3E73B3C0306E89667SFOEXMB01silver_--


From MAILER-DAEMON Wed Oct 10 14:28:08 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TM10q-0007O1-Ss
	for mharc-coreutils@gnu.org; Wed, 10 Oct 2012 14:28:08 -0400
Received: from eggs.gnu.org ([208.118.235.92]:59291)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eblake@redhat.com>) id 1TM10k-0007Kb-96
	for coreutils@gnu.org; Wed, 10 Oct 2012 14:28:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <eblake@redhat.com>) id 1TM10f-0002tT-Af
	for coreutils@gnu.org; Wed, 10 Oct 2012 14:28:02 -0400
Received: from mx1.redhat.com ([209.132.183.28]:26772)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eblake@redhat.com>) id 1TM10f-0002tK-1T
	for coreutils@gnu.org; Wed, 10 Oct 2012 14:27:57 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9AIRuSM024414
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Wed, 10 Oct 2012 14:27:56 -0400
Received: from [10.3.113.23] (ovpn-113-23.phx2.redhat.com [10.3.113.23])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9AIRtgn004535; Wed, 10 Oct 2012 14:27:55 -0400
Message-ID: <5075BE2A.8040407@redhat.com>
Date: Wed, 10 Oct 2012 12:27:54 -0600
From: Eric Blake <eblake@redhat.com>
Organization: Red Hat
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:15.0) Gecko/20120911 Thunderbird/15.0.1
MIME-Version: 1.0
To: Brad Norling <bnorling@silverspringnet.com>
Subject: Re: Problem the TEE command
References: <59FF87295F47044F9A3BC6A3E73B3C0306E89667@SFO-EXMB-01.silverspringnet.com>
In-Reply-To: <59FF87295F47044F9A3BC6A3E73B3C0306E89667@SFO-EXMB-01.silverspringnet.com>
X-Enigmail-Version: 1.4.4
OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature";
	boundary="------------enig94156A063F258E20DDA317BD"
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: "coreutils@gnu.org" <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 10 Oct 2012 18:28:06 -0000

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig94156A063F258E20DDA317BD
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On 10/10/2012 11:59 AM, Brad Norling wrote:
> I'm running the gnu tee command under windows 7.  It doesn't appear to =
work.
>=20
> For example,  from the cmd screen, I type: [dir | tee "out.txt"],  the =
output appears in the standard output (screen), but 'out.txt' is not crea=
ted.
>=20
> Am I doing something wrong?

The tee from cygwin works for me on my Windows box (where tee --version
reports 8.15).  You didn't mention where you got your build of tee, or
what version it is, but this may be a porting problem where you are
better off complaining to the person that pre-built the binary you are
using than here, because we are unable to do anything about a bad port
on this upstream list.  If you aren't already using cygwin, might I
suggest that as a reasonable port of GNU tools to Windows (see cygwin.com=
).

--=20
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


--------------enig94156A063F258E20DDA317BD
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQEcBAEBCAAGBQJQdb4rAAoJEKeha0olJ0Nq21sH/1J7b+TntbZMopWKN5gkHG1+
rs0OTb6D6CEkqG6X7xEndPg6Vl9nfKvf3EjhrNkmb2lBLFoWCzzOsGPj3gWUF59i
BFFSSX4zaRlJ5kFJ3O7q3NbuRLrfAtqSNQIo84bKoVdQ7sjCxAAVBYLcjKOiQku7
a1MPBGoR6Z5WRZG1Uc6fSVdlIGBkfK7z2Qe/aCug8+8c61iiHrjN285mdNHL38WE
aZgJpIa5+ICA+u8SGWETX50zxnyYp8LOlrsl67A2G9JvM787xgBr8u90vVbcnLw1
frSDUfZFNM0nKnMQ7WMAbk3wkqbd1lSKw9Oxb0sunuSuR2tzm53QCqLAA1ifp4g=
=kypC
-----END PGP SIGNATURE-----

--------------enig94156A063F258E20DDA317BD--


From MAILER-DAEMON Wed Oct 10 14:30:49 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TM13R-00009V-KF
	for mharc-coreutils@gnu.org; Wed, 10 Oct 2012 14:30:49 -0400
Received: from eggs.gnu.org ([208.118.235.92]:34763)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bnorling@silverspringnet.com>) id 1TM13O-000097-Cv
	for coreutils@gnu.org; Wed, 10 Oct 2012 14:30:48 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <bnorling@silverspringnet.com>) id 1TM13I-00044M-01
	for coreutils@gnu.org; Wed, 10 Oct 2012 14:30:46 -0400
Received: from it-ipcorp-01.silverspringnet.com ([74.121.22.25]:36789)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bnorling@silverspringnet.com>) id 1TM13H-00040n-QR
	for coreutils@gnu.org; Wed, 10 Oct 2012 14:30:39 -0400
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: Ap4EAHO9dVAKOQxz/2dsb2JhbABBA8A5giABAQEEOj8MBAIBCA0BAwQBAQEKFAkHMhQDAQUIAQEEDgUIv2uLR4J6gkZgA5cBhG+NGYIX
X-IronPort-AV: E=Sophos;i="4.80,566,1344236400"; d="scan'208";a="14975474"
Received: from unknown (HELO SFO-EXCA-02.silverspringnet.com) ([10.57.12.115])
	by it-ipcorp-01.silverspringnet.com with ESMTP/TLS/AES128-SHA;
	10 Oct 2012 11:30:34 -0700
Received: from SFO-EXMB-01.silverspringnet.com ([fe80::fdb4:fa8c:9a07:be02])
	by SFO-EXCA-02.silverspringnet.com ([::1]) with mapi id 14.01.0355.002;
	Wed, 10 Oct 2012 11:30:34 -0700
From: Brad Norling <bnorling@silverspringnet.com>
To: Eric Blake <eblake@redhat.com>
Subject: RE: Problem the TEE command
Thread-Topic: Problem the TEE command
Thread-Index: Ac2nEI+itFWssplfRH6R9NBkffs8dwAPxM0AAA6lR8A=
Date: Wed, 10 Oct 2012 18:30:33 +0000
Message-ID: <59FF87295F47044F9A3BC6A3E73B3C0306E896D3@SFO-EXMB-01.silverspringnet.com>
References: <59FF87295F47044F9A3BC6A3E73B3C0306E89667@SFO-EXMB-01.silverspringnet.com>
	<5075BE2A.8040407@redhat.com>
In-Reply-To: <5075BE2A.8040407@redhat.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-originating-ip: [10.57.12.115]
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 74.121.22.25
Cc: "coreutils@gnu.org" <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 10 Oct 2012 18:30:48 -0000

Ok - thank you.  I think I figured it out.  It works from within documents =
folder, but not under program files.  This is on a company owned laptop, an=
d I think the issue was permissions.

Thanks for the fast response!

Brad


-----Original Message-----
From: Eric Blake [mailto:eblake@redhat.com]=20
Sent: Wednesday, October 10, 2012 11:28 AM
To: Brad Norling
Cc: coreutils@gnu.org
Subject: Re: Problem the TEE command

On 10/10/2012 11:59 AM, Brad Norling wrote:
> I'm running the gnu tee command under windows 7.  It doesn't appear to wo=
rk.
>=20
> For example,  from the cmd screen, I type: [dir | tee "out.txt"],  the ou=
tput appears in the standard output (screen), but 'out.txt' is not created.
>=20
> Am I doing something wrong?

The tee from cygwin works for me on my Windows box (where tee --version rep=
orts 8.15).  You didn't mention where you got your build of tee, or what ve=
rsion it is, but this may be a porting problem where you are better off com=
plaining to the person that pre-built the binary you are using than here, b=
ecause we are unable to do anything about a bad port on this upstream list.=
  If you aren't already using cygwin, might I suggest that as a reasonable =
port of GNU tools to Windows (see cygwin.com).

--=20
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org



From MAILER-DAEMON Sat Oct 13 01:38:31 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TMuQh-000556-CO
	for mharc-coreutils@gnu.org; Sat, 13 Oct 2012 01:38:31 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49705)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <nik@nikolaskallis.com>) id 1TMu5r-00034h-4G
	for coreutils@gnu.org; Sat, 13 Oct 2012 01:17:00 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <nik@nikolaskallis.com>) id 1TMu5p-0006F1-VM
	for coreutils@gnu.org; Sat, 13 Oct 2012 01:16:59 -0400
Received: from 123-243-137-139.static.tpgi.com.au ([123.243.137.139]:59370
	helo=nikolaskallis.com) by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <nik@nikolaskallis.com>) id 1TMu5p-0006EL-Js
	for coreutils@gnu.org; Sat, 13 Oct 2012 01:16:57 -0400
Received: from [10.0.0.2] (unknown [10.0.0.2])
	by nikolaskallis.com (Postfix) with ESMTPS id D628EE0113
	for <coreutils@gnu.org>; Sat, 13 Oct 2012 15:41:44 +1100 (EST)
Message-ID: <5078F108.2070302@nikolaskallis.com>
Date: Sat, 13 Oct 2012 15:41:44 +1100
From: Nikolas Kallis <nik@nikolaskallis.com>
User-Agent: Mozilla/5.0 (X11; Linux i686;
	rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version: 1.0
To: coreutils@gnu.org
Subject: Problem with Coreutils Contribution Guidelines
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 123.243.137.139
X-Mailman-Approved-At: Sat, 13 Oct 2012 01:38:30 -0400
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 13 Oct 2012 05:17:00 -0000


Hello,



There is a problem with the Coreutils Contribution Guidelines:

http://git.savannah.gnu.org/cgit/coreutils.git/tree/HACKING


I got up to 'Your first commit: the quick and dirty way' and executed 
the command 'git format-patch --stdout -1 > DIFF', and got the error 
message "fatal: Not a git repository (or any of the parent directories): 
.git".

It seems I got this error message because I executed the command from my 
home directory, and figured the command needed to be ran inside the 
coreutils/ directory.

Executing such a command is probably common knowledge for people whom 
use Git frequently, however this is only my second instance using it and 
so I didn't know.

The instructions should specify the command needs to be executed from 
the coreutils/ directory, or perhaps its a better idea to make the 
document specify to enter the coreutils/ directory first, as I suspect 
most - if not all commands in the instructions should generally be 
executed inside the coreutils/ directory.
This will help put the instructions in line with implementation.



Regards,

Nikolas Kallis


From MAILER-DAEMON Sat Oct 13 13:59:07 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TN5zO-0008G5-VW
	for mharc-coreutils@gnu.org; Sat, 13 Oct 2012 13:59:06 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49571)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TN5zN-0008Fz-5Y
	for coreutils@gnu.org; Sat, 13 Oct 2012 13:59:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TN5zL-00063p-Uy
	for coreutils@gnu.org; Sat, 13 Oct 2012 13:59:05 -0400
Received: from mx.meyering.net ([88.168.87.75]:45879)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TN5zL-00063l-CO
	for coreutils@gnu.org; Sat, 13 Oct 2012 13:59:03 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 4E0A4600BE;
	Sat, 13 Oct 2012 19:59:02 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Nikolas Kallis <nik@nikolaskallis.com>
Subject: Re: Problem with Coreutils Contribution Guidelines
In-Reply-To: <5078F108.2070302@nikolaskallis.com> (Nikolas Kallis's message of
	"Sat, 13 Oct 2012 15:41:44 +1100")
References: <5078F108.2070302@nikolaskallis.com>
Date: Sat, 13 Oct 2012 19:59:02 +0200
Message-ID: <87zk3qckyh.fsf@rho.meyering.net>
Lines: 59
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 13 Oct 2012 17:59:06 -0000

Nikolas Kallis wrote:
> There is a problem with the Coreutils Contribution Guidelines:
>
> http://git.savannah.gnu.org/cgit/coreutils.git/tree/HACKING
>
> I got up to 'Your first commit: the quick and dirty way' and executed
> the command 'git format-patch --stdout -1 > DIFF', and got the error
> message "fatal: Not a git repository (or any of the parent
> directories): .git".
>
> It seems I got this error message because I executed the command from
> my home directory, and figured the command needed to be ran inside the
> coreutils/ directory.
>
> Executing such a command is probably common knowledge for people whom
> use Git frequently, however this is only my second instance using it
> and so I didn't know.
>
> The instructions should specify the command needs to be executed from
> the coreutils/ directory, or perhaps its a better idea to make the
> document specify to enter the coreutils/ directory first, as I suspect
> most - if not all commands in the instructions should generally be
> executed inside the coreutils/ directory.
> This will help put the instructions in line with implementation.

Thanks.
I've added the one-line summary and the "ChangeLog entry"
as the body of the git commit log message for you.
Normally I would require a contributor to do that, but since
you're new to this business, you get this one for free.

For your info, I would have preferred it if you had
sent me the following (the output of that git format-patch
command you mention above):

>From aca3d5ebc62265401e11a53fe754fcad7f50ce25 Mon Sep 17 00:00:00 2001
From: Nikolas Kallis <nik@nikolaskallis.com>
Date: Sat, 13 Oct 2012 19:52:33 +0200
Subject: [PATCH] doc: improve HACKING guidelines

* HACKING: Add "cd coreutils" after the git clone command.
---
 HACKING | 1 +
 1 file changed, 1 insertion(+)

diff --git a/HACKING b/HACKING
index f8d3a9b..de8cd7b 100644
--- a/HACKING
+++ b/HACKING
@@ -21,6 +21,7 @@ Base any changes you make on the latest upstream sources.
 You can get a copy of the latest with this command:

     git clone git://git.sv.gnu.org/coreutils
+    cd coreutils

 That downloads the entire repository, including revision control history
 dating back to 1991.  The repository (the part you download, and which
--
1.8.0.rc2


From MAILER-DAEMON Sun Oct 14 22:47:17 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TNai5-0006I4-7q
	for mharc-coreutils@gnu.org; Sun, 14 Oct 2012 22:47:17 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37460)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TNXSI-0001tz-DP
	for coreutils@gnu.org; Sun, 14 Oct 2012 19:18:47 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TNXSG-000450-Qq
	for coreutils@gnu.org; Sun, 14 Oct 2012 19:18:46 -0400
Received: from bart.planet-work.net ([79.99.164.26]:40811)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TNXSG-00041U-CD
	for coreutils@gnu.org; Sun, 14 Oct 2012 19:18:44 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
	d=aebs-tech.com; s=dkim; 
	h=Content-Type:Subject:To:MIME-Version:From:Date:Message-ID;
	bh=CO2YYWgf04HjWb+hlskW4+xLnpXWT/Dq+kSyrmtYeEM=; 
	b=ym1h9RQN5vC8tTarK7E8Dbm43Rvp+S3el+SkaSIUN0ik6MZJyPyHlNGdCqDUohpLQIfqPGvIOeuMDS5GDlO4FDPvGDpQnNS/uBsOJmBJ1dgoA92G5fQgtbHQJRfT71/hhY2r/980O1FvczXpD/bHLNHykGOwRPjFtafHDfn369s=;
Received: from [41.221.22.157] (helo=[10.234.34.25])
	by bart.planet-work.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)
	(Exim 4.72) (envelope-from <tlepaul@aebs-tech.com>)
	id 1TNXS1-0004x1-0d
	for coreutils@gnu.org; Mon, 15 Oct 2012 01:18:29 +0200
Message-ID: <507B4842.3020408@aebs-tech.com>
Date: Mon, 15 Oct 2012 00:18:26 +0100
From: Thibault LE PAUL <tlepaul@aebs-tech.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:10.0.7) Gecko/20120922 Icedove/10.0.7
MIME-Version: 1.0
To: coreutils@gnu.org
Subject: [head] wished an option to continue consuming the input after the
	specified number of lines has been read
Content-Type: multipart/alternative;
	boundary="------------050909030407090304060009"
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 79.99.164.26
X-Mailman-Approved-At: Sun, 14 Oct 2012 22:47:15 -0400
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 14 Oct 2012 23:18:47 -0000

This is a multi-part message in MIME format.
--------------050909030407090304060009
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hello

As far as I know, when the specified number of lines has been read, the 
'head' process stops, and a signal is sent to the anterior process in 
the pipe. I think this behavior is not always the best. I suggest to add 
an option to say head to continue reading the input until EOF.

Regards
-- 

Thibault Le Paul
Directeur Technique
tlepaul@aebs-tech.com

10, Lotissement EL OMRANIA
Dely Brahim. Alger. Algérie
Tél: +213 (0) 21 91 74 11
Fax: +213 (0) 21 91 95 30
Mob: +213 (0) 555 052 487
Web: www.aebs-tech.com


--------------050909030407090304060009
Content-Type: multipart/related;
 boundary="------------070404090705080607040901"


--------------070404090705080607040901
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello<br>
    <br>
    As far as I know, when the specified number of lines has been read,
    the 'head' process stops, and a signal is sent to the anterior
    process in the pipe. I think this behavior is not always the best. I
    suggest to add an option to say head to continue reading the input
    until EOF.<br>
    <br>
    Regards<br>
    <div class="moz-signature">-- <br>
      <font face="Arial,Lucida Sans,Gill Sans">
        <img src="cid:part1.01090900.02020607@aebs-tech.com"
          name="images1" height="60" hspace="5" align="left" border="0"
          vspace="3">
        <small><br>
          Thibault Le Paul<br>
          Directeur Technique<br>
          <a class="moz-txt-link-freetext"
            href="mailto:tlepaul@aebs-tech.com">tlepaul@aebs-tech.com</a></small></font>
      <p><font face="Arial,Lucida Sans,Gill Sans"><small>
            10, Lotissement EL OMRANIA<br>
            Dely Brahim. Alger. Alg&eacute;rie<br>
            T&eacute;l: +213 (0) 21 91 74 11<br>
            Fax: +213 (0) 21 91 95 30<br>
            Mob: +213 (0) 555 052 487<br>
            Web: <a class="moz-txt-link-freetext"
              href="http://www.aebs-tech.com">www.aebs-tech.com</a>
          </small>
        </font></p>
    </div>
  </body>
</html>

--------------070404090705080607040901
Content-Type: image/png;
 name="images1"
Content-Transfer-Encoding: base64
Content-ID: <part1.01090900.02020607@aebs-tech.com>
Content-Disposition: inline;
 filename="images1"

iVBORw0KGgoAAAANSUhEUgAAAOsAAABTCAIAAADx8WeaAAAAA3NCSVQICAjb4U/gAAAAGXRF
WHRTb2Z0d2FyZQBnbm9tZS1zY3JlZW5zaG907wO/PgAAGKxJREFUeJztnXlAVOX6x5+ZObPC
sCmyiYAirqhlAorlXrkjenPJq5KlXq9mVrdr9jNNM/V23XIpEwPTtDK3StTcEjVc7jVRRJAd
ZBEEZmE2Zvv9MTgMM+eced+ZMxDd+fx15pznvO878J3nvMvzPodlNBrBjZt2C7utG+DGjVO4
FeymfeNWsJv2jVvBbto3bgW7ad+4FeymfeNWsJv2jVvBbto3bgW7ad8Qbd2ANkOpvWU60Kh+
s71KEKEcbhcA4LKDuZzgVm0ZQKOhskH5nbdwPocjbuWq2x3/Ewo2GOVqXa5G85tOW6TT5jcq
f8YtgcP35RBD+MLRBLsLn9ebT/R0RTvN8NhBXG7fikovD58tfp7LXVpXe4f1Z42LMBjlysab
GvU1tTpNp7qBcgubAII/vulYKSdUEtBIWpqUangAAAY+8Lzm8oTDhfw416lZpjxWXz2VK4zx
67Bf4OLfTPvlz6Zgrb5SoT6rUhyld7QmsfL4MRxOFx63L5cTzOUEG3QyXc0Z3eM0ffl+lLqM
XiIj398g9DX49OB1mCUWTWLoSzQjUaRKa5LYBHj7HfUSJTJe/p+AP4+CpeoTStlXjcqfqAw4
/ACBcBZXMJRP9BEQPSwvGVTlmoJP9eXbjTonWiAOZwdNF0asZBNeTpRiTWXNhEbFKQDwCzwq
FrhFbI1rFXzlAtLj2y7Pj4qluqTVV0oVe1Wy1QYK8RGCWKHnDJFgrJVqTRh0Mk1psu7BO4y0
EwBYBPCePcvzfxHrrvRLlH8og072pP5TMCgBwNtnoYDbg2VjYwTKfyILWOYjW/r27+HTwRur
qXa5dumW+djwtFL20wYa2SyrM2YbVnMLm9sc//xA+upcqOArF24seXsDI0VlZp6wPanVV0pl
/1JIt5HewuEHiMQrxMLpXE4QVbGayu+1d6c75Xcp4D37PT/oL4jGxfllk6cuZb4RaPTv3X3B
G38ZOjLGmUJOn7x06fKt3+/lVlfXMtUwM/Hxz4x8PmbazLGkV12o4NnT37mXU8BIUVYK1uor
pPJPFRJy7fLFc73ES0S852gK1Ksfqe8uNtRQdjmcB13Eh1NPbtya4rqWoPDSiLh/bVuBe5ek
Vpry1bG0X666QrhW9O/fc92aJWFdO1udd9WKxuHUk0zJFwCK88tMBwaj/IlkeUVZiK182QR4
+LwVHFoe2CGVXr6NNWdUl0NdKl8AaLz9ik56HcXy4cMSl7YEhbOXrr/31kasW9JOXho7flHq
wZOtIF8AyMzMmTH7H/fu5Fqdd5WC9x0gee47TFlJBQBIFPvLy71ItevVcXtIiKyjz1a7qw+q
3NWam2Nd0XOwRX17LopZXkGpq1uCwtlL169evIliKamVvrd80/sfbleqVK5ulSVKhWrB4jVW
InaJgg+lnKx5Us9ggVz+44qqOGnNPNvhmsj77cCgCl/PN9ksO8tXBp1MeTNBl7+WwYbRY1Q+
bKw8YtfsXk5+KzQGhc3b7E8jSmqlSUkrz17MaIX22KJUqFav3Wl5xiUKTvmaSQcMAJ2CJmvV
1qN1gWhiQOccf9/NNGM1MwadTHl9nL7mJLMNs0tjwXZ6gyvnmZmuYYTCkvLigjIaA5N8C0vK
W61JthQUlP1w+LT5I/MKPpRysrqOSQcMAE+ejLH8yCbAt9PxgE4/kk6Q2WKSr1F6jdlWoWCU
XjPoZDQGDx78URywibLiCpqrK1dsbVv5mjh0JM18zLyCGXfAAGA5XyIUzwsOknmJEhDvNWjb
TL5NDVA8oLn6MK/th3GWsEjnjQEA4Mtdh6/dvNOajaGioKCspKjph8RwZM/hVOYdMACUl/oE
BgKbAG+/4+jaNaG8gS1fFheILquJwHGET9MsqUEn09ffbCzaZajB/n3qaq8R3pQrMpn38nAL
bBOK88u+OtjafTAayh89DosIAcZ98Ff7mXfAAFBdLeQKY/wDc7Dlm/UWlnxZXOD33ioaKRX0
XGOWLwCwCS+u/2iPmOOCgUdZXKwm0CGplbriB+8Kdu/8RqVUt3UrmsnNKTQdMKngw6knXPT/
yM726dTpPGKv14ymLFlfYmcgZQknZJ5opJQX8RZNYAM3MFEQw9jY697vOUwVxRQGNskKV3F+
2dlLSHPbrYa8QWE6YEzBklrJZ7u/RbcX8fgiHh/R+PK1EsLeZJkV+obsxrtvoNtzu60WDUhB
CcohfGK43VZjNYaKmzfuMlKOq/nl7NW2boI1zz0XbTpgrB+c/Pn3Sg3GU2bKuOG/33mQXeyS
yXyDTqa6swjdnt8/hdd5Hro9p8NQLRMLjr9n0g3ybEmY1LFFM9jeHrxeLSxaDsOu/Ha7qIxu
bgGRtDNXHLirk7/fM9E9goI7AQDL0HTS2NJnVlXWnLlAskfGLiGdA0wHzChYUis9+uNFdHt/
L/HCZa8uSvo/Rmq3RVOabJSi/tE5YW9hyRcAWFyM+EmauJPCEgx5iQS81+bvszwjEE0M6LSZ
5pZ38IMuzFIzI6mVFpXi/QyEIsGH/1wwLmEkivGKOumbSz+5m2W9XEyDyENoGsYBU72I5M+/
w3LAr81N8PbDC6K9ch61H6ZvyEaPlmSJegp6foTVElwIr2jS8yX5ZQo1xh+tZ1QHB2qfOW9y
RKhT+/zu3sXurH+5czWifAHA18974vgXsMrvHhlmPmZAwQ444FmvTwWAyK6hztduiyYbI8ZK
8Mx+ZgPSbWFR7Nb87cp/scrpEq61OsPmdke50dNDiF5LaJi13P+TkYV+OwAkzZzUb2Av+3YW
vDJrPJb9wAHNe64YUHDy7m9xHbDpQOzliX6XVNKAYqaT3tAjB52x/RMsp8zQaXx0GN2Y8I0j
PZ+TW4xVaXQfa1/I5oaRWjqMUCQIj7RxK5RLHOSMHEP+fWmor5Ni2ZuHceC8giW10qM/XUK3
NztgAECeigAAyHlQiGKmyV2PXiYv4u8YLXiKXlWuLyEPTbaF7dmN6lJ+IcYoVijgDoqzntjm
E31R7n1cXYdYy9CY/uhNoqLfwN64t2RnPsSy79030nzs7EjOYQesaJB7+jE8l6ST3kCP+mVx
ges/2oFa1LdnoRuz/CdQXcrKRfpNmhgaR9IT4HPtb2Auzi9Dn6SfPAm180qDpFaKu3Opd/+o
3ds+sN2SxHq68chiBoMFAL5+zeU7pWBnHPCT+sN+PvcAOtLfYkYuV9i10RbuRm8Mu9M8dGMz
yqzlBkk6uj3Hdwjp+fRzeAsEidPOWZ3hCmNQUrHs+OwAYhX+HX1J9yMaWXi7eM6cSp8xZyLW
Lb5+3vEjBmHdYsapXkTybuwpCNNB3ZNy0C/EqqvA3jNXryrXVXyNXiDhjffENOhkyjtJ6P0H
E9yOL5Oef3AfwwGPGe4VElpldVLo8ardG79NOXn+MlLQOgCsXokxg07Dvq+PS2rx+rXO4LiC
i/JLD/yQZt/uKZYOWKHBcJaINFZ+h2XP8kTqRJrQVh1TXvTWl6diVUEEz2FTzBzn5RUjFiLk
8+bNJ/GjnkI7m/C+2P7Nhm2oM8FDBkbTbAjHorqmLilpZauJ2PFexM6tGA4PAJYt/avpQNEg
N2g/AYCgkAL0XkSVvU0fhpI9WO1pfLhOX3uVzfchvaqtufz0qA6r22AJO4BykijzAerYZdFC
hdjmV3DvznsleSXAaorMtAiJNALAjet3z17IQO/+hocGbfj0XcrLNmscdiksKX95wsJxI+NH
kvwqWjQVLDq7ANC5S1BYN+u9nPQ4qOCi/NLzV/+Dbt87vMvEV5pSKDwqvyzgAwAE2zwZaaip
l9Bc1ckfGJR441mDJN1haaJABM/hB79Ceqm+TlpdS/d1zIwZ7jVilLUDvnU9ft2GXAC8jZlU
eAgE69YsYTxrhEqpPvrzhaM/X8C9sVOnDsMGPzt77qTwbkjLBQ72InAd8N/+PtN87NPxR8cq
pUFf78jauutgecfzo3dQXc26jRQOMThGvHQ5Sf9h1+ddHG9ZS8JDg3bvWtXvuT5MFeg81dW1
R06em5y49O8L15QUPrJr74iCHXDAL7w42PyxUbnXgUrBYs+9Lfoq126dx4LlGy+KTaNZ6ruR
YX8acXCM+P0PDtqe37H1r3USpVPte8qUcSP2798w4I8kX0uuXr8zY/a73x86RW/mSC9ix1bU
CRoTlg5Y0SA36JsvRYYT+cWoO99Lix6RrBgBAEDrb+GkguUbLxqURjWAM3HHXkgalXx/PjH5
3K90u+4Qie7RdeGC6c+PZmbo5jqUCvX6TXuBdtkZW8FF+aUXrt6yb/cUKwdcUZ6LtRSHAmJi
kVaACFsq7PuZXbOCR3ShXpPGi15fQC7fL53L7BMd1TUyMmze/EQqR0BKcLC/U7U6zfpNe4EF
r8wkFzF2L2LnZsd7wE7yIIt8W69eep+pKhzGSIAg9gyKfIvzy5QqDdXVBUnw+gKSoAvn5QsA
9x4Wnr2QsXH9HvRAPwAYO3G4h0DgbN3OsXXHgWKKPjGegovyS8//5ngP2BahCKN2mZy8/2fU
td78OSlEl2WeI6Xcji+hGF9LJ/8DCvncf31SPCGBpDvEiHxNKDXqjNtZS97ZOPsvbyNO2fp0
8J422ZHldwZRKtSrVpGPjPEUvGkd3pyrXQccHsZA+ifDk1+dL8QxiC7LRKPKhNHb6Du+luSS
haR1DvRITv6hZ59M20vfHZzKlHwtufewMGnOCkQRv73ydSeDjJ3nblbu1cskP34MBaefy8i4
g/G8JnXAwSF4uzUtycujWlhu7Tcycfwn8qKTPV6SCqO3cQR4M/AFNlnSJo8T7t5zyHbZAgA2
fDz7myOuyvFW+KhyxbufIhqn7t8QHmo/N5JL+elHkiAcjJHcni/wlm3/+cEC25MenuK6ejBP
R3h6GtD1p1CR9yIcmIjgR+9je/cBAIP0vt1OiBGMLMKb4920Cs326OVMUHxWXpH5uIOvcPGi
MtuwSQCQy2DNmtl5BXKHK0Ih43bWlfPXnx9tP6LXp4P3/v0bt/079XgaRiwXs1RUPbE9iarg
9HMZWfnF6JUNjx0wIIY88IAnekMtb5oSjoqsQ19YZhC2d5+mLCTUuUhcgWVI2qjhXq/NP0Dq
enPu99/0aa/aenlYgL+HEGOHBQDU1NXXyDB0fx5NwQDg08F7zYZl815P/CUtPf3qbZLQd9t0
8c1nWhhnZjOW5wVVwXv2fI9V7vL35lNdkjyZJOA3KXhg3DWAyYhlWnovJ6FJouNSsrPzoNn1
kj86vj2YeOiIHkAFAJ/t/hBr5svEsgVrfr2Bmh4KK9AeAMK7hS5Y+uqCpfYj42iQ1EqPfHd6
5x6M9AxUID3B089lYKlneOwAmr9755BhbE7zx+je/xPvtDNRUnZ/8jhhSuq3VD2HVe/PPnSk
qY/l7yV2QL4AsHbj2+jGWIH2TOHTwfuNxTPiYwY4XxSSenAdcGxMdPovdPllQ6NmseGQ6Tgu
VnEvG3WRo75Oahmf345QNP5HLl2/aAllVq5LF8Z/sUeo0jR3AMJDQxyrC3cfeFsxYfwLzqcS
tK/g9HPXcR/fm3bYWXaeOBbeeBpOPXLUmQOHpqg1SDF89/6b/cIYugnmPyAm7WoUlNotLwvc
8/noO/flAC12I0d1Z3gj5x8NL5ytvlTYV/AeJjorVpy7yB4/PtAUXekhhjEjDT+dtntT+0Ou
uaiQ7aDRLgDs2zPjl4t6lZpk7BUXz8BD1gGK8ksfNWcRphyumWEqNN4unp4kg1o7Ck4/dz0L
eTcBOmqN4d//jt+y/ajp46xXT567iOSGZVKyUTbXynnZR9+Qw/F01XtedUa5XHlCIVmp19IF
B146P+7rg1619ZSvoqBfznQd+5OPHT/9K7o96bvSUHj0CCNAHAB6RJI8lOyM5DZvScWqA538
Yt3eL5pmITzEMGUS0rw96fYyjg/qbIYZo9YlC9Fy9a81knfLS7xkNXNo5Hvrevw/lv916w4u
jXzDAhyPp7lzEyNHiYhvHfOQeQ8jSU90T8p0Ana5fTsby14s9rA9SeeDD+87VlyB9yvB4qfT
EBj48sSEMwAwc/ZPt25NRY+0tMTI5eHeYtCUATD27JNrLqpVaSr5ZqPejuXFc6NOp4XkFkoB
7ARJRoQ7OIwDgKOHMfpkXcOsV9oKMV2jY0hqpenIU34mevTqanuSTsH7DjC/mcKKvSl8gCYR
r/v46N+WTJFI6PoSFVU1JGc9u+n9QMcFnj6CLS0yIvQotFWneIHTHGw0AABotHnKxutadbpK
noxiX1U+YMXKnnUSFQCS+4+NIc+2Zpfi/DKs/QdtxSfrPsdNqT10GMlrAil7Ed/sO0a/NY0p
9qbwt21JAAAPMXywIl/Ap+vYPK4mWVfkigdy6oD/GEBXqwwCSQ9QhIOuczejT5iRYj3LUJ6q
b8B7hKl1uQ3qi3XyXVXVU0vLWFXlUbKaOSjy5YsSfQNOFOasqpNgvH2tdz9HAkiK88veXLxW
2UgZvWnLM/1a5DjLvIUXqoqZTKKJ95ZtxE2pPSSOfFxL6YNTvm69XQ8XLxtzcqa88Vr1wLhr
6z6CVasjESfXTHA8m9IcsSQyoQREXND6cFVeBdqnE8dcFQAAXwMcfRBbzWOB0KjJUd4azok7
AgT5hI5KncEClsEo0alvGwxVWjX2PjyuYIhQvMhDMJrHCQKABzl0aVJtoVqTp0JaJzt17NyO
Pd9jyRcAevSOaFGOBC8So6CkvCS/LAxt5UVSKz3z8+XkAydqalATYZkZ8Tx5ShRyBX+z71iN
pFWDbiseGz7a0DF2UOK0qXnbNmesXTe44jGJiKufkDwWOJ69WQSYX9Np1AJRoxXXgFEIBnGE
WlTUKAQjG7RCAKi0uK8GHg9n/IvwRYl8jwSzcM0UFNG9p80KEY8/c/KbWPU6lktcxBdMnDrG
vh01CrV6kutfay7yEIwZN5T0ErmCW9MBW3Ljlv7Gra7BAZE9exqVGrZtn5jqd8UJWaazeWUG
SwUcVZEHgAeA0VOsFws1/GotHwzMLWOzdcDVgEAdxGFFcqK3iLiU73PGmpRUNmpclN3eiiGD
8Dx9WzE98UWqtViSfyauA/b38X5xZBzQvoqMhrMXM6yqq3hsqHgMtMnPreGGzrRVsCWsBjnR
IG/+tj499TylkcfVsgt0BAALtPb20Zi6IoQOuIZurEYDp5EPEvOsUyVAJS9CD77k9+J2LluN
hCltvPkCBZFQOC9pKtVVEgXjOuCkOZNfnZ+I3a6nGMH4zbGz6PZ3bmbZ9hEJ71iWKMqInvRE
kmMKLnLIHZO/QqMxbwMRQz63n3H1tiP1uJjoqK62cZWhEW28F8OWD99fQJOQxXrg74ADdka+
gO+5ZRRDDcEAvC2ojKOvOUk1v5H7kLG4UKYQCfkfb1huez4ikrF0KowwNLb/2MkjaAxaKFhS
K9mJGYaWNAd7PcxFEL6x7OC5bdgAts9QFp98x1FhIQMvFGKWudMnUYVuDn7mj9I5jgjvvH6D
nUjRFgr+cudhrGyqzjtgABCLcfYrA2RnUb4HSxD9GUsU5WR7HIMdMk8Yc4p0v6ekVlJc1Rqr
XOiMHvrcouWUIeovkC0ctD4RYSGpX623m9CtWcH1ddLjpy7TmNry4QcMZJzt1RfpdSZm5DLK
F2pwCC/hoOOsVo+Y5/ba7DEghWq7ciZalrRWY/TQ5zbvonsP2qykhE4dyFN6thoRYSGpKZ+g
5CNsVvDeHYewHHCfruFtFTxFA8ezt/CFR2zf+NapjiWKEg27L+hK96S78dsf4n3wJkYNHUQv
XxPLFs9uhcZQMSSmH6J8waxgBxzwor9Nx24aE/yeaSdyiiMMEcSkEZGrXNoMFgHcXps9R+Sa
VwSpKCjAWMtwHSIhf/G8qVt2fYBiPGHa6ISXh7m6SbYIRYKlC2d8vnctejbYpidu8g68HjCD
Drg/5rvHUFbiOYSXsMdaXeD4xtwNjCcFZBHA7baFCJ/PQdtzfzenDTaiWTF4QJ8VqxZh7br7
aNNyYMGJ03h+zRleGjl48ZJZiGmDzRAAIKmVHjv1K9ZtC5lzwD6YXS4FckAT4R1LxJzQVv2g
LT3IiI5Zoiii2z+5wdMQtQsAxXmlWK6BWUQC3pBn+815bUr/QY6kWP1o4/JBMdHbdx5EzNft
GJ38/caOiU+c9iKudk0QAHDlwo2I0AAAAAPS1GxAgN8wRnvAfbq5cEMYN3AaN3CaviG7sfw7
fcW3GKseT+F0nMgOSuD6DuaIMR8XAJJ6WR+ynQVUkMyOI/1PWhh5CEXdu3eJHdzP+T2FExJH
T0gcfSjlxOX0Ww2KFrF1zc9Cm6QQRtuEEebPT09079YlKio8Lv4Zx/ZjWzTD6FB4XLtF35Bj
aLivk941SjMBwFB/0hQSxPF+Hnh+JhtOx2EAwBaFsj172+3mumlb/ucU7OZPRmvnzHPjhlnc
CnbTvnEr2E37xq1gN+0bt4LdtG/cCnbTvnEr2E375v8BB57uT18PhsoAAAAASUVORK5CYII=
--------------070404090705080607040901--

--------------050909030407090304060009--


From MAILER-DAEMON Sun Oct 14 23:03:20 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TNaxc-0007ao-Sr
	for mharc-coreutils@gnu.org; Sun, 14 Oct 2012 23:03:20 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37315)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TNaxa-0007af-OX
	for coreutils@gnu.org; Sun, 14 Oct 2012 23:03:19 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TNaxZ-0007h9-FG
	for coreutils@gnu.org; Sun, 14 Oct 2012 23:03:18 -0400
Received: from joseki.proulx.com ([216.17.153.58]:47577)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TNaxZ-0007gw-7q
	for coreutils@gnu.org; Sun, 14 Oct 2012 23:03:17 -0400
Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119])
	by joseki.proulx.com (Postfix) with ESMTP id 06A42211DA;
	Sun, 14 Oct 2012 21:03:16 -0600 (MDT)
Received: by hysteria.proulx.com (Postfix, from userid 1000)
	id D981D2DCCF; Sun, 14 Oct 2012 21:03:15 -0600 (MDT)
Date: Sun, 14 Oct 2012 21:03:15 -0600
From: Bob Proulx <bob@proulx.com>
To: Thibault LE PAUL <tlepaul@aebs-tech.com>
Subject: Re: [head] wished an option to continue consuming the input after
	the specified number of lines has been read
Message-ID: <20121015030315.GA14084@hysteria.proulx.com>
Mail-Followup-To: Thibault LE PAUL <tlepaul@aebs-tech.com>, coreutils@gnu.org
References: <507B4842.3020408@aebs-tech.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <507B4842.3020408@aebs-tech.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 216.17.153.58
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 15 Oct 2012 03:03:20 -0000

Thibault LE PAUL wrote:
> As far as I know, when the specified number of lines has been read,
> the 'head' process stops,

That is by design.  Because often people will do things like this:

  #!/bin/sh
  # File trial1
  line1=$(head -n1)
  line2=$(head -n1)
  line3=$(head -n1)
  cat > somefile

And then call it:

  printf "one\ntwo\nthree\nfour\nfive\n" | trial1

and other similar things.  Therefore head needs to avoid draining
input that it isn't going to read.

> and a signal is sent to the anterior process in the pipe.

That depends upon the circumstances.  SIGPIPE is sent to a writer when
the write pipe is closed while still trying to write output.  However
continuing as above there won't be sigpipe sent since later head calls
and the final 'cat' above will consume the rest of the input.  It
isn't head that is sending the signal.

> I think this behavior is not always the best. I suggest to add an
> option to say head to continue reading the input until EOF.

You can always use 'sed' to do this.  Simply have sed discard all
subsequent lines if that is what you wish to do.  For example to do
something similar to head -n2 but to consume all input do this:
  
  sed '3,$d'

So will this:

  awk 'NR<3'

So will this:

  head -n2 ; cat >/dev/null

Since there are already so many existing ways to accomplish this I
don't think there is a need for an option.

Having said all of the above, I can't think of any cases when I would
actually want to do this.  Under what circumstances are you having
problems with SIGPIPE?  I think this is an XY problem[1].  If we can
fix X then we don't need to fix Y.  :-)  Why are you having issues
with SIGPIPE?  Or if not SIGPIPE then what is the original issue you
are trying to solve?

Bob

[1] XY problem:
      http://www.perlmonks.org/index.pl?node_id=542341
      http://mywiki.wooledge.org/XyProblem


From MAILER-DAEMON Mon Oct 15 17:10:29 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TNrvh-0008Me-AX
	for mharc-coreutils@gnu.org; Mon, 15 Oct 2012 17:10:29 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37804)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <lcaph72@gmail.com>) id 1TNrZk-00075c-15
	for coreutils@gnu.org; Mon, 15 Oct 2012 16:47:49 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <lcaph72@gmail.com>) id 1TNrZi-0007hm-JF
	for coreutils@gnu.org; Mon, 15 Oct 2012 16:47:47 -0400
Received: from nm4.bullet.mail.ukl.yahoo.com ([217.146.182.225]:36184)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <lcaph72@gmail.com>) id 1TNrZi-0007fC-A8
	for coreutils@gnu.org; Mon, 15 Oct 2012 16:47:46 -0400
Received: from [217.146.183.214] by nm4.bullet.mail.ukl.yahoo.com with NNFMP;
	15 Oct 2012 20:47:45 -0000
Received: from [217.146.183.206] by tm7.bullet.mail.ukl.yahoo.com with NNFMP;
	15 Oct 2012 20:47:45 -0000
Received: from [127.0.0.1] by omp1004.bt.mail.ukl.yahoo.com with NNFMP;
	15 Oct 2012 20:47:45 -0000
X-Yahoo-Newman-Id: 89739.43709.bm@omp1004.bt.mail.ukl.yahoo.com
Received: (qmail 93626 invoked from network); 15 Oct 2012 20:47:45 -0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024;
	t=1350334064; bh=s9yNseuQMp1hpjM6i2afIqZTILMzyyhDFVaW0xho8KI=;
	h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:Message-ID:From:To:Subject:Date:MIME-Version:Content-Type:X-Priority:X-MSMail-Priority:X-Mailer:X-MimeOLE;
	b=DoOcy+snELnxIaHZ+bD5mwc/pVRm0sFcrnAI/zmUdtFNyTaT7xJDVZRbtdzi1cMPSVp0zbzsM3mP01xTdpR2oJeLpVCgnqsCglMzb1UaWCafHwSzAkQrPx1d8s0zsE5x+n6bZTXSGnYhJ7mCEhbeI+mlwbanju7C7wbxBlZGFnA=
X-Yahoo-Newman-Property: ymail-3
X-YMail-OSG: e3NmwJMVM1mYgLitjt6s53zC8.penRLO9jfe69A5bKYumBz
	vVBQ_mhiKjdy0l4.13Vo_gw4KAkYlj3XVbcL.wXpcT.._wrva1cp57kZ8U9O
	3pXyrOHyqGQayC2Z61hot9dqtzvxxQhuHyajWvHzEWkJ8PlmC0uukbpz7tg5
	HExD4stwjAydpuJDNgsPsl.Khm7hTQyWtfXvdYCRpNYvyADfwkIaKeydI65J
	A3cICK_XSUM2obB8r6IEdyMX9U7OxTXDnuRdimcg5iz2z7SzHK0EgLe2.iGd
	pVH4JqyUmOzRHWbbw2Q9P8soBHdz4yp49da0.gm_327Sscxv9lN1qFLPhQ7b
	47zJ4n_ieLm0alhA2wE34ahB7Tj1mAwzIBpITQHxdzU4haDpUfu859HakKPw
	Pgrb3LwiRcg_7vG3V8eCtWlhWQ62fsRz3CFRcwtTp9flNhPVyArdreZWZYZL
	AXG0EqDhTmi8Xl0KIIGWaGw8I8MWr07HgIrDuUcXvVdLStxzLJhT9vsaFxIh
	_IqkRlc7OKcWLIWkgS9E93A--
X-Yahoo-SMTP: 1ZmwRp6swBBRlpBfVrY5xNg6Hy83a4YjB.ICXzSIzEdiRAnx9xhDVwg-
Received: from msmastermind (lcaph72@86.139.170.55 with login)
	by smtp826.mail.ird.yahoo.com with SMTP; 15 Oct 2012 13:47:44 -0700 PDT
Message-ID: <A8E0CF84B47E4BE4A66BC2E42C260192@msmastermind>
From: "Emanuele Alpi" <lcaph72@gmail.com>
To: <coreutils@gnu.org>
Subject: Coreutils for Windows info
Date: Mon, 15 Oct 2012 21:47:46 +0100
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_000C_01CDAB1E.B6DF2BA0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.5931
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 217.146.182.225
X-Mailman-Approved-At: Mon, 15 Oct 2012 17:10:27 -0400
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 15 Oct 2012 20:47:49 -0000

This is a multi-part message in MIME format.

------=_NextPart_000_000C_01CDAB1E.B6DF2BA0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,
I am not a programmer (just a simple user of some GNU utilities) and I =
would like to know if a more updated package of Coreutils for Windows =
exists with respect to this one which is from 2005: =
http://gnuwin32.sourceforge.net/packages/coreutils.htm
Could you help?

Thank you in anticipation

Best Regards

Emanuele Alpi
------=_NextPart_000_000C_01CDAB1E.B6DF2BA0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.19328">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2 face=3DArial>Hello,</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>I am not a programmer (just a simple =
user of some=20
GNU utilities)&nbsp;and I would like to know if a more updated package =
of=20
Coreutils for Windows exists with respect to this one which is from =
2005: <A=20
href=3D"http://gnuwin32.sourceforge.net/packages/coreutils.htm">http://gn=
uwin32.sourceforge.net/packages/coreutils.htm</A></FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>Could you help?</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Thank you in anticipation</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Best Regards</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Emanuele =
Alpi</FONT></DIV></BODY></HTML>

------=_NextPart_000_000C_01CDAB1E.B6DF2BA0--



From MAILER-DAEMON Mon Oct 15 17:13:39 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TNryl-0000Ka-Qz
	for mharc-coreutils@gnu.org; Mon, 15 Oct 2012 17:13:39 -0400
Received: from eggs.gnu.org ([208.118.235.92]:51125)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eblake@redhat.com>) id 1TNryj-0000JH-GW
	for coreutils@gnu.org; Mon, 15 Oct 2012 17:13:38 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <eblake@redhat.com>) id 1TNryi-0005wh-2b
	for coreutils@gnu.org; Mon, 15 Oct 2012 17:13:37 -0400
Received: from mx1.redhat.com ([209.132.183.28]:9988)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eblake@redhat.com>) id 1TNryh-0005wc-PS
	for coreutils@gnu.org; Mon, 15 Oct 2012 17:13:35 -0400
Received: from int-mx11.intmail.prod.int.phx2.redhat.com
	(int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9FLDYWY009815
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Mon, 15 Oct 2012 17:13:34 -0400
Received: from [10.3.113.93] (ovpn-113-93.phx2.redhat.com [10.3.113.93])
	by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9FLDXKr010409; Mon, 15 Oct 2012 17:13:33 -0400
Message-ID: <507C7C7D.3010208@redhat.com>
Date: Mon, 15 Oct 2012 15:13:33 -0600
From: Eric Blake <eblake@redhat.com>
Organization: Red Hat
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121009 Thunderbird/16.0
MIME-Version: 1.0
To: Emanuele Alpi <lcaph72@gmail.com>
Subject: Re: Coreutils for Windows info
References: <A8E0CF84B47E4BE4A66BC2E42C260192@msmastermind>
In-Reply-To: <A8E0CF84B47E4BE4A66BC2E42C260192@msmastermind>
X-Enigmail-Version: 1.4.5
OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature";
	boundary="------------enigC6C3DACAC01A165D586A9D83"
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 15 Oct 2012 21:13:38 -0000

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigC6C3DACAC01A165D586A9D83
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On 10/15/2012 02:47 PM, Emanuele Alpi wrote:
> Hello,
> I would like to know if a more updated package of Coreutils for Windows=
 exists with respect to this one which is from 2005: http://gnuwin32.sour=
ceforge.net/packages/coreutils.htm

Yes, the cygwin port of coreutils is currently at 8.15 from February of
this year, and I am hoping to bump that up to even newer coreutils when
I can get enough free time to spend on it.  http://cygwin.com

--=20
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


--------------enigC6C3DACAC01A165D586A9D83
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQEcBAEBCAAGBQJQfHx9AAoJEKeha0olJ0NqI0QIAK5pNbzI+sMq+TR1B7mfR3nm
3wQQb7xv7KIFZgeemscpC1JlqH0DIRLFARjDCylKvGoFrXgJ0jgZlUYrE/0vVbzB
XXOXPG6KnrIb9XQm1N62oNk/FZ6thUl8jEMRzUFR+PoPKOzZVq30vhYxPAugYDRW
+9Cmi2Wu6j/Ekb7tiN9Sj7q0ttaeAuZw79KCWUA/mZpjAS4lVGGaxliwUGVtvUps
CHNH5gal5FoemNMsWQZhDnf4YHl3Eaof7TLH8jpdDIDa24acfBZn6CgLAgv0ayMn
TuYrJ8F/y8l0m8ornEJcxPfj+TiAub+GfXlrLKeA1hlPsVvN5pomdoI3OtD1PFY=
=kC8J
-----END PGP SIGNATURE-----

--------------enigC6C3DACAC01A165D586A9D83--


From MAILER-DAEMON Mon Oct 15 23:20:16 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TNxhY-0005lY-KR
	for mharc-coreutils@gnu.org; Mon, 15 Oct 2012 23:20:16 -0400
Received: from eggs.gnu.org ([208.118.235.92]:52457)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rwp@proulx.com>) id 1TNxhW-0005kL-HW
	for coreutils@gnu.org; Mon, 15 Oct 2012 23:20:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <rwp@proulx.com>) id 1TNxhV-000081-FX
	for coreutils@gnu.org; Mon, 15 Oct 2012 23:20:14 -0400
Received: from joseki.proulx.com ([216.17.153.58]:55326)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rwp@proulx.com>) id 1TNxhV-00007v-8u
	for coreutils@gnu.org; Mon, 15 Oct 2012 23:20:13 -0400
Received: from dismay.proulx.com (dismay.proulx.com [172.27.61.4])
	by joseki.proulx.com (Postfix) with ESMTP id A3D88211DF;
	Mon, 15 Oct 2012 21:20:10 -0600 (MDT)
Received: by dismay.proulx.com (Postfix, from userid 1000)
	id 02E3DD20E1B; Mon, 15 Oct 2012 21:20:09 -0600 (MDT)
Date: Mon, 15 Oct 2012 21:20:09 -0600
From: Bob Proulx <bob@proulx.com>
To: Thibault LE PAUL <tlepaul@aebs-tech.com>
Subject: Re: [head] wished an option to continue consuming the input after
	the specified number of lines has been read
Message-ID: <20121016032009.GA15412@dismay.proulx.com>
Mail-Followup-To: Thibault LE PAUL <tlepaul@aebs-tech.com>, coreutils@gnu.org
References: <507B4842.3020408@aebs-tech.com>
	<20121015030315.GA14084@hysteria.proulx.com>
	<507BD518.7000702@aebs-tech.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <507BD518.7000702@aebs-tech.com>
User-Agent: Mutt/1.5.20 (2009-06-14)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 216.17.153.58
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
Reply-To: coreutils@gnu.org
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Oct 2012 03:20:15 -0000

Hello Thibault,

Please keep the mailing list in the CC list so that everyone can
participate and learn from the discussion.  Thanks.

Thibault LE PAUL wrote:
> The problem was with a tee.
> Here is an example :
> 
> rm /tmp/fifo1
> mkfifo /tmp/fifo1
> cat /tmp/fifo1|(head -20;cat >/dev/null)|sed 's/^/head &/' &
> #(cat /tmp/fifo1|sed -e '21,$d' -e 's/^/head &/') &
> #(cat /tmp/fifo1|awk 'FNR<21{print "head "$0}')&
> tee /tmp/fifo1|tail -20|sed 's/^/tail &/'
> 
> It works with cat, I didn't think to it.

You have shown part of what you are trying.  That is good.  But I
don't see a problem with what you are showing.  Please show us both
what you are expecting and also what you are seeing that you think is
a problem.

Using 'head -20' is problematic usage.  I recommend avoiding it.

I tried this:

  $ mkfifo fifo
  $ cat fifo | head -n1 | sed 's/^/head &/' &
  [1] 20056
  $ printf "foo\nfoo\nfoo\n" > fifo
  head foo
  $
  [1]+  Done                    cat fifo | head -n1 | sed 's/^/head &/'
  $

That all seems reasonable to me.  What problem are you seeing?

Bob


From MAILER-DAEMON Tue Oct 16 04:08:25 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TO2CP-0001fQ-Ut
	for mharc-coreutils@gnu.org; Tue, 16 Oct 2012 04:08:25 -0400
Received: from eggs.gnu.org ([208.118.235.92]:59484)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TO2CK-0001d4-R6
	for coreutils@gnu.org; Tue, 16 Oct 2012 04:08:23 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TO2CI-0003b7-8j
	for coreutils@gnu.org; Tue, 16 Oct 2012 04:08:20 -0400
Received: from bart.planet-work.net ([79.99.164.26]:38185)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TO2CH-0003Ra-SF
	for coreutils@gnu.org; Tue, 16 Oct 2012 04:08:18 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
	d=aebs-tech.com; s=dkim; 
	h=Content-Type:In-Reply-To:References:Subject:CC:To:MIME-Version:From:Date:Message-ID;
	bh=WQ+tCeqvoVQYC+t2kUoSA2ZO7gwxTBwA+RfIIm8tajw=; 
	b=AbDlRR+a9d8T5OlGvolwp7gUcHG7/cBWDyXhUYNEU5WsGIH2YLZkErIHyL7OSnqm1qAQcf++u/oigq1Sb4ICgasozwMhg8r/luFQ5qKInZfIzDAppaPRgG1dcQ6g46V3IaHWpVAuw5fQ/oqFWgPVMQ00o9Ps9aRJfc4pfKCgVCM=;
Received: from [41.221.22.157] (helo=[10.234.34.25])
	by bart.planet-work.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)
	(Exim 4.72) (envelope-from <tlepaul@aebs-tech.com>)
	id 1TO2C2-0004ah-8w; Tue, 16 Oct 2012 10:08:03 +0200
Message-ID: <507D15DF.7070703@aebs-tech.com>
Date: Tue, 16 Oct 2012 09:07:59 +0100
From: Thibault LE PAUL <tlepaul@aebs-tech.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:10.0.7) Gecko/20120922 Icedove/10.0.7
MIME-Version: 1.0
To: Bob Proulx <bob@proulx.com>
Subject: Re: [head] wished an option to continue consuming the input after
	the specified number of lines has been read
References: <507B4842.3020408@aebs-tech.com>
	<20121015030315.GA14084@hysteria.proulx.com>
	<507BD518.7000702@aebs-tech.com>
	<20121016032009.GA15412@dismay.proulx.com>
In-Reply-To: <20121016032009.GA15412@dismay.proulx.com>
Content-Type: multipart/alternative;
	boundary="------------020904060208030009070707"
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 79.99.164.26
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Oct 2012 08:08:23 -0000

This is a multi-part message in MIME format.
--------------020904060208030009070707
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Hello Bob.

I wasn't clear enough.
My goal was to do different things on the first lines and the last lines 
of same input, without using storage, thus using piped processes.
Then I used tee, to fork the pipe into two processes.
In my post before, I wanted to show three ways that work, including 
(head; cat) that does exactly the same as what would do head with the 
option I suggested in my initial post.
Opposite to that, my original way that fails :

rm /tmp/fifo1
mkfifo /tmp/fifo1
cat /tmp/fifo1|head -n2|sed 's/^/head&/'&
tee /tmp/fifo1|tail -n2|sed 's/^/tail&/'

That way, the /tmp/fifo1 fifo propagates SIGPIPE ahead to tee as soon as 
head has finished, then tee stops, and tail doesn't read the expected 
last lines, instead just the lines before tee aborts and EOF is read on 
pipe. The effect is observable on large input, like 
/usr/share/mysql/errmsg-utf8.txt
Also tried tee -i to ignore interrupts, but it is not the purpose of 
this option I suppose. No effect in our case.



Thibault Le Paul
Directeur Technique
tlepaul@aebs-tech.com

10, Lotissement EL OMRANIA
Dely Brahim. Alger. Algérie
Tél: +213 (0) 21 91 74 11
Fax: +213 (0) 21 91 95 30
Mob: +213 (0) 555 052 487
Web: www.aebs-tech.com


On 16/10/2012 04:20, Bob Proulx wrote:
> Hello Thibault,
>
> Please keep the mailing list in the CC list so that everyone can
> participate and learn from the discussion.  Thanks.
>
> Thibault LE PAUL wrote:
>> The problem was with a tee.
>> Here is an example :
>>
>> rm /tmp/fifo1
>> mkfifo /tmp/fifo1
>> cat /tmp/fifo1|(head -20;cat>/dev/null)|sed 's/^/head&/'&
>> #(cat /tmp/fifo1|sed -e '21,$d' -e 's/^/head&/')&
>> #(cat /tmp/fifo1|awk 'FNR<21{print "head "$0}')&
>> tee /tmp/fifo1|tail -20|sed 's/^/tail&/'
>>
>> It works with cat, I didn't think to it.
> You have shown part of what you are trying.  That is good.  But I
> don't see a problem with what you are showing.  Please show us both
> what you are expecting and also what you are seeing that you think is
> a problem.
>
> Using 'head -20' is problematic usage.  I recommend avoiding it.
>
> I tried this:
>
>    $ mkfifo fifo
>    $ cat fifo | head -n1 | sed 's/^/head&/'&
>    [1] 20056
>    $ printf "foo\nfoo\nfoo\n">  fifo
>    head foo
>    $
>    [1]+  Done                    cat fifo | head -n1 | sed 's/^/head&/'
>    $
>
> That all seems reasonable to me.  What problem are you seeing?
>
> Bob

--------------020904060208030009070707
Content-Type: multipart/related;
 boundary="------------010905060500030601010003"


--------------010905060500030601010003
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello Bob.<br>
    <br>
    I wasn't clear enough.<br>
    My goal was to do different things on the first lines and the last
    lines of same input, without using storage, thus using piped
    processes.<br>
    Then I used tee, to fork the pipe into two processes.<br>
    In my post before, I wanted to show three ways that work, including
    (head; cat) that does exactly the same as what would do head with
    the option I suggested in my initial post.<br>
    Opposite to that, my original way that fails :<br>
    <pre wrap="">rm /tmp/fifo1
mkfifo /tmp/fifo1
cat /tmp/fifo1|head -n2|sed 's/^/head &amp;/' &amp;
tee /tmp/fifo1|tail -n2|sed 's/^/tail &amp;/'</pre>
    That way, the /tmp/fifo1 fifo propagates SIGPIPE ahead to tee as
    soon as head has finished, then tee stops, and tail doesn't read the
    expected last lines, instead just the lines before tee aborts and
    EOF is read on pipe. The effect is observable on large input, like
    /usr/share/mysql/errmsg-utf8.txt<br>
    Also tried tee -i to ignore interrupts, but it is not the purpose of
    this option I suppose. No effect in our case.<br>
    <br>
    <br>
    <div class="moz-signature"><font face="Arial,Lucida Sans,Gill Sans">
        <img src="cid:part1.02060101.04020207@aebs-tech.com"
          name="images1" height="60" hspace="5" align="left" border="0"
          vspace="3">
        <small><br>
          Thibault Le Paul<br>
          Directeur Technique<br>
          <a class="moz-txt-link-freetext"
            href="mailto:tlepaul@aebs-tech.com">tlepaul@aebs-tech.com</a></small></font>
      <p><font face="Arial,Lucida Sans,Gill Sans"><small>
            10, Lotissement EL OMRANIA<br>
            Dely Brahim. Alger. Alg&eacute;rie<br>
            T&eacute;l: +213 (0) 21 91 74 11<br>
            Fax: +213 (0) 21 91 95 30<br>
            Mob: +213 (0) 555 052 487<br>
            Web: <a class="moz-txt-link-freetext"
              href="http://www.aebs-tech.com">www.aebs-tech.com</a>
          </small>
        </font></p>
    </div>
    <br>
    On 16/10/2012 04:20, Bob Proulx wrote:
    <blockquote cite="mid:20121016032009.GA15412@dismay.proulx.com"
      type="cite">
      <pre wrap="">Hello Thibault,

Please keep the mailing list in the CC list so that everyone can
participate and learn from the discussion.  Thanks.

Thibault LE PAUL wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">The problem was with a tee.
Here is an example :

rm /tmp/fifo1
mkfifo /tmp/fifo1
cat /tmp/fifo1|(head -20;cat &gt;/dev/null)|sed 's/^/head &amp;/' &amp;
#(cat /tmp/fifo1|sed -e '21,$d' -e 's/^/head &amp;/') &amp;
#(cat /tmp/fifo1|awk 'FNR&lt;21{print "head "$0}')&amp;
tee /tmp/fifo1|tail -20|sed 's/^/tail &amp;/'

It works with cat, I didn't think to it.
</pre>
      </blockquote>
      <pre wrap="">
You have shown part of what you are trying.  That is good.  But I
don't see a problem with what you are showing.  Please show us both
what you are expecting and also what you are seeing that you think is
a problem.

Using 'head -20' is problematic usage.  I recommend avoiding it.

I tried this:

  $ mkfifo fifo
  $ cat fifo | head -n1 | sed 's/^/head &amp;/' &amp;
  [1] 20056
  $ printf "foo\nfoo\nfoo\n" &gt; fifo
  head foo
  $
  [1]+  Done                    cat fifo | head -n1 | sed 's/^/head &amp;/'
  $

That all seems reasonable to me.  What problem are you seeing?

Bob
</pre>
    </blockquote>
  </body>
</html>

--------------010905060500030601010003
Content-Type: image/png;
 name="images1"
Content-Transfer-Encoding: base64
Content-ID: <part1.02060101.04020207@aebs-tech.com>
Content-Disposition: inline;
 filename="images1"

iVBORw0KGgoAAAANSUhEUgAAAOsAAABTCAIAAADx8WeaAAAAA3NCSVQICAjb4U/gAAAAGXRF
WHRTb2Z0d2FyZQBnbm9tZS1zY3JlZW5zaG907wO/PgAAGKxJREFUeJztnXlAVOX6x5+ZObPC
sCmyiYAirqhlAorlXrkjenPJq5KlXq9mVrdr9jNNM/V23XIpEwPTtDK3StTcEjVc7jVRRJAd
ZBEEZmE2Zvv9MTgMM+eced+ZMxDd+fx15pznvO878J3nvMvzPodlNBrBjZt2C7utG+DGjVO4
FeymfeNWsJv2jVvBbto3bgW7ad+4FeymfeNWsJv2jVvBbto3bgW7ad8Qbd2ANkOpvWU60Kh+
s71KEKEcbhcA4LKDuZzgVm0ZQKOhskH5nbdwPocjbuWq2x3/Ewo2GOVqXa5G85tOW6TT5jcq
f8YtgcP35RBD+MLRBLsLn9ebT/R0RTvN8NhBXG7fikovD58tfp7LXVpXe4f1Z42LMBjlysab
GvU1tTpNp7qBcgubAII/vulYKSdUEtBIWpqUangAAAY+8Lzm8oTDhfw416lZpjxWXz2VK4zx
67Bf4OLfTPvlz6Zgrb5SoT6rUhyld7QmsfL4MRxOFx63L5cTzOUEG3QyXc0Z3eM0ffl+lLqM
XiIj398g9DX49OB1mCUWTWLoSzQjUaRKa5LYBHj7HfUSJTJe/p+AP4+CpeoTStlXjcqfqAw4
/ACBcBZXMJRP9BEQPSwvGVTlmoJP9eXbjTonWiAOZwdNF0asZBNeTpRiTWXNhEbFKQDwCzwq
FrhFbI1rFXzlAtLj2y7Pj4qluqTVV0oVe1Wy1QYK8RGCWKHnDJFgrJVqTRh0Mk1psu7BO4y0
EwBYBPCePcvzfxHrrvRLlH8og072pP5TMCgBwNtnoYDbg2VjYwTKfyILWOYjW/r27+HTwRur
qXa5dumW+djwtFL20wYa2SyrM2YbVnMLm9sc//xA+upcqOArF24seXsDI0VlZp6wPanVV0pl
/1JIt5HewuEHiMQrxMLpXE4QVbGayu+1d6c75Xcp4D37PT/oL4jGxfllk6cuZb4RaPTv3X3B
G38ZOjLGmUJOn7x06fKt3+/lVlfXMtUwM/Hxz4x8PmbazLGkV12o4NnT37mXU8BIUVYK1uor
pPJPFRJy7fLFc73ES0S852gK1Ksfqe8uNtRQdjmcB13Eh1NPbtya4rqWoPDSiLh/bVuBe5ek
Vpry1bG0X666QrhW9O/fc92aJWFdO1udd9WKxuHUk0zJFwCK88tMBwaj/IlkeUVZiK182QR4
+LwVHFoe2CGVXr6NNWdUl0NdKl8AaLz9ik56HcXy4cMSl7YEhbOXrr/31kasW9JOXho7flHq
wZOtIF8AyMzMmTH7H/fu5Fqdd5WC9x0gee47TFlJBQBIFPvLy71ItevVcXtIiKyjz1a7qw+q
3NWam2Nd0XOwRX17LopZXkGpq1uCwtlL169evIliKamVvrd80/sfbleqVK5ulSVKhWrB4jVW
InaJgg+lnKx5Us9ggVz+44qqOGnNPNvhmsj77cCgCl/PN9ksO8tXBp1MeTNBl7+WwYbRY1Q+
bKw8YtfsXk5+KzQGhc3b7E8jSmqlSUkrz17MaIX22KJUqFav3Wl5xiUKTvmaSQcMAJ2CJmvV
1qN1gWhiQOccf9/NNGM1MwadTHl9nL7mJLMNs0tjwXZ6gyvnmZmuYYTCkvLigjIaA5N8C0vK
W61JthQUlP1w+LT5I/MKPpRysrqOSQcMAE+ejLH8yCbAt9PxgE4/kk6Q2WKSr1F6jdlWoWCU
XjPoZDQGDx78URywibLiCpqrK1dsbVv5mjh0JM18zLyCGXfAAGA5XyIUzwsOknmJEhDvNWjb
TL5NDVA8oLn6MK/th3GWsEjnjQEA4Mtdh6/dvNOajaGioKCspKjph8RwZM/hVOYdMACUl/oE
BgKbAG+/4+jaNaG8gS1fFheILquJwHGET9MsqUEn09ffbCzaZajB/n3qaq8R3pQrMpn38nAL
bBOK88u+OtjafTAayh89DosIAcZ98Ff7mXfAAFBdLeQKY/wDc7Dlm/UWlnxZXOD33ioaKRX0
XGOWLwCwCS+u/2iPmOOCgUdZXKwm0CGplbriB+8Kdu/8RqVUt3UrmsnNKTQdMKngw6knXPT/
yM726dTpPGKv14ymLFlfYmcgZQknZJ5opJQX8RZNYAM3MFEQw9jY697vOUwVxRQGNskKV3F+
2dlLSHPbrYa8QWE6YEzBklrJZ7u/RbcX8fgiHh/R+PK1EsLeZJkV+obsxrtvoNtzu60WDUhB
CcohfGK43VZjNYaKmzfuMlKOq/nl7NW2boI1zz0XbTpgrB+c/Pn3Sg3GU2bKuOG/33mQXeyS
yXyDTqa6swjdnt8/hdd5Hro9p8NQLRMLjr9n0g3ybEmY1LFFM9jeHrxeLSxaDsOu/Ha7qIxu
bgGRtDNXHLirk7/fM9E9goI7AQDL0HTS2NJnVlXWnLlAskfGLiGdA0wHzChYUis9+uNFdHt/
L/HCZa8uSvo/Rmq3RVOabJSi/tE5YW9hyRcAWFyM+EmauJPCEgx5iQS81+bvszwjEE0M6LSZ
5pZ38IMuzFIzI6mVFpXi/QyEIsGH/1wwLmEkivGKOumbSz+5m2W9XEyDyENoGsYBU72I5M+/
w3LAr81N8PbDC6K9ch61H6ZvyEaPlmSJegp6foTVElwIr2jS8yX5ZQo1xh+tZ1QHB2qfOW9y
RKhT+/zu3sXurH+5czWifAHA18974vgXsMrvHhlmPmZAwQ444FmvTwWAyK6hztduiyYbI8ZK
8Mx+ZgPSbWFR7Nb87cp/scrpEq61OsPmdke50dNDiF5LaJi13P+TkYV+OwAkzZzUb2Av+3YW
vDJrPJb9wAHNe64YUHDy7m9xHbDpQOzliX6XVNKAYqaT3tAjB52x/RMsp8zQaXx0GN2Y8I0j
PZ+TW4xVaXQfa1/I5oaRWjqMUCQIj7RxK5RLHOSMHEP+fWmor5Ni2ZuHceC8giW10qM/XUK3
NztgAECeigAAyHlQiGKmyV2PXiYv4u8YLXiKXlWuLyEPTbaF7dmN6lJ+IcYoVijgDoqzntjm
E31R7n1cXYdYy9CY/uhNoqLfwN64t2RnPsSy79030nzs7EjOYQesaJB7+jE8l6ST3kCP+mVx
ges/2oFa1LdnoRuz/CdQXcrKRfpNmhgaR9IT4HPtb2Auzi9Dn6SfPAm180qDpFaKu3Opd/+o
3ds+sN2SxHq68chiBoMFAL5+zeU7pWBnHPCT+sN+PvcAOtLfYkYuV9i10RbuRm8Mu9M8dGMz
yqzlBkk6uj3Hdwjp+fRzeAsEidPOWZ3hCmNQUrHs+OwAYhX+HX1J9yMaWXi7eM6cSp8xZyLW
Lb5+3vEjBmHdYsapXkTybuwpCNNB3ZNy0C/EqqvA3jNXryrXVXyNXiDhjffENOhkyjtJ6P0H
E9yOL5Oef3AfwwGPGe4VElpldVLo8ardG79NOXn+MlLQOgCsXokxg07Dvq+PS2rx+rXO4LiC
i/JLD/yQZt/uKZYOWKHBcJaINFZ+h2XP8kTqRJrQVh1TXvTWl6diVUEEz2FTzBzn5RUjFiLk
8+bNJ/GjnkI7m/C+2P7Nhm2oM8FDBkbTbAjHorqmLilpZauJ2PFexM6tGA4PAJYt/avpQNEg
N2g/AYCgkAL0XkSVvU0fhpI9WO1pfLhOX3uVzfchvaqtufz0qA6r22AJO4BykijzAerYZdFC
hdjmV3DvznsleSXAaorMtAiJNALAjet3z17IQO/+hocGbfj0XcrLNmscdiksKX95wsJxI+NH
kvwqWjQVLDq7ANC5S1BYN+u9nPQ4qOCi/NLzV/+Dbt87vMvEV5pSKDwqvyzgAwAE2zwZaaip
l9Bc1ckfGJR441mDJN1haaJABM/hB79Ceqm+TlpdS/d1zIwZ7jVilLUDvnU9ft2GXAC8jZlU
eAgE69YsYTxrhEqpPvrzhaM/X8C9sVOnDsMGPzt77qTwbkjLBQ72InAd8N/+PtN87NPxR8cq
pUFf78jauutgecfzo3dQXc26jRQOMThGvHQ5Sf9h1+ddHG9ZS8JDg3bvWtXvuT5MFeg81dW1
R06em5y49O8L15QUPrJr74iCHXDAL7w42PyxUbnXgUrBYs+9Lfoq126dx4LlGy+KTaNZ6ruR
YX8acXCM+P0PDtqe37H1r3USpVPte8qUcSP2798w4I8kX0uuXr8zY/a73x86RW/mSC9ix1bU
CRoTlg5Y0SA36JsvRYYT+cWoO99Lix6RrBgBAEDrb+GkguUbLxqURjWAM3HHXkgalXx/PjH5
3K90u+4Qie7RdeGC6c+PZmbo5jqUCvX6TXuBdtkZW8FF+aUXrt6yb/cUKwdcUZ6LtRSHAmJi
kVaACFsq7PuZXbOCR3ShXpPGi15fQC7fL53L7BMd1TUyMmze/EQqR0BKcLC/U7U6zfpNe4EF
r8wkFzF2L2LnZsd7wE7yIIt8W69eep+pKhzGSIAg9gyKfIvzy5QqDdXVBUnw+gKSoAvn5QsA
9x4Wnr2QsXH9HvRAPwAYO3G4h0DgbN3OsXXHgWKKPjGegovyS8//5ngP2BahCKN2mZy8/2fU
td78OSlEl2WeI6Xcji+hGF9LJ/8DCvncf31SPCGBpDvEiHxNKDXqjNtZS97ZOPsvbyNO2fp0
8J422ZHldwZRKtSrVpGPjPEUvGkd3pyrXQccHsZA+ifDk1+dL8QxiC7LRKPKhNHb6Du+luSS
haR1DvRITv6hZ59M20vfHZzKlHwtufewMGnOCkQRv73ydSeDjJ3nblbu1cskP34MBaefy8i4
g/G8JnXAwSF4uzUtycujWlhu7Tcycfwn8qKTPV6SCqO3cQR4M/AFNlnSJo8T7t5zyHbZAgA2
fDz7myOuyvFW+KhyxbufIhqn7t8QHmo/N5JL+elHkiAcjJHcni/wlm3/+cEC25MenuK6ejBP
R3h6GtD1p1CR9yIcmIjgR+9je/cBAIP0vt1OiBGMLMKb4920Cs326OVMUHxWXpH5uIOvcPGi
MtuwSQCQy2DNmtl5BXKHK0Ih43bWlfPXnx9tP6LXp4P3/v0bt/079XgaRiwXs1RUPbE9iarg
9HMZWfnF6JUNjx0wIIY88IAnekMtb5oSjoqsQ19YZhC2d5+mLCTUuUhcgWVI2qjhXq/NP0Dq
enPu99/0aa/aenlYgL+HEGOHBQDU1NXXyDB0fx5NwQDg08F7zYZl815P/CUtPf3qbZLQd9t0
8c1nWhhnZjOW5wVVwXv2fI9V7vL35lNdkjyZJOA3KXhg3DWAyYhlWnovJ6FJouNSsrPzoNn1
kj86vj2YeOiIHkAFAJ/t/hBr5svEsgVrfr2Bmh4KK9AeAMK7hS5Y+uqCpfYj42iQ1EqPfHd6
5x6M9AxUID3B089lYKlneOwAmr9755BhbE7zx+je/xPvtDNRUnZ/8jhhSuq3VD2HVe/PPnSk
qY/l7yV2QL4AsHbj2+jGWIH2TOHTwfuNxTPiYwY4XxSSenAdcGxMdPovdPllQ6NmseGQ6Tgu
VnEvG3WRo75Oahmf345QNP5HLl2/aAllVq5LF8Z/sUeo0jR3AMJDQxyrC3cfeFsxYfwLzqcS
tK/g9HPXcR/fm3bYWXaeOBbeeBpOPXLUmQOHpqg1SDF89/6b/cIYugnmPyAm7WoUlNotLwvc
8/noO/flAC12I0d1Z3gj5x8NL5ytvlTYV/AeJjorVpy7yB4/PtAUXekhhjEjDT+dtntT+0Ou
uaiQ7aDRLgDs2zPjl4t6lZpk7BUXz8BD1gGK8ksfNWcRphyumWEqNN4unp4kg1o7Ck4/dz0L
eTcBOmqN4d//jt+y/ajp46xXT567iOSGZVKyUTbXynnZR9+Qw/F01XtedUa5XHlCIVmp19IF
B146P+7rg1619ZSvoqBfznQd+5OPHT/9K7o96bvSUHj0CCNAHAB6RJI8lOyM5DZvScWqA538
Yt3eL5pmITzEMGUS0rw96fYyjg/qbIYZo9YlC9Fy9a81knfLS7xkNXNo5Hvrevw/lv916w4u
jXzDAhyPp7lzEyNHiYhvHfOQeQ8jSU90T8p0Ana5fTsby14s9rA9SeeDD+87VlyB9yvB4qfT
EBj48sSEMwAwc/ZPt25NRY+0tMTI5eHeYtCUATD27JNrLqpVaSr5ZqPejuXFc6NOp4XkFkoB
7ARJRoQ7OIwDgKOHMfpkXcOsV9oKMV2jY0hqpenIU34mevTqanuSTsH7DjC/mcKKvSl8gCYR
r/v46N+WTJFI6PoSFVU1JGc9u+n9QMcFnj6CLS0yIvQotFWneIHTHGw0AABotHnKxutadbpK
noxiX1U+YMXKnnUSFQCS+4+NIc+2Zpfi/DKs/QdtxSfrPsdNqT10GMlrAil7Ed/sO0a/NY0p
9qbwt21JAAAPMXywIl/Ap+vYPK4mWVfkigdy6oD/GEBXqwwCSQ9QhIOuczejT5iRYj3LUJ6q
b8B7hKl1uQ3qi3XyXVXVU0vLWFXlUbKaOSjy5YsSfQNOFOasqpNgvH2tdz9HAkiK88veXLxW
2UgZvWnLM/1a5DjLvIUXqoqZTKKJ95ZtxE2pPSSOfFxL6YNTvm69XQ8XLxtzcqa88Vr1wLhr
6z6CVasjESfXTHA8m9IcsSQyoQREXND6cFVeBdqnE8dcFQAAXwMcfRBbzWOB0KjJUd4azok7
AgT5hI5KncEClsEo0alvGwxVWjX2PjyuYIhQvMhDMJrHCQKABzl0aVJtoVqTp0JaJzt17NyO
Pd9jyRcAevSOaFGOBC8So6CkvCS/LAxt5UVSKz3z8+XkAydqalATYZkZ8Tx5ShRyBX+z71iN
pFWDbiseGz7a0DF2UOK0qXnbNmesXTe44jGJiKufkDwWOJ69WQSYX9Np1AJRoxXXgFEIBnGE
WlTUKAQjG7RCAKi0uK8GHg9n/IvwRYl8jwSzcM0UFNG9p80KEY8/c/KbWPU6lktcxBdMnDrG
vh01CrV6kutfay7yEIwZN5T0ErmCW9MBW3Ljlv7Gra7BAZE9exqVGrZtn5jqd8UJWaazeWUG
SwUcVZEHgAeA0VOsFws1/GotHwzMLWOzdcDVgEAdxGFFcqK3iLiU73PGmpRUNmpclN3eiiGD
8Dx9WzE98UWqtViSfyauA/b38X5xZBzQvoqMhrMXM6yqq3hsqHgMtMnPreGGzrRVsCWsBjnR
IG/+tj499TylkcfVsgt0BAALtPb20Zi6IoQOuIZurEYDp5EPEvOsUyVAJS9CD77k9+J2LluN
hCltvPkCBZFQOC9pKtVVEgXjOuCkOZNfnZ+I3a6nGMH4zbGz6PZ3bmbZ9hEJ71iWKMqInvRE
kmMKLnLIHZO/QqMxbwMRQz63n3H1tiP1uJjoqK62cZWhEW28F8OWD99fQJOQxXrg74ADdka+
gO+5ZRRDDcEAvC2ojKOvOUk1v5H7kLG4UKYQCfkfb1huez4ikrF0KowwNLb/2MkjaAxaKFhS
K9mJGYaWNAd7PcxFEL6x7OC5bdgAts9QFp98x1FhIQMvFGKWudMnUYVuDn7mj9I5jgjvvH6D
nUjRFgr+cudhrGyqzjtgABCLcfYrA2RnUb4HSxD9GUsU5WR7HIMdMk8Yc4p0v6ekVlJc1Rqr
XOiMHvrcouWUIeovkC0ctD4RYSGpX623m9CtWcH1ddLjpy7TmNry4QcMZJzt1RfpdSZm5DLK
F2pwCC/hoOOsVo+Y5/ba7DEghWq7ciZalrRWY/TQ5zbvonsP2qykhE4dyFN6thoRYSGpKZ+g
5CNsVvDeHYewHHCfruFtFTxFA8ezt/CFR2zf+NapjiWKEg27L+hK96S78dsf4n3wJkYNHUQv
XxPLFs9uhcZQMSSmH6J8waxgBxzwor9Nx24aE/yeaSdyiiMMEcSkEZGrXNoMFgHcXps9R+Sa
VwSpKCjAWMtwHSIhf/G8qVt2fYBiPGHa6ISXh7m6SbYIRYKlC2d8vnctejbYpidu8g68HjCD
Drg/5rvHUFbiOYSXsMdaXeD4xtwNjCcFZBHA7baFCJ/PQdtzfzenDTaiWTF4QJ8VqxZh7br7
aNNyYMGJ03h+zRleGjl48ZJZiGmDzRAAIKmVHjv1K9ZtC5lzwD6YXS4FckAT4R1LxJzQVv2g
LT3IiI5Zoiii2z+5wdMQtQsAxXmlWK6BWUQC3pBn+815bUr/QY6kWP1o4/JBMdHbdx5EzNft
GJ38/caOiU+c9iKudk0QAHDlwo2I0AAAAAPS1GxAgN8wRnvAfbq5cEMYN3AaN3CaviG7sfw7
fcW3GKseT+F0nMgOSuD6DuaIMR8XAJJ6WR+ynQVUkMyOI/1PWhh5CEXdu3eJHdzP+T2FExJH
T0gcfSjlxOX0Ww2KFrF1zc9Cm6QQRtuEEebPT09079YlKio8Lv4Zx/ZjWzTD6FB4XLtF35Bj
aLivk941SjMBwFB/0hQSxPF+Hnh+JhtOx2EAwBaFsj172+3mumlb/ucU7OZPRmvnzHPjhlnc
CnbTvnEr2E37xq1gN+0bt4LdtG/cCnbTvnEr2E375v8BB57uT18PhsoAAAAASUVORK5CYII=
--------------010905060500030601010003--

--------------020904060208030009070707--


From MAILER-DAEMON Tue Oct 16 09:09:46 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TO6u2-0001wc-FH
	for mharc-coreutils@gnu.org; Tue, 16 Oct 2012 09:09:46 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58571)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TO6tw-0001vi-Ln
	for coreutils@gnu.org; Tue, 16 Oct 2012 09:09:44 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TO6ts-0007NT-Ay
	for coreutils@gnu.org; Tue, 16 Oct 2012 09:09:40 -0400
Received: from mx1.redhat.com ([209.132.183.28]:1259)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TO6ts-0007NH-1o
	for coreutils@gnu.org; Tue, 16 Oct 2012 09:09:36 -0400
Received: from int-mx02.intmail.prod.int.phx2.redhat.com
	(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9GD9TKm003995
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 16 Oct 2012 09:09:32 -0400
Received: from [10.16.60.53] (redsox.boston.devel.redhat.com [10.16.60.53])
	by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9GD9SqN011207; Tue, 16 Oct 2012 09:09:29 -0400
Message-ID: <507D5C87.3030501@redhat.com>
Date: Tue, 16 Oct 2012 09:09:27 -0400
From: Daniel J Walsh <dwalsh@redhat.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: Make mv work better with SELinux.
References: <50733664.5000503@redhat.com> <50733CC1.9000506@draigBrady.com>
	<87626jolel.fsf@rho.meyering.net>
In-Reply-To: <87626jolel.fsf@rho.meyering.net>
X-Enigmail-Version: 1.4.5
Content-Type: text/plain; charset=ISO-8859-1
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9GD9TKm003995
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Oct 2012 13:09:45 -0000

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/09/2012 08:54 AM, Jim Meyering wrote:
> P=E1draig Brady wrote:
>=20
>> On 10/08/2012 09:24 PM, Daniel J Walsh wrote:
>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>>>=20
>>> One of if not the most common problem people hit with SELinux is the
>>> mv command, which maintains the file context of the source
>>> destination.
>>>=20
>>> mv /home/dwalsh/index.html /var/www/html/
>>>=20
>>> This blows up on everybody and then the users have no idea why.
>>>=20
>>> I was thinking about adding -Z (--restorecon) to mv and having it
>>> basically do a internal restorecon on the destination.
>>>=20
>>> Then we could suggest people who get burnt by this to:
>>>=20
>>> alias mv=3D"mv -Z"
>>>=20
>>> In Fedora 18 we have greatly enhanced matchpathcon, by pre-compiling
>>> the regex, so there should be very little slow down in doing this.
>>>=20
>>> I will work on the patch, if people agree with the idea.
>>=20
>> I like the idea. Now cp and install should behave similarly, and they
>> already have the -Z option.
>=20
> Upstream cp does not have -Z. I agree that this seems like the right ti=
me
> to add it.
>=20
>> So I would suggest that cp, mv and install support the -Z option witho=
ut
>> an argument, which means auto set the context based on the destination.
>>=20
>> The caveat with that is that short options with optional args are very
>> problematic. So I'd just have the long --context have an optional arg,
>> while -Z would require an arg.
>=20
> [in a follow-up]
>> Thinking further, --context without an option, is not too clear to the
>> user. They might think they were copying the original context rather t=
han
>> setting a new context.
>=20
>> Pity the long option wasn't called --new-context. I suppose we could h=
ave
>> that as an alias for --context and deprecate the former?
>=20
> Sounds reasonable. Adjust the other --context=3DCTX commands, mkdir, mk=
fifo,
> mknod at the same time.
>=20

I just want to make sure that you guys are expecting a patch from me?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlB9XIcACgkQrlYvE4MpobOy2gCg1Xi+KqveevB6PlupeWWkrH9A
EtYAoJbnlqq1ZvrZedJFBqaPwg10uA4q
=3DmliO
-----END PGP SIGNATURE-----


From MAILER-DAEMON Tue Oct 16 09:32:57 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TO7GT-0008HG-Fk
	for mharc-coreutils@gnu.org; Tue, 16 Oct 2012 09:32:57 -0400
Received: from eggs.gnu.org ([208.118.235.92]:48397)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TO7GL-0008GB-7u
	for coreutils@gnu.org; Tue, 16 Oct 2012 09:32:55 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TO7G8-0005jo-HR
	for coreutils@gnu.org; Tue, 16 Oct 2012 09:32:49 -0400
Received: from mx.meyering.net ([88.168.87.75]:54396)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TO7G8-0005jh-AJ
	for coreutils@gnu.org; Tue, 16 Oct 2012 09:32:36 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 901F5600A6;
	Tue, 16 Oct 2012 15:32:35 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Daniel J Walsh <dwalsh@redhat.com>
Subject: Re: Make mv work better with SELinux.
In-Reply-To: <507D5C87.3030501@redhat.com> (Daniel J. Walsh's message of "Tue, 
	16 Oct 2012 09:09:27 -0400")
References: <50733664.5000503@redhat.com> <50733CC1.9000506@draigBrady.com>
	<87626jolel.fsf@rho.meyering.net> <507D5C87.3030501@redhat.com>
Date: Tue, 16 Oct 2012 15:32:35 +0200
Message-ID: <87wqyqwnik.fsf@rho.meyering.net>
Lines: 20
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Oct 2012 13:32:55 -0000

Daniel J Walsh wrote:
> On 10/09/2012 08:54 AM, Jim Meyering wrote:
>> P=E1draig Brady wrote:
>>> On 10/08/2012 09:24 PM, Daniel J Walsh wrote:
...
>> [in a follow-up]
>>> Thinking further, --context without an option, is not too clear to the
>>> user. They might think they were copying the original context rather th=
an
>>> setting a new context.
>>
>>> Pity the long option wasn't called --new-context. I suppose we could ha=
ve
>>> that as an alias for --context and deprecate the former?
>>
>> Sounds reasonable. Adjust the other --context=3DCTX commands, mkdir, mkf=
ifo,
>> mknod at the same time.
>
> I just want to make sure that you guys are expecting a patch from me?

I am.  That'd be great, especially if you can add NEWS entries
and tests to exercise the new code.


From MAILER-DAEMON Tue Oct 16 14:25:24 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TOBpU-0000iP-BP
	for mharc-coreutils@gnu.org; Tue, 16 Oct 2012 14:25:24 -0400
Received: from eggs.gnu.org ([208.118.235.92]:43459)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TOBpL-0000fG-TS
	for coreutils@gnu.org; Tue, 16 Oct 2012 14:25:22 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TOBpF-0005HQ-K3
	for coreutils@gnu.org; Tue, 16 Oct 2012 14:25:15 -0400
Received: from joseki.proulx.com ([216.17.153.58]:60406)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TOBpF-0005DW-56
	for coreutils@gnu.org; Tue, 16 Oct 2012 14:25:09 -0400
Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119])
	by joseki.proulx.com (Postfix) with ESMTP id 93ADA211DA;
	Tue, 16 Oct 2012 12:25:07 -0600 (MDT)
Received: by hysteria.proulx.com (Postfix, from userid 1000)
	id 85BD62DCD1; Tue, 16 Oct 2012 12:25:07 -0600 (MDT)
Date: Tue, 16 Oct 2012 12:25:07 -0600
From: Bob Proulx <bob@proulx.com>
To: Thibault LE PAUL <tlepaul@aebs-tech.com>
Subject: Re: [head] wished an option to continue consuming the input after
	the specified number of lines has been read
Message-ID: <20121016182507.GA19647@hysteria.proulx.com>
Mail-Followup-To: Thibault LE PAUL <tlepaul@aebs-tech.com>, coreutils@gnu.org
References: <507B4842.3020408@aebs-tech.com>
	<20121015030315.GA14084@hysteria.proulx.com>
	<507BD518.7000702@aebs-tech.com>
	<20121016032009.GA15412@dismay.proulx.com>
	<507D15DF.7070703@aebs-tech.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <507D15DF.7070703@aebs-tech.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 216.17.153.58
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
Reply-To: coreutils@gnu.org
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Oct 2012 18:25:22 -0000

Thibault LE PAUL wrote:
> I wasn't clear enough.
> My goal was to do different things on the first lines and the last
> lines of same input, without using storage, thus using piped
> processes.

Depending upon what you want to do I would do something like this
using sed to do the difference to either part.

  $ seq 1 10 | sed '1,3s/^/head /;7,10s/^/tail /'
  head 1
  head 2
  head 3
  4
  5
  6
  tail 7
  tail 8
  tail 9
  tail 10

Or without printing the skipped lines:

  $ seq 1 10 | sed -n '1,3s/^/head /p;7,9s/^/tail /p'
  head 1
  head 2
  head 3
  tail 7
  tail 8
  tail 9

Or awk:

  $ seq 1 10 | awk 'NR<=3{print "head ",$0} NR>7{print "tail ",$0}'
  head  1
  head  2
  head  3
  tail  8
  tail  9
  tail  10

Or perl, python, ruby for complex tasks where I wanted to write
multiple line subroutines.  I would write all of the code out in a
subroutine and then call the subroutine on the appropriate line.

> Then I used tee, to fork the pipe into two processes.

That is okay.  But manually using multiple processes always comes with
it the problem of manually using multple processes. :-)

> Opposite to that, my original way that fails :

I cannot recreate a failure.

> rm /tmp/fifo1
> mkfifo /tmp/fifo1
> cat /tmp/fifo1|head -n2|sed 's/^/head&/'&
> tee /tmp/fifo1|tail -n2|sed 's/^/tail&/'

I assume that any amount of input to the tee can be used?  Can I
simply 'echo foo > /tmp/fifo1' and trigger your test case?  Please
say what input must be used.  If you don't say then we won't know.

What input are you providing to tee?  For use in this test case I
assume a few lines of input larger than 2+2=4 lines.  I will use the
command 'seq 1 7' to generate easy repeatable input.  I also like
spaces between debug strings so will add some spaces.

  seq 1 7 | tee /tmp/fifo1|tail -n2|sed 's/^/tail &/'

> That way, the /tmp/fifo1 fifo propagates SIGPIPE ahead to tee as
> soon as head has finished,

What?  There is a misunderstanding at this point.  This statement does
not make sense.

SIGPIPE occurs when a process writes to a closed pipe.  It is sent
from the kernel to the writing process.  The default action of SIGPIPE
is terminate the process.  See 'man 7 signal' for more details.

The 'tee' process is writing to the pipe.  When the last reader on the
pipe closes (usually by exiting) then all future writers will receive
a sigpipe signal which will terminate them.  This is normal behavior.

So, yes, tee is not able to read all of the input and write all of the
output to all of the output pipes from it.  But that is expected given
that one of the readers has exited.

> cat /tmp/fifo1|head -n2|sed 's/^/head&/'&

That extra 'cat' process is going to confuse things.  It will buffer
input and write buffered output.  This will reblock the data in
confusing ways.  I prefer to remove it.  It isn't needed.

  head -n2 < /tmp/fifo1 | sed 's/^/head &/'&

But perhaps this is simply a smaller example from the larger problem
and the cat represents some other process?

> rm /tmp/fifo1
> mkfifo /tmp/fifo1
> cat /tmp/fifo1|head -n2|sed 's/^/head&/'&
> tee /tmp/fifo1|tail -n2|sed 's/^/tail&/'

It is easier to debug this by avoiding the backgrounding and running
this test in three terminal windows.  In one read from the pipe with
the "head" section.  In two run the tee section.  In three send input
to the fifo.  Doing so will make it more visible when the processes
are running and when they are exiting.  Doing so will show that the
head command pipeline is reading two lines and emitting them followed
by the tail task emitting two lines them.  But running them as you
have shown produces this output:

  $ head -n2 < fifo | sed 's/^/head &/' &
  [1] 14641
  $ seq 1 9 | tee fifo | tail -n2 | sed 's/^/tail &/'
  head 1
  head 2
  tail 8
  tail 9
  [1]+  Done                    head -n2 < fifo | sed 's/^/head &/'
  $ 

> then tee stops, and tail doesn't read the expected last lines,
> instead just the lines before tee aborts and EOF is read on
> pipe. The effect is observable on large input, like
> /usr/share/mysql/errmsg-utf8.txt

Yes.  I did this:

  $ head -n2 < fifo | sed 's/^/head &/' &
  [1] 14641
  $ tee fifo < /usr/share/mysql/errmsg-utf8.txt | tail -n2 | sed 's/^/tail &/'

And I could see that tee exited due to the write on the fifo finishing
before the write to stdout and so the tail did not get all of the
file.  I consider that a normal behavior.  Yes, reading all of the
input and discarding it in the head process will allow tee to write
all of the output.  But that is a lot of extra data writing that is
wasteful and unused and simply thrown away and therefore I would avoid
doing it that way.  Doing tee to two asynchronous parallel processes
that may independently exit at different times.  Therefore I
immediately think of one of the earlier solutions I posted above that
processed the input on the fly.  It is so much simpler.

Also since the background process is asynchronous the order of emitted
output isn't specified.  It is possible that the background process
would be scheduled later (kernel process scheduling) and then the
output of the two processes might appear in a different order.  It is
tickling a lot of possible problems.  Best to those avoid entirely.

The use of the term "abort" would usually mean 'man 3 abort', the
abort() system call.  That is the action that happens from various
signals.  But I think you are using it casually simpling meaning that
the program is exiting.  Read the man page for 'man 3 abort' and the
signals that cause an abort() to happen in 'man 7 signals' and then
please avoid using that word when we aren't talking about that event
so that it doesn't confuse us.  :-)

> Also tried tee -i to ignore interrupts, but it is not the purpose of
> this option I suppose. No effect in our case.

The tee -i option only ignores SIGINT meant to avoid Control-C
interrupts.

Whew!  So where are we?  I advise avoiding the background process
approach, for this particular case at least, as it isn't needed.  It
opens a large box of potential and real problems.

Bob


From MAILER-DAEMON Tue Oct 16 15:58:24 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TODHU-0000iY-6K
	for mharc-coreutils@gnu.org; Tue, 16 Oct 2012 15:58:24 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49041)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TODHQ-0000hB-Vf
	for coreutils@gnu.org; Tue, 16 Oct 2012 15:58:22 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TODHP-0008Im-2J
	for coreutils@gnu.org; Tue, 16 Oct 2012 15:58:20 -0400
Received: from bart.planet-work.net ([79.99.164.26]:56258)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TODHO-0008ID-MM
	for coreutils@gnu.org; Tue, 16 Oct 2012 15:58:18 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
	d=aebs-tech.com; s=dkim; 
	h=Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Subject:To:MIME-Version:From:Date:Message-ID;
	bh=kpv5OOMH+IJYzWiL6aNDs7W9ptflEdYxz3IsUZ7N4UA=; 
	b=fV1ag67bia2nGSvbJimZ9YeDqbAD73M/MTr79fAsG7H7VA8Ns4UzFvNpRXiE+bbWPnyzpGrYkxa5WMwW7USMl53BwkNlgpfJMP/oDe/VFUnFcEnTnh3G1IRDGxBo5AdCmvcKxF19FwcYHwPpwy68N9dmnbcGdodrA4Q/c8GYdrs=;
Received: from [41.221.22.157] (helo=[10.234.34.25])
	by bart.planet-work.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)
	(Exim 4.72) (envelope-from <tlepaul@aebs-tech.com>)
	id 1TODHJ-0000Lt-DU
	for coreutils@gnu.org; Tue, 16 Oct 2012 21:58:14 +0200
Message-ID: <507DBC4D.8020304@aebs-tech.com>
Date: Tue, 16 Oct 2012 20:58:05 +0100
From: Thibault LE PAUL <tlepaul@aebs-tech.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:10.0.7) Gecko/20120922 Icedove/10.0.7
MIME-Version: 1.0
To: coreutils@gnu.org
Subject: Re: [head] wished an option to continue consuming the input after
	the specified number of lines has been read
References: <507B4842.3020408@aebs-tech.com>
	<20121015030315.GA14084@hysteria.proulx.com>
	<507BD518.7000702@aebs-tech.com>
	<20121016032009.GA15412@dismay.proulx.com>
	<507D15DF.7070703@aebs-tech.com>
	<20121016182507.GA19647@hysteria.proulx.com>
In-Reply-To: <20121016182507.GA19647@hysteria.proulx.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 79.99.164.26
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Oct 2012 19:58:22 -0000

On 16/10/2012 19:25, Bob Proulx wrote:
> Thibault LE PAUL wrote:
>> I wasn't clear enough.
>> My goal was to do different things on the first lines and the last
>> lines of same input, without using storage, thus using piped
>> processes.
> Depending upon what you want to do I would do something like this
> using sed to do the difference to either part.
>
>    $ seq 1 10 | sed '1,3s/^/head /;7,10s/^/tail /'
>    head 1
>    head 2
>    head 3
>    4
>    5
>    6
>    tail 7
>    tail 8
>    tail 9
>    tail 10
>
> Or without printing the skipped lines:
>
>    $ seq 1 10 | sed -n '1,3s/^/head /p;7,9s/^/tail /p'
>    head 1
>    head 2
>    head 3
>    tail 7
>    tail 8
>    tail 9
>
> Or awk:
>
>    $ seq 1 10 | awk 'NR<=3{print "head ",$0} NR>7{print "tail ",$0}'
>    head  1
>    head  2
>    head  3
>    tail  8
>    tail  9
>    tail  10
It's difficult that way without knowing a priori the line numbers, if 
you want the tail -n2 equivalent. I suppose that tail is using something 
like a rotating line buffer.
> I assume that any amount of input to the tee can be used?  Can I
> simply 'echo foo>  /tmp/fifo1' and trigger your test case?  Please
> say what input must be used.  If you don't say then we won't know.
>
> What input are you providing to tee?  For use in this test case I
> assume a few lines of input larger than 2+2=4 lines.  I will use the
> command 'seq 1 7' to generate easy repeatable input.  I also like
> spaces between debug strings so will add some spaces.
>
>    seq 1 7 | tee /tmp/fifo1|tail -n2|sed 's/^/tail&/'
>
>> That way, the /tmp/fifo1 fifo propagates SIGPIPE ahead to tee as
>> soon as head has finished,
> What?  There is a misunderstanding at this point.  This statement does
> not make sense.
>
> SIGPIPE occurs when a process writes to a closed pipe.  It is sent
> from the kernel to the writing process.  The default action of SIGPIPE
> is terminate the process.  See 'man 7 signal' for more details.
>
> The 'tee' process is writing to the pipe.  When the last reader on the
> pipe closes (usually by exiting) then all future writers will receive
> a sigpipe signal which will terminate them.  This is normal behavior.
>
> So, yes, tee is not able to read all of the input and write all of the
> output to all of the output pipes from it.  But that is expected given
> that one of the readers has exited.
>
>> cat /tmp/fifo1|head -n2|sed 's/^/head&/'&
> That extra 'cat' process is going to confuse things.  It will buffer
> input and write buffered output.  This will reblock the data in
> confusing ways.  I prefer to remove it.  It isn't needed.
However (head -n2;cat >/dev/null) wiill read until EOF, that was the 
object of my XY problem :)
>   head -n2<  /tmp/fifo1 | sed 's/^/head&/'&
>
> But perhaps this is simply a smaller example from the larger problem
> and the cat represents some other process?
>
>> rm /tmp/fifo1
>> mkfifo /tmp/fifo1
>> cat /tmp/fifo1|head -n2|sed 's/^/head&/'&
>> tee /tmp/fifo1|tail -n2|sed 's/^/tail&/'
> It is easier to debug this by avoiding the backgrounding and running
> this test in three terminal windows.  In one read from the pipe with
> the "head" section.  In two run the tee section.  In three send input
> to the fifo.  Doing so will make it more visible when the processes
> are running and when they are exiting.  Doing so will show that the
> head command pipeline is reading two lines and emitting them followed
> by the tail task emitting two lines them.  But running them as you
> have shown produces this output:
>
>    $ head -n2<  fifo | sed 's/^/head&/'&
>    [1] 14641
>    $ seq 1 9 | tee fifo | tail -n2 | sed 's/^/tail&/'
>    head 1
>    head 2
>    tail 8
>    tail 9
>    [1]+  Done                    head -n2<  fifo | sed 's/^/head&/'
>    $
>
>> then tee stops, and tail doesn't read the expected last lines,
>> instead just the lines before tee aborts and EOF is read on
>> pipe. The effect is observable on large input, like
>> /usr/share/mysql/errmsg-utf8.txt
> Yes.  I did this:
>
>    $ head -n2<  fifo | sed 's/^/head&/'&
>    [1] 14641
>    $ tee fifo<  /usr/share/mysql/errmsg-utf8.txt | tail -n2 | sed 's/^/tail&/'
>
> And I could see that tee exited due to the write on the fifo finishing
> before the write to stdout and so the tail did not get all of the
> file.  I consider that a normal behavior.  Yes, reading all of the
> input and discarding it in the head process will allow tee to write
> all of the output.  But that is a lot of extra data writing that is
> wasteful and unused and simply thrown away and therefore I would avoid
> doing it that way.
I agree. However, if you use temporary file storage, it's worse. You 
write it to disk instead of socket, and you read it from disk instead of 
socket. Even if you write twice on socket instead of once to disk, I 
think it's better. Further the performance point, you may not want to 
use storage that you are not sure to get available : you don't know how 
big is your input. By the way, you are sure to get available CPU.
> Also since the background process is asynchronous the order of emitted
> output isn't specified.  It is possible that the background process
> would be scheduled later (kernel process scheduling) and then the
> output of the two processes might appear in a different order.  It is
> tickling a lot of possible problems.  Best to those avoid entirely.
Either :
1) add wait :

cat /tmp/fifo1|(head -n2;cat>/dev/null)|sed 's/^/head&/'&
cat /usr/share/mysql/errmsg-utf8.txt|tee /tmp/fifo1|tail -n2|(wait;sed 's/^/tail&/')

2) be independent upon scheduling  :

cat /tmp/fifo1|(head -n2;cat>/dev/null)>  /tmp/head&
cat /usr/share/mysql/errmsg-utf8.txt|tee /tmp/fifo1|tail -n2>  /tmp/tail

> The use of the term "abort" would usually mean 'man 3 abort', the
> abort() system call.  That is the action that happens from various
> signals.  But I think you are using it casually simpling meaning that
> the program is exiting.  Read the man page for 'man 3 abort' and the
> signals that cause an abort() to happen in 'man 7 signals' and then
> please avoid using that word when we aren't talking about that event
> so that it doesn't confuse us.  :-)
While writing it I felt guilty but lazy, Sorry :)
Thanks to be strict.
>
>> Also tried tee -i to ignore interrupts, but it is not the purpose of
>> this option I suppose. No effect in our case.
> The tee -i option only ignores SIGINT meant to avoid Control-C
> interrupts.
>
> Whew!  So where are we?  I advise avoiding the background process
> approach, for this particular case at least, as it isn't needed.  It
> opens a large box of potential and real problems.
Finally, when we write it correctly, it works, doesn't it ? With very 
few code, we've solved Y.

However my initial case was to extract a sheet from a calc document, let 
the 4 first lines unsorted (table headers), sort the following lines by 
a column value, then catenate the result and transform the output into 
html table. And, for this case, it is better to use awk, of course, 
instead of head -n4 and tail -n+4.  This is the X problem solved. You 
were right :D

Thibault


From MAILER-DAEMON Tue Oct 16 16:07:32 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TODQK-0004JV-7W
	for mharc-coreutils@gnu.org; Tue, 16 Oct 2012 16:07:32 -0400
Received: from eggs.gnu.org ([208.118.235.92]:40593)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TODQH-0004I3-ID
	for coreutils@gnu.org; Tue, 16 Oct 2012 16:07:30 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TODQF-0002QV-NG
	for coreutils@gnu.org; Tue, 16 Oct 2012 16:07:29 -0400
Received: from bart.planet-work.net ([79.99.164.26]:56520)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tlepaul@aebs-tech.com>) id 1TODQF-0002QJ-Aq
	for coreutils@gnu.org; Tue, 16 Oct 2012 16:07:27 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
	d=aebs-tech.com; s=dkim; 
	h=Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Subject:To:MIME-Version:From:Date:Message-ID;
	bh=XQNiUTASEMRZ/DCNuOTQJ5tp6TKMsLZFtAtsn5F/Jks=; 
	b=WJJQwpVlQc0x0GYfegITIRamdq/guvJ4zg1NUi5ZOGz94TL897x+rjydKc7jdiycN0griZ1QntVQq8YSsF64MLNgHojGMrmK2I44zh8Xl0CN/t90+7wuJB5oBya6yUWdm4qflRmG0hPIKCEsykrGMKZCV06mtHx7+IB9vQnoVT4=;
Received: from [41.221.22.157] (helo=[10.234.34.25])
	by bart.planet-work.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)
	(Exim 4.72) (envelope-from <tlepaul@aebs-tech.com>)
	id 1TODQB-0000in-5w
	for coreutils@gnu.org; Tue, 16 Oct 2012 22:07:24 +0200
Message-ID: <507DBE7B.6010606@aebs-tech.com>
Date: Tue, 16 Oct 2012 21:07:23 +0100
From: Thibault LE PAUL <tlepaul@aebs-tech.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:10.0.7) Gecko/20120922 Icedove/10.0.7
MIME-Version: 1.0
To: coreutils@gnu.org
Subject: Re: [head] wished an option to continue consuming the input after
	the specified number of lines has been read
References: <507B4842.3020408@aebs-tech.com>
	<20121015030315.GA14084@hysteria.proulx.com>
	<507BD518.7000702@aebs-tech.com>
	<20121016032009.GA15412@dismay.proulx.com>
	<507D15DF.7070703@aebs-tech.com>
	<20121016182507.GA19647@hysteria.proulx.com>
	<507DBC4D.8020304@aebs-tech.com>
In-Reply-To: <507DBC4D.8020304@aebs-tech.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 79.99.164.26
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Oct 2012 20:07:31 -0000

On 16/10/2012 20:58, Thibault LE PAUL wrote:
> On 16/10/2012 19:25, Bob Proulx wrote:
>> Thibault LE PAUL wrote:
>>> I wasn't clear enough.
>>> My goal was to do different things on the first lines and the last
>>> lines of same input, without using storage, thus using piped
>>> processes.
>> Depending upon what you want to do I would do something like this
>> using sed to do the difference to either part.
>>
>>    $ seq 1 10 | sed '1,3s/^/head /;7,10s/^/tail /'
>>    head 1
>>    head 2
>>    head 3
>>    4
>>    5
>>    6
>>    tail 7
>>    tail 8
>>    tail 9
>>    tail 10
>>
>> Or without printing the skipped lines:
>>
>>    $ seq 1 10 | sed -n '1,3s/^/head /p;7,9s/^/tail /p'
>>    head 1
>>    head 2
>>    head 3
>>    tail 7
>>    tail 8
>>    tail 9
>>
>> Or awk:
>>
>>    $ seq 1 10 | awk 'NR<=3{print "head ",$0} NR>7{print "tail ",$0}'
>>    head  1
>>    head  2
>>    head  3
>>    tail  8
>>    tail  9
>>    tail  10
> It's difficult that way without knowing a priori the line numbers, if 
> you want the tail -n2 equivalent. I suppose that tail is using 
> something like a rotating line buffer.
>> I assume that any amount of input to the tee can be used?  Can I
>> simply 'echo foo>  /tmp/fifo1' and trigger your test case?  Please
>> say what input must be used.  If you don't say then we won't know.
>>
>> What input are you providing to tee?  For use in this test case I
>> assume a few lines of input larger than 2+2=4 lines.  I will use the
>> command 'seq 1 7' to generate easy repeatable input.  I also like
>> spaces between debug strings so will add some spaces.
>>
>>    seq 1 7 | tee /tmp/fifo1|tail -n2|sed 's/^/tail&/'
>>
>>> That way, the /tmp/fifo1 fifo propagates SIGPIPE ahead to tee as
>>> soon as head has finished,
>> What?  There is a misunderstanding at this point.  This statement does
>> not make sense.
>>
>> SIGPIPE occurs when a process writes to a closed pipe.  It is sent
>> from the kernel to the writing process.  The default action of SIGPIPE
>> is terminate the process.  See 'man 7 signal' for more details.
>>
>> The 'tee' process is writing to the pipe.  When the last reader on the
>> pipe closes (usually by exiting) then all future writers will receive
>> a sigpipe signal which will terminate them.  This is normal behavior.
>>
>> So, yes, tee is not able to read all of the input and write all of the
>> output to all of the output pipes from it.  But that is expected given
>> that one of the readers has exited.
>>
>>> cat /tmp/fifo1|head -n2|sed 's/^/head&/'&
>> That extra 'cat' process is going to confuse things.  It will buffer
>> input and write buffered output.  This will reblock the data in
>> confusing ways.  I prefer to remove it.  It isn't needed.
> However (head -n2;cat >/dev/null) wiill read until EOF, that was the 
> object of my XY problem :)
>>   head -n2<  /tmp/fifo1 | sed 's/^/head&/'&
>>
>> But perhaps this is simply a smaller example from the larger problem
>> and the cat represents some other process?
>>
>>> rm /tmp/fifo1
>>> mkfifo /tmp/fifo1
>>> cat /tmp/fifo1|head -n2|sed 's/^/head&/'&
>>> tee /tmp/fifo1|tail -n2|sed 's/^/tail&/'
>> It is easier to debug this by avoiding the backgrounding and running
>> this test in three terminal windows.  In one read from the pipe with
>> the "head" section.  In two run the tee section.  In three send input
>> to the fifo.  Doing so will make it more visible when the processes
>> are running and when they are exiting.  Doing so will show that the
>> head command pipeline is reading two lines and emitting them followed
>> by the tail task emitting two lines them.  But running them as you
>> have shown produces this output:
>>
>>    $ head -n2<  fifo | sed 's/^/head&/'&
>>    [1] 14641
>>    $ seq 1 9 | tee fifo | tail -n2 | sed 's/^/tail&/'
>>    head 1
>>    head 2
>>    tail 8
>>    tail 9
>>    [1]+  Done                    head -n2<  fifo | sed 's/^/head&/'
>>    $
>>
>>> then tee stops, and tail doesn't read the expected last lines,
>>> instead just the lines before tee aborts and EOF is read on
>>> pipe. The effect is observable on large input, like
>>> /usr/share/mysql/errmsg-utf8.txt
>> Yes.  I did this:
>>
>>    $ head -n2<  fifo | sed 's/^/head&/'&
>>    [1] 14641
>>    $ tee fifo<  /usr/share/mysql/errmsg-utf8.txt | tail -n2 | sed 
>> 's/^/tail&/'
>>
>> And I could see that tee exited due to the write on the fifo finishing
>> before the write to stdout and so the tail did not get all of the
>> file.  I consider that a normal behavior.  Yes, reading all of the
>> input and discarding it in the head process will allow tee to write
>> all of the output.  But that is a lot of extra data writing that is
>> wasteful and unused and simply thrown away and therefore I would avoid
>> doing it that way.
> I agree. However, if you use temporary file storage, it's worse. You 
> write it to disk instead of socket, and you read it from disk instead 
> of socket. Even if you write twice on socket instead of once to disk, 
> I think it's better. Further the performance point, you may not want 
> to use storage that you are not sure to get available : you don't know 
> how big is your input. By the way, you are sure to get available CPU.
>> Also since the background process is asynchronous the order of emitted
>> output isn't specified.  It is possible that the background process
>> would be scheduled later (kernel process scheduling) and then the
>> output of the two processes might appear in a different order.  It is
>> tickling a lot of possible problems.  Best to those avoid entirely.
> Either :
> 1) add wait :
>
> cat /tmp/fifo1|(head -n2;cat>/dev/null)|sed 's/^/head&/'&
> cat /usr/share/mysql/errmsg-utf8.txt|tee /tmp/fifo1|tail -n2|(wait;sed 
> 's/^/tail&/')
Ooops ! It works but it may go into deadlock. The waited event should be 
the end of head, not the end of cat.
>
> 2) be independent upon scheduling  :
>
> cat /tmp/fifo1|(head -n2;cat>/dev/null)>  /tmp/head&
> cat /usr/share/mysql/errmsg-utf8.txt|tee /tmp/fifo1|tail -n2>  /tmp/tail
>
>> The use of the term "abort" would usually mean 'man 3 abort', the
>> abort() system call.  That is the action that happens from various
>> signals.  But I think you are using it casually simpling meaning that
>> the program is exiting.  Read the man page for 'man 3 abort' and the
>> signals that cause an abort() to happen in 'man 7 signals' and then
>> please avoid using that word when we aren't talking about that event
>> so that it doesn't confuse us.  :-)
> While writing it I felt guilty but lazy, Sorry :)
> Thanks to be strict.
>>
>>> Also tried tee -i to ignore interrupts, but it is not the purpose of
>>> this option I suppose. No effect in our case.
>> The tee -i option only ignores SIGINT meant to avoid Control-C
>> interrupts.
>>
>> Whew!  So where are we?  I advise avoiding the background process
>> approach, for this particular case at least, as it isn't needed.  It
>> opens a large box of potential and real problems.
> Finally, when we write it correctly, it works, doesn't it ? With very 
> few code, we've solved Y.
>
> However my initial case was to extract a sheet from a calc document, 
> let the 4 first lines unsorted (table headers), sort the following 
> lines by a column value, then catenate the result and transform the 
> output into html table. And, for this case, it is better to use awk, 
> of course, instead of head -n4 and tail -n+4.  This is the X problem 
> solved. You were right :D
>
> Thibault


From MAILER-DAEMON Wed Oct 17 06:07:58 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TOQXe-0005Cw-DF
	for mharc-coreutils@gnu.org; Wed, 17 Oct 2012 06:07:58 -0400
Received: from eggs.gnu.org ([208.118.235.92]:50083)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TOQXX-000593-Th
	for coreutils@gnu.org; Wed, 17 Oct 2012 06:07:56 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TOQXP-00079R-Fc
	for coreutils@gnu.org; Wed, 17 Oct 2012 06:07:51 -0400
Received: from mx.meyering.net ([88.168.87.75]:57177)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TOQXP-00075x-8Z
	for coreutils@gnu.org; Wed, 17 Oct 2012 06:07:43 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id C6E98600AE;
	Wed, 17 Oct 2012 12:07:41 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: 8.20 release plan?
Date: Wed, 17 Oct 2012 12:07:41 +0200
Message-ID: <87y5j5s976.fsf@rho.meyering.net>
Lines: 48
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Paul Eggert <eggert@cs.ucla.edu>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 17 Oct 2012 10:07:56 -0000

Hi P=E1draig,

Would you please review this?

    [ cp: avoid data-corrupting free-memory-read ]
    http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/25139/focus=3D251=
51

That bug is obviously serious and the fix merits a prompt release.

What would you or anyone else like to see committed before the release?
Ondrej's df patch is overdue, but I haven't reviewed it, and now wonder
if it'd be better to defer it until after 8.20.  Without reviewing it,
however, I'm not well placed to estimate its risk/benefit ratio.

I will have less time for free software in the coming months (I'm
changing jobs and moving back to the US (San Francisco)), so help
with the backlog would be most welcome, even if it's just doing
triage (ping/add-"moreinfo"/close-if-fixed) on the bugs that have
been around for too long:

    http://debbugs.gnu.org/coreutils

Anyone can help.  Just send properly formatted mail messages per
these guidelines: http://debbugs.gnu.org/Using.html

Additional guidelines: closing a bug can seem harsh to the submitter,
so be gentle and give more explanation rather than less.  If a report
may be valid but lacks sufficient info, please request more info and
leave a record by applying the "moreinfo" tag.  Then, as is too often
the case, when there's no reply, we can go through and close the old
moreinfo-marked bugs.

Another way to help with bug triage that I've recently experimented
with is to use emacs' brand new debbugs interface.  To do that,
you may have to use a very recent version of emacs, like 24.2
or maybe even newer:

    http://ftp.gnu.org/gnu/emacs/emacs-24.2.tar.bz2
    http://ftp.gnu.org/gnu/emacs/emacs-24.2.tar.bz2.sig

I use the latest emacs built from git/bzr and put this in ~/.emacs:

    (setq debbugs-gnu-default-packages '("coreutils"))

With that, run this command to get a nice interactive
view onto the hundreds of open coreutils bugs:

    emacs --eval '(debbugs-gnu nil)'


From MAILER-DAEMON Wed Oct 17 06:23:27 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TOQmd-0002ak-Ig
	for mharc-coreutils@gnu.org; Wed, 17 Oct 2012 06:23:27 -0400
Received: from eggs.gnu.org ([208.118.235.92]:40609)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <kzak@redhat.com>) id 1TOQmW-0002a5-Jj
	for coreutils@gnu.org; Wed, 17 Oct 2012 06:23:26 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <kzak@redhat.com>) id 1TOQmV-00044s-CO
	for coreutils@gnu.org; Wed, 17 Oct 2012 06:23:20 -0400
Received: from mx1.redhat.com ([209.132.183.28]:62970)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <kzak@redhat.com>) id 1TOQmV-00044V-49
	for coreutils@gnu.org; Wed, 17 Oct 2012 06:23:19 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9HANH6m027862
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Wed, 17 Oct 2012 06:23:17 -0400
Received: from x2 (ovpn-113-69.phx2.redhat.com [10.3.113.69])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9HANGnI016905; Wed, 17 Oct 2012 06:23:17 -0400
Date: Wed, 17 Oct 2012 12:23:15 +0200
From: Karel Zak <kzak@redhat.com>
To: "Voelker, Bernhard" <bernhard.voelker@siemens-enterprise.com>
Subject: Re: Hide rootfs filesystem in df
Message-ID: <20121017102315.GA2092@x2.net.home>
References: <20120924104509.6825b8ec@viper.suse.cz>
	<A75C39900FCF0B42A2CE8B26F837D2C306C226@MCHP02MSX.global-ad.net>
	<20120924155240.63607bc0@viper.suse.cz>
	<A75C39900FCF0B42A2CE8B26F837D2C306C26A@MCHP02MSX.global-ad.net>
	<20120924164902.6a4af494@viper.suse.cz>
	<A75C39900FCF0B42A2CE8B26F837D2C306C2EA@MCHP02MSX.global-ad.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <A75C39900FCF0B42A2CE8B26F837D2C306C2EA@MCHP02MSX.global-ad.net>
User-Agent: Mutt/1.5.21 (2011-07-01)
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: Robert Milasan <rmilasan@suse.com>, "coreutils@gnu.org" <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 17 Oct 2012 10:23:26 -0000

On Mon, Sep 24, 2012 at 03:01:36PM +0000, Voelker, Bernhard wrote:
> Robert Milasan wrote:
>  
> > That has been fixed, at least in 12.1 and 12.2 (even if it's not fixed
> > there is not rootfs entry in /proc/self/mountinfo):
> 
> The problem is that mount from util-linux has it's own
> wrapper for the mount entries which is using mountinfo
> while coreutils' df is just calling get_fs_usage() from
> gnulib which in turn is reading /etc/mtab - which is
> a symlink to /proc/self/mounts in this case.
> And that file has both entries.
> 
> So the question is:
> * is it a kernel thing to not expose rootfs to
>   /proc/self/mounts?
> * should gnulib's get_fs_usage() switch to reading
>   mountinfo?
> * is it a gnulib thing to not filter the rootfs
>   entry?
> * is it up to coreutils to filter out the rootfs
>   entry?
> * should coreutils' df switch to reading mountinfo?

The reason why libmount reads the mountinfo file is that the file
provides more information (like FS root, mount Id, ...) necessary for
libmount. From my point of view the /proc/mounts should be enough for
programs like df(1) as you don't need any additional information.

I have doubts that rootfs entry is good reason to maintain another
parser.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


From MAILER-DAEMON Wed Oct 17 06:32:58 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TOQvq-0003o1-PK
	for mharc-coreutils@gnu.org; Wed, 17 Oct 2012 06:32:58 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58829)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TOQvj-0003n4-Rv
	for coreutils@gnu.org; Wed, 17 Oct 2012 06:32:57 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TOQvf-0006Pd-KC
	for coreutils@gnu.org; Wed, 17 Oct 2012 06:32:51 -0400
Received: from cantor2.suse.de ([195.135.220.15]:40156 helo=mx2.suse.de)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <rmilasan@suse.com>) id 1TOQvf-0006Nh-EK
	for coreutils@gnu.org; Wed, 17 Oct 2012 06:32:47 -0400
Received: from relay1.suse.de (unknown [195.135.220.254])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx2.suse.de (Postfix) with ESMTP id 2F1DC89994;
	Wed, 17 Oct 2012 12:32:45 +0200 (CEST)
Date: Wed, 17 Oct 2012 12:32:43 +0200
From: Robert Milasan <rmilasan@suse.com>
To: "Karel Zak" <kzak@redhat.com>
Subject: Re: Hide rootfs filesystem in df
Message-ID: <20121017123243.14013bb3@viper.suse.cz>
In-Reply-To: <20121017102315.GA2092@x2.net.home>
References: <20120924104509.6825b8ec@viper.suse.cz>
	<A75C39900FCF0B42A2CE8B26F837D2C306C226@MCHP02MSX.global-ad.net>
	<20120924155240.63607bc0@viper.suse.cz>
	<A75C39900FCF0B42A2CE8B26F837D2C306C26A@MCHP02MSX.global-ad.net>
	<20120924164902.6a4af494@viper.suse.cz>
	<A75C39900FCF0B42A2CE8B26F837D2C306C2EA@MCHP02MSX.global-ad.net>
	<20121017102315.GA2092@x2.net.home>
Organization: SUSE Linux
X-Mailer: Claws Mail 3.7.10 (GTK+ 2.24.7; x86_64-suse-linux-gnu)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6
X-Received-From: 195.135.220.15
Cc: "coreutils@gnu.org" <coreutils@gnu.org>,
	Bernhard Voelker <bernhard.voelker@siemens-enterprise.com>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 17 Oct 2012 10:32:57 -0000

On Wed, 17 Oct 2012 12:23:15 +0200
"Karel Zak" <kzak@redhat.com> wrote:
> 
> The reason why libmount reads the mountinfo file is that the file
> provides more information (like FS root, mount Id, ...) necessary for
> libmount. From my point of view the /proc/mounts should be enough for
> programs like df(1) as you don't need any additional information.
> 
> I have doubts that rootfs entry is good reason to maintain another
> parser.
> 
>     Karel
> 

Yes, that's why I just wrote a simple patch to hide the "rootfs" entry.
It's the most simple and functional way to do it.

-- 
Robert Milasan

L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmilasan@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A


From MAILER-DAEMON Wed Oct 17 12:09:35 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TOWBb-0007uy-0Q
	for mharc-coreutils@gnu.org; Wed, 17 Oct 2012 12:09:35 -0400
Received: from eggs.gnu.org ([208.118.235.92]:54119)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TOWBU-0007di-Lv
	for coreutils@gnu.org; Wed, 17 Oct 2012 12:09:32 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TOWBJ-0005fv-9M
	for coreutils@gnu.org; Wed, 17 Oct 2012 12:09:28 -0400
Received: from mx1.redhat.com ([209.132.183.28]:33006)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TOWBJ-0005fg-1N
	for coreutils@gnu.org; Wed, 17 Oct 2012 12:09:17 -0400
Received: from int-mx01.intmail.prod.int.phx2.redhat.com
	(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9HG98h9001403
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Wed, 17 Oct 2012 12:09:08 -0400
Received: from [10.36.116.67] (ovpn-116-67.ams2.redhat.com [10.36.116.67])
	by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9HG94Yl027973
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Wed, 17 Oct 2012 12:09:06 -0400
Message-ID: <507ED81F.7030505@draigBrady.com>
Date: Wed, 17 Oct 2012 09:09:03 -0700
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: 8.20 release plan?
References: <87y5j5s976.fsf@rho.meyering.net>
In-Reply-To: <87y5j5s976.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9HG98h9001403
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: Paul Eggert <eggert@cs.ucla.edu>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 17 Oct 2012 16:09:33 -0000

On 10/17/2012 03:07 AM, Jim Meyering wrote:
> Hi P=E1draig,
>
> Would you please review this?
>
>      [ cp: avoid data-corrupting free-memory-read ]
>      http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/25139/focus=3D=
25151

Thanks for handling this.
The fix looks good, and I can't see any other references
to the realloc'd memory that need to be updated.
That code is only enabled for sparse files at present
so maybe the NEWS might be adjusted slightly like:

  cp could read from freed memory and could even make corrupt copies.
  This could happen with a very fragmented and sparse input file,
  on GNU/Linux file systems supporting fiemap extent scanning.
  [bug introduced in coreutils-8.11]


> That bug is obviously serious and the fix merits a prompt release.
>
> What would you or anyone else like to see committed before the release?
> Ondrej's df patch is overdue, but I haven't reviewed it, and now wonder
> if it'd be better to defer it until after 8.20.  Without reviewing it,
> however, I'm not well placed to estimate its risk/benefit ratio.

We've 8 fixes now queued up, including this serious one.
So I agree we should do a new release with what we have.
http://git.sv.gnu.org/gitweb/?p=3Dcoreutils.git;a=3Dblob;f=3DNEWS;h=3Daff=
5bf1

I'm travelling at present, so I'll look at doing a release on Monday.

thanks!
P=E1draig.


From MAILER-DAEMON Wed Oct 17 12:20:04 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TOWLk-0002VV-0F
	for mharc-coreutils@gnu.org; Wed, 17 Oct 2012 12:20:04 -0400
Received: from eggs.gnu.org ([208.118.235.92]:56601)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TOWLe-0002TO-Gf
	for coreutils@gnu.org; Wed, 17 Oct 2012 12:20:03 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TOWLd-0000g5-AY
	for coreutils@gnu.org; Wed, 17 Oct 2012 12:19:58 -0400
Received: from mx.meyering.net ([88.168.87.75]:58130)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TOWLd-0000fw-2y
	for coreutils@gnu.org; Wed, 17 Oct 2012 12:19:57 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 538F7601AA;
	Wed, 17 Oct 2012 18:19:56 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: 8.20 release plan?
In-Reply-To: <507ED81F.7030505@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?=
	=?iso-8859-1?Q?g?= Brady"'s message of
	"Wed, 17 Oct 2012 09:09:03 -0700")
References: <87y5j5s976.fsf@rho.meyering.net> <507ED81F.7030505@draigBrady.com>
Date: Wed, 17 Oct 2012 18:19:56 +0200
Message-ID: <87k3upkr4j.fsf@rho.meyering.net>
Lines: 37
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Paul Eggert <eggert@cs.ucla.edu>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 17 Oct 2012 16:20:03 -0000

P=E1draig Brady wrote:
> On 10/17/2012 03:07 AM, Jim Meyering wrote:
>> Hi P=E1draig,
>>
>> Would you please review this?
>>
>>      [ cp: avoid data-corrupting free-memory-read ]
>>      http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/25139/focus=
=3D25151
>
> Thanks for handling this.
> The fix looks good, and I can't see any other references
> to the realloc'd memory that need to be updated.
> That code is only enabled for sparse files at present
> so maybe the NEWS might be adjusted slightly like:
>
>  cp could read from freed memory and could even make corrupt copies.
>  This could happen with a very fragmented and sparse input file,
>  on GNU/Linux file systems supporting fiemap extent scanning.
>  [bug introduced in coreutils-8.11]

Thanks.  I prefer that, too.  Amended and pushed,
along with a commit to update to the latest gnulib.

>> That bug is obviously serious and the fix merits a prompt release.
>>
>> What would you or anyone else like to see committed before the release?
>> Ondrej's df patch is overdue, but I haven't reviewed it, and now wonder
>> if it'd be better to defer it until after 8.20.  Without reviewing it,
>> however, I'm not well placed to estimate its risk/benefit ratio.
>
> We've 8 fixes now queued up, including this serious one.
> So I agree we should do a new release with what we have.
> http://git.sv.gnu.org/gitweb/?p=3Dcoreutils.git;a=3Dblob;f=3DNEWS;h=3Daff=
5bf1
>
> I'm travelling at present, so I'll look at doing a release on Monday.

Sounds good.  Thank you.


From MAILER-DAEMON Wed Oct 17 14:42:13 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TOYZJ-0002tp-8R
	for mharc-coreutils@gnu.org; Wed, 17 Oct 2012 14:42:13 -0400
Received: from eggs.gnu.org ([208.118.235.92]:38931)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TOYZE-0002nT-2m
	for coreutils@gnu.org; Wed, 17 Oct 2012 14:42:12 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TOYZC-00039i-It
	for coreutils@gnu.org; Wed, 17 Oct 2012 14:42:07 -0400
Received: from joseki.proulx.com ([216.17.153.58]:43054)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bob@proulx.com>) id 1TOYZC-00039K-B6
	for coreutils@gnu.org; Wed, 17 Oct 2012 14:42:06 -0400
Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119])
	by joseki.proulx.com (Postfix) with ESMTP id 713A0211DF;
	Wed, 17 Oct 2012 12:42:04 -0600 (MDT)
Received: by hysteria.proulx.com (Postfix, from userid 1000)
	id 410E22DCD1; Wed, 17 Oct 2012 12:42:04 -0600 (MDT)
Date: Wed, 17 Oct 2012 12:42:04 -0600
From: Bob Proulx <bob@proulx.com>
To: Thibault LE PAUL <tlepaul@aebs-tech.com>
Subject: Re: [head] wished an option to continue consuming the input after
	the specified number of lines has been read
Message-ID: <20121017184204.GA22534@hysteria.proulx.com>
Mail-Followup-To: Thibault LE PAUL <tlepaul@aebs-tech.com>, coreutils@gnu.org
References: <507B4842.3020408@aebs-tech.com>
	<20121015030315.GA14084@hysteria.proulx.com>
	<507BD518.7000702@aebs-tech.com>
	<20121016032009.GA15412@dismay.proulx.com>
	<507D15DF.7070703@aebs-tech.com>
	<20121016182507.GA19647@hysteria.proulx.com>
	<507DBC4D.8020304@aebs-tech.com> <507DBE7B.6010606@aebs-tech.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <507DBE7B.6010606@aebs-tech.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 216.17.153.58
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
Reply-To: coreutils@gnu.org
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 17 Oct 2012 18:42:12 -0000

Thibault LE PAUL wrote:
>Bob Proulx wrote:
> > Depending upon what you want to do I would do something like this
> > using sed to do the difference to either part.
> >
> >   $ seq 1 10 | sed '1,3s/^/head /;7,10s/^/tail /'
> >   $ seq 1 10 | sed -n '1,3s/^/head /p;7,9s/^/tail /p'
> >   $ seq 1 10 | awk 'NR<=3{print "head ",$0} NR>7{print "tail ",$0}'
>
>It's difficult that way without knowing a priori the line numbers,
>if you want the tail -n2 equivalent. I suppose that tail is using
>something like a rotating line buffer.

Ah...  Yes.  That is very true and a very compelling point.  I hadn't
considered that part of the problem.  Like directions that say "Turn
just before you can see barn."

> > And I could see that tee exited due to the write on the fifo finishing
> > before the write to stdout and so the tail did not get all of the
> > file.  I consider that a normal behavior.  Yes, reading all of the
> > input and discarding it in the head process will allow tee to write
> > all of the output.  But that is a lot of extra data writing that is
> > wasteful and unused and simply thrown away and therefore I would avoid
> > doing it that way.
>
> I agree. However, if you use temporary file storage, it's worse.

I agree about the temporary storage.  But I haven't been suggesting
using any temporary storage.  At least not yet. :-)

> You write it to disk instead of socket, and you read it from disk
> instead of socket. Even if you write twice on socket instead of
> once to disk, I think it's better. Further the performance point,
> you may not want to use storage that you are not sure to get
> available : you don't know how big is your input. By the way, you
> are sure to get available CPU.

Good point.

> > Also since the background process is asynchronous the order of emitted
> > output isn't specified.  It is possible that the background process
> > would be scheduled later (kernel process scheduling) and then the
> > output of the two processes might appear in a different order.  It is
> > tickling a lot of possible problems.  Best to those avoid entirely.
>
> Either :
> 1) add wait :
>
> cat /tmp/fifo1|(head -n2;cat>/dev/null)|sed 's/^/head&/'&
> cat /usr/share/mysql/errmsg-utf8.txt|tee /tmp/fifo1|tail -n2|(wait;sed 's/^/tail&/')

Very clever.

> Ooops ! It works but it may go into deadlock. The waited event
> should be the end of head, not the end of cat.

Yes.  An example of the types of complications that can occur.  But if
those are needed then they can be done.

> 2) be independent upon scheduling  :
>
> cat /tmp/fifo1|(head -n2;cat>/dev/null)>  /tmp/head&
> cat /usr/share/mysql/errmsg-utf8.txt|tee /tmp/fifo1|tail -n2>  /tmp/tail

Obviously this has the problems already discussed.  I prefer using
wait to join the forked process flow.

Bob


From MAILER-DAEMON Fri Oct 19 07:36:49 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TPAsj-0002Ta-3K
	for mharc-coreutils@gnu.org; Fri, 19 Oct 2012 07:36:49 -0400
Received: from eggs.gnu.org ([208.118.235.92]:38531)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TPAsa-0002QS-4h
	for coreutils@gnu.org; Fri, 19 Oct 2012 07:36:46 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TPAsX-0004XU-9O
	for coreutils@gnu.org; Fri, 19 Oct 2012 07:36:40 -0400
Received: from mx.meyering.net ([88.168.87.75]:35729)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>)
	id 1TPAsW-0004XQ-Rz; Fri, 19 Oct 2012 07:36:37 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id D9AA060128;
	Fri, 19 Oct 2012 13:36:35 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: coreutils@gnu.org
Subject: new snapshot available: coreutils-8.19.166-3131c
Mail-Followup-To: coreutils@gnu.org
Date: Fri, 19 Oct 2012 13:36:35 +0200
Message-ID: <874nlq1ynw.fsf@rho.meyering.net>
Lines: 309
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coordinator@translationproject.org, platform-testers@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 19 Oct 2012 11:36:46 -0000

We plan to release coreutils-8.20 early next week, so any testing
you can do between now and Monday would be most welcome.

Here's the NEWS:

  http://git.sv.gnu.org/cgit/coreutils.git/tree/NEWS

coreutils snapshot:
  http://meyering.net/cu/coreutils-ss.tar.xz      5.0 MB
  http://meyering.net/cu/coreutils-ss.tar.xz.sig
  http://meyering.net/cu/coreutils-8.19.166-3131c.tar.xz

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
Changes in coreutils since v8.19:

Benno Schulenberg (3):
      touch: line up long option in --help text
      dd: remove references to the word BLOCKS from help and texi docs
      doc: remove a stray parenthesis from 'cp --force' description

Bernhard Voelker (4):
      tests: correct print_ver_ arguments and add a rule to enforce this
      build: fix syntax-check rules broken by test-added .sh/pl suffixes
      maint: gen-lists-of-programs.sh: fix typo from previous comment edit
      maint: mbsalign.h: fix typo from previous comment edit

Eric Blake (2):
      build: work with new glibc when not optimizing
      build: default to --enable-gcc-warnings for git tree

Erik Auerswald (1):
      doc: escape double quotes in autotools-install --help

Jim Meyering (58):
      maint: post-release administrivia
      tests: don't require @acronym{...} around POSIX
      maint: stop using @acronym{...} in texinfo sources
      build: update gnulib submodule to latest
      tail,stat: improve support for ZFS
      scripts: git commit message hook: prohibit use of "Signed-off-by:"
      build: factor out a little more re list of *.texi files
      scripts: add autotools-install, for those stuck with outdated tools
      build: reenable just-moved/broken syntax-check rule
      scripts: fix the Signed-off-by:-prohibiting hook to actually work
      build: fix VPATH issues in C compilation
      maint: avoid distcheck failure by properly cleaning $(ALL_MANS)
      maint: check-programs-vs-x: avoid a new syntax-check failure
      build: make each man/prog.1 depend on src/prog, not src/prog.c
      build: restore handling of space-tainted build directory name
      maint: accommodate upcoming, expanded list of warnings from gnulib
      maint: disable sc_proper_name_utf8_requires_ICONV test
      tests: depend on the programs we're testing
      rm: avoid bogus diagnostic for a slash-decorated symlink-to-dir
      rm: be more careful when using a replacement errno value
      tail,stat: add support for VZFS
      tests: improve checks for setuidgid-using root-only tests
      factor: NEWS and tests
      maint: adjust ChangeLog to correct Author
      maint: move gl/m4/root-dev-ino.m4 contents into its module definition
      maint: move the last coreutils-specific files from lib/ to gl/
      build: fix a minor man-page generation dependency error
      build: do not require help2man at build-from-tarball time
      maint: gen-lists-of-programs.sh: improve comments
      maint: allow per-directory CFLAGS settings with non-recursive make
      build: new module to convert lib/ to non-recursive make
      build: handle @ALLOCA@-vs-non-recursive make problems
      build: build lib/ using non-recursive make
      tests: reenable "make -C tests ..." commands
      seq: 70x faster for non-negative whole numbers and incr=3D=3D1
      build: don't prefix the RHS of "GPERF =3D ..." with "lib/"
      build: do not rely on automake's AM_TESTS_ENVIRONMENT
      doc: update seq description
      doc: NEWS: mention the conversion to non-recursive make
      maint: make the tight-scope syntax-check rule work again
      tests: cp/link-heap: avoid new failure on rawhide
      maint: fix a comment typo
      rm: be even more careful when using a replacement errno value
      build: move non-recursive-gnulib-prefix-hack to gnulib; update
      tail,stat: improve support for vmhgfs
      doc: correct an old bit of ugliness in nice --help output
      doc: same correction, but now in texinfo documentation
      du: avoid abort on systems for which ->me_type is not malloc'd
      build: remove redundant dependency: $(PROGRAMS): lib/libcoreutils.a
      maint: make-prime-list: avoid -Wsuggest-attribute=3Dconst warning
      maint: make-prime-list: do not ignore write failure
      maint: make-prime-list: syntax conventions; be robust for large N
      factor: merge with preexisting factor; integrate tests; avoid warnings
      factor: 25% speed-up, on output
      build: avoid link failure when strerror is replaced
      maint: avoid warning from gcc's -Wunused-macros
      cp: avoid data-corrupting free-memory-read
      build: update gnulib submodule to latest

Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy (1):
      df: allow translators to reorder "1K-blocks" header

Nick Alcock (1):
      tests: fix misc/sort-exit-early to skip if root

Niels M=C3=B6ller (1):
      factor: more improvements

Nikolas Kallis (1):
      doc: improve HACKING guidelines

Ondrej Oprala (3):
      du: handle bind-mounted directory cycles gracefully
      md5sum, sha*sum: add --tag to output a format indicating the algorithm
      cp: fix the --no-preserve=3Dmode option

Pozs=C3=A1r Bal=C3=A1zs (1):
      dd: new option, status=3Dnone to suppress output statistics

P=C3=A1draig Brady (8):
      nproc: disallow non option command line parameters
      maint: add more control flags to mbsalign
      seq: enable the fast integer printing code in more cases
      ls: fix coloring of dangling symlinks in default listing mode
      timeout: handle signals more transparently
      doc: disambiguate the niceness explanation in nice --help
      build: support older GMP versions
      factor: fix integer validation and GMP fallback

Rob Day (1):
      rm: fix the new --dir (-d) option to work with -i

Stefano Lattarini (78):
      tests: remove useless defn of REPLACE_GETCWD from TESTS_ENVIRONMENT
      build: don't abuse Automake internals (with its 'check-am' rule)
      maint: slightly improve .gitignore
      build: add extra *.texi files to coreutils_TEXINFOS, not EXTRA_DIST
      build: prefer '$(top_srcdir)/doc' over '$(srcdir)' in doc Makefile
      build: use 'check-local' to extend the 'check' target
      build: don't use recursive make to build the 'doc' subdirectory
      build: don't define $(SUFFIXES) explicitly
      maint: simplify definition of $MAN in configure.ac
      build: add an explanatory comment
      build: fix a stray usage of uninitialized $(ME)
      build: rename common_dep -> mandep in man/Makefile
      maint: typofix: s/it's/its/
      build: rely on VPATH capabilities in man/Makefile
      build: make a rule less dependent on exact source tree layout
      build: provide convenience target 'all_programs' also at top-level
      build: rework some recipes in man/Makefile.am, for future changes
      build: don't use recursive make to build the 'man' subdirectory
      maint: move man-related syntax checks in cfg.mk
      maint: adjust syntax check 'check-x-vs-1'
      maint: adjust syntax check 'sc_option_desc_uppercase'
      maint: update gitignore entries
      build: enable the 'subdir-objects' Automake option globally
      tests: merge tests/check.mk into tests/Makefile.am
      tests: prefer AM_TESTS_ENVIRONMENT over TESTS_ENVIRONMENT
      build: require Automake >=3D 1.11.2
      tests: avoid use of '-T' in shebang line to enable perl taint mode
      tests: detect missing perl at configure runtime
      tests: add .sh and .pl suffixes to shell and perl tests, respectively
      tests: get rid of the 'shell-or-perl' auxiliary script
      maint: fixup: don't try to distribute a now-removed file
      build: move definition of 'all_programs' in cfg.mk
      build: some refactorings in cfg.mk
      build: don't use foo_LDADD if there's no foo program
      maint: remove unused variable in src/Makefile.am
      maint: more uses of $(ASSORT)
      build: don't use '$<' in non-suffix rules
      maint: get rid of obsolete script 'cvsu'
      maint: make required gettext version consistent
      maint: add our 'bootstrap_post_import_hook' function
      build: refactor how lists of coreutils programs are defined
      build: don't use recursive make to build the 'src' subdirectory
      build: fix generation of manpages for programs not built by default
      maint: improve remake rules for maintainers
      maint: remove unused target 'install-root'
      maint: fix and simplify maintainer checks
      maint: fix one stray reference to src/Makefile.am
      maint: update gitignore entries
      build: simplify: get rid of some indirection variables
      build: simplify and make more portable to non-GNU make
      build: one less unneeded make variable
      build: rename dist_man1_MANS -> man1_MANS
      build: simplify: get rid of yet some more indirection variables
      build: enhance man pages cleaning and dependencies
      build: $(mandeps): new, to factor out man pages dependencies
      maint: simplify declaration of "libexec" programs
      maint: port manpages generation to VPATH builds
      maint: fix build_programs definition not to use "make -C src ..."
      scripts: autotools-install: style and portability fixes
      scripts: autotools-install: allow user-specified make program
      build: use 'check-local' to extend the 'check' target
      maint: avoid parsing of Makefile.am from vc_exe_in_TESTS
      maint: remove useless dependency for vc_exe_in_TESTS
      maint: make vc_exe_in_TESTS also work in VPATH builds
      tests: use suffix, not exec-bit, to tell which files are tests
      tests: remove the unused 'root-hint' target
      maint: remove duplicated declaration of the 'sc_check-AUTHORS' target
      maint: remove anachronistic syntax-check
      maint: list of names of built programs available in the Makefiles
      build: don't use recursive make for tests/ subdirectory
      tests: put test-suite.log back in 'tests/'
      build: remove two now-useless convenience targets
      maint: vc_exe_in_TESTS should actually be a syntax check
      maint: avoid a spurious syntax-check error
      maint: fix syntax checks 'sc_root_tests'
      tests: more resilient about tainted absolute srcdir path
      maint: fix a spurious syntax-check failure
      build: fixup: correctly recognize if perl is missing

Torbj=C3=B6rn Granlund (3):
      factor: don't ever declare composites to be prime
      factor: prepare for the new factor program
      factor: new much-improved implementation; not yet integrated


Changes in gnulib since v8.19:

* gnulib bc33a8a...d245e6d (94):
  > euidaccess: speed up 'configure' on GNU hosts
  > * lib/regexec.c (re_search_internal): Fix grammar in comment.
  > fchmodat, fchownat, fstatat: port to non-inlining compilers
  > fchmodat.c, fchownat.c: fix compile-impeding typos
  > fcntl-h: support GNU flags like O_IGNORE_CTTY
  > faccessat, etc.: support AT_FDCWD-only use
  > faccessat: speed up 'configure' on mainstream hosts
  > faccessat: port to Solaris 10
  > canonicalize: fix C89 compilation
  > autoupdate
  > group-member: omit unnecessary dependencies
  > gethrxtime: port to C++
  > ptsname: fix macro-name typo
  > inttostr: Relax license.
  > ptsname_r: support ptys returned by FreeBSD posix_openpt
  > pselect: reject invalid file descriptors
  > select: reject invalid file descriptors
  > select: enhance test
  > ptsname: reject invalid file descriptors
  > hash-pjw-bare: new module
  > manywarnings: cater to more gcc infelicities
  > select, poll tests: Make setsockopt invocation effective.
  > sockets, sys_stat: restore AC_C_INLINE
  > localeconv tests: Avoid test failure on OpenIndiana.
  > havelib: Follow libtool developments.
  > ChangeLog: mention who reported the problem.
  > fstatat.c: fix a compile-impeding typo
  > extern-inline: provide a -Wundef safe config.h
  > hash-pjw: relax license to LGPLv2+
  > autoupdate
  > maint.mk: fix strict vs. lazy variable issues with RELEASE
  > maint.mk: formatting changes
  > maint.mk: provide "make upload" to ease uploading
  > maint.mk: factor the validation of RELEASE_TYPE
  > maint.mk: silent rules
  > localename: port gl_locale_name_thread_unsafe to FreeBSD
  > binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
  > pipe-filter-gi, pipe-filter-ii: better use of 'inline'
  > fdutimensat: omit unnecessary AC_C_INLINE
  > fchmodat, fchownat, fstatat: use extern-inline
  > acl, mbchar, priv-set: use extern-inline
  > sockets, sys_stat: remove AC_C_INLINE in MSVC-only cases
  > tls-tests: omit unnecessary 'inline'
  > utimens-tests: avoid unnecessary 'inline'
  > misc: don't limit commentary to inline functions
  > non-recursive-gnulib-prefix-hack: new module
  > ChangeLog: fix indentation
  > maint.mk: generalize _gl_tight_scope for non-recursive make
  > maint.mk: exempt trailing blanks found in "binary" files
  > maint.mk: sc_prohibit_path_max_allocation: don't FP for UNIX_PATH_MAX
  > maint.mk: teach sc_prohibit_magic_number_exit to accept 77
  > maint.mk: relax sc_prohibit_strcmp, to avoid a false positive
  > localcharset: work around Mac OS X bug with UTF-8 and MB_CUR_MAX
  > doc: document sticky-EOF issue
  > poll: fix poll(0, NULL, msec)
  > poll: fix for systems that can't recv() on a non-socket
  > poll/select: document portability problems not fixed by Gnulib.
  > update from texinfo
  > Fix typo in previous patch: 1 -> 4.
  > fcntl-h: check for AIX 7.1 bug with O_NOFOLLOW and O_CREAT
  > net_if: give more details about the bug being fixed
  > net_if: new module
  > readutmp: fix non-portable UT_PID use
  > update from texinfo
  > fts: reduce two or more trailing slashes to just one, usually
  > fts: when there is no risk of overlap, use memcpy, not memmove
  > autoupdate
  > autoupdate
  > manywarnings: update the list of "all" warnings
  > * lib/stdbool.in.h (_Bool) [__cplusplus]: bool, not _Bool.
  > stdbool: be more compatible with mixed C/C++ compiles
  > revert last change: it was not needed
  > tests: test-vc-list-files-git.sh: skip if git is not available
  > gnulib-tool: Remove no-op option --no-changelog.
  > autoupdate
  > doc: remove fdl-1.2.texi
  > execinfo: port to FreeBSD
  > xstrtol.h: avoid "_Noreturn is not at beginning of declaration" warning
  > doc: do not use @acronym
  > stdnoreturn: port to newer GCCs
  > pipe-filter: fix comment typo
  > execinfo: new module
  > extern-inline: support old GCC 'inline'
  > maint.mk: avoid redundant file name in message
  > timer-time: fix link order when static linking on glibc
  > timespec: omit unnecessary AC_C_INLINE
  > stat-time: omit unnecessary AC_C_INLINE
  > ignore-value: omit unnecessary AC_C_INLINE
  > sys_select: avoid 'static inline'
  > mktime: avoid 'static inline'
  > autoupdate
  > gnulib-tool: Improve coding style.
  > gnulib-tool: Fix indentation.
  > gnulib-tool: Remove old file names from .cvsignore, .gitignore.


From MAILER-DAEMON Fri Oct 19 17:53:10 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TPKVC-0007Dt-KN
	for mharc-coreutils@gnu.org; Fri, 19 Oct 2012 17:53:10 -0400
Received: from eggs.gnu.org ([208.118.235.92]:48409)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TPKV5-00078A-BY
	for coreutils@gnu.org; Fri, 19 Oct 2012 17:53:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TPKV1-0001NR-FB
	for coreutils@gnu.org; Fri, 19 Oct 2012 17:53:03 -0400
Received: from mx1.redhat.com ([209.132.183.28]:10609)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TPKV1-0001NJ-0e
	for coreutils@gnu.org; Fri, 19 Oct 2012 17:52:59 -0400
Received: from int-mx11.intmail.prod.int.phx2.redhat.com
	(int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9JLqs0e030313
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Fri, 19 Oct 2012 17:52:54 -0400
Received: from [10.11.9.196] (vpn-9-196.rdu.redhat.com [10.11.9.196])
	by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9JLqqF6032389; Fri, 19 Oct 2012 17:52:53 -0400
Message-ID: <5081CBB0.2020507@redhat.com>
Date: Fri, 19 Oct 2012 17:52:48 -0400
From: Daniel J Walsh <dwalsh@redhat.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121016 Thunderbird/16.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: Make mv work better with SELinux.
References: <50733664.5000503@redhat.com> <50733CC1.9000506@draigBrady.com>
	<87626jolel.fsf@rho.meyering.net> <507D5C87.3030501@redhat.com>
	<87wqyqwnik.fsf@rho.meyering.net>
In-Reply-To: <87wqyqwnik.fsf@rho.meyering.net>
X-Enigmail-Version: 1.4.5
Content-Type: multipart/mixed; boundary="------------040908060905070400030504"
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 19 Oct 2012 21:53:06 -0000

This is a multi-part message in MIME format.
--------------040908060905070400030504
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id q9JLqs0e030313

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/16/2012 09:32 AM, Jim Meyering wrote:
> Daniel J Walsh wrote:
>> On 10/09/2012 08:54 AM, Jim Meyering wrote:
>>> P=E1draig Brady wrote:
>>>> On 10/08/2012 09:24 PM, Daniel J Walsh wrote:
> ...
>>> [in a follow-up]
>>>> Thinking further, --context without an option, is not too clear to
>>>> the user. They might think they were copying the original context
>>>> rather than setting a new context.
>>>=20
>>>> Pity the long option wasn't called --new-context. I suppose we could
>>>> have that as an alias for --context and deprecate the former?
>>>=20
>>> Sounds reasonable. Adjust the other --context=3DCTX commands, mkdir,
>>> mkfifo, mknod at the same time.
>>=20
>> I just want to make sure that you guys are expecting a patch from me?
>=20
> I am.  That'd be great, especially if you can add NEWS entries and test=
s to
> exercise the new code.
>=20
Here is what I have thus far.  Major problem I have not figured out yet i=
s how
to get selinux.c code to work in the library, so it is hacked to just be
included as part of the selinux.h file.

Just looking to get feedback that I am not going down the wrong path.

Made -Z and --context take optional context for apps that have had these =
flags
for a while

mkdir, mkfifo, mknod and cp

Added -Z --context to mv without optional flag.  ( I would love to dump t=
he
optional flag but it has been in place for years.)

Not sure how man pages get created so I modified in patch.  Also modified=
 info
stuff.

Basically there are two new functions, restorecon which fixed file labels
after they are created, this is not optimal since there is a potential ra=
ce
condition, but since mv does a rename this is all we can do.

defaultcon will tell SELinux what to label a file before it is created.

I have added the function mode_to_security_class to libselinux for Fedora=
 18,
but it is not in all versions of libselinux.  I can back port this, but f=
or
now left it in patch.

This patch is based off of fedora package, not sure if I should have merg=
ed
all SELinux changes into patch to send upstream.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlCBy7AACgkQrlYvE4MpobPloACbBa6uiXbKzUs50is4rylABr6u
lXAAmQGsBJ0RYCiHBcHcCPdmUGz84IjD
=3DQ+pd
-----END PGP SIGNATURE-----

--------------040908060905070400030504
Content-Type: text/x-patch;
 name="coreutils-restorecon.patch"
Content-Disposition: attachment;
 filename="coreutils-restorecon.patch"
Content-Transfer-Encoding: 7bit

diff -up coreutils-8.19/doc/coreutils.texi.restorecon coreutils-8.19/doc/coreutils.texi
--- coreutils-8.19/doc/coreutils.texi.restorecon	2012-10-19 17:41:30.073219080 -0400
+++ coreutils-8.19/doc/coreutils.texi	2012-10-19 17:41:31.151219479 -0400
@@ -8629,13 +8629,13 @@ Program used to strip binaries.
 @opindex --verbose
 Print the name of each file before copying it.
 
-@item -Z @var{context}
-@itemx --context=@var{context}
+@item -Z [@var{context}]
+@itemx --context[=@var{context}]
 @opindex -Z
 @opindex --context
 @cindex SELinux
 @cindex security context
-Set the default SELinux security context to be used for any
+Use the default SELinux security context or use specified context to be used for any
 created files and directories.  If SELinux is disabled then
 print a warning and ignore the option.
 
@@ -8652,7 +8652,7 @@ print a warning and ignore the option.
 @command{mv} moves or renames files (or directories).  Synopses:
 
 @example
-mv [@var{option}]@dots{} [-T] @var{source} @var{dest}
+mv [@var{option}]@dots{} [-Z] [-T] @var{source} @var{dest}
 mv [@var{option}]@dots{} @var{source}@dots{} @var{directory}
 mv [@var{option}]@dots{} -t @var{directory} @var{source}@dots{}
 @end example
@@ -8762,6 +8762,15 @@ same source and destination.
 @opindex --verbose
 Print the name of each file before moving it.
 
+@item -Z [@var{context}]
+@itemx --context[=@var{context}]
+@opindex -Z
+@opindex --context
+@cindex SELinux
+@cindex security context
+Set the default SELinux security context on the destination.  If SELinux is disabled then
+print a warning and ignore the option.
+
 @optStripTrailingSlashes
 
 @optBackupSuffix
@@ -9557,13 +9566,13 @@ newly-created parent directories are inh
 Print a message for each created directory.  This is most useful with
 @option{--parents}.
 
-@item -Z @var{context}
-@itemx --context=@var{context}
+@item -Z [@var{context}]
+@itemx --context[=@var{context}]
 @opindex -Z
 @opindex --context
 @cindex SELinux
 @cindex security context
-Set the default SELinux security context to be used for created directories.
+Set the default SELinux security context or use specified context for created directories.
 
 @end table
 
@@ -9604,13 +9613,13 @@ Set the mode of created FIFOs to @var{mo
 for the point of departure.  @var{mode} should specify only file
 permission bits.  @xref{File permissions}.
 
-@item -Z @var{context}
-@itemx --context=@var{context}
+@item -Z [@var{context}]
+@itemx --context[=@var{context}]
 @opindex -Z
 @opindex --context
 @cindex SELinux
 @cindex security context
-Set the default SELinux security context to be used for created FIFOs.
+Set the default SELinux security context or use specified context for created FIFOs.
 
 @end table
 
@@ -9687,13 +9696,13 @@ Set the mode of created files to @var{mo
 @var{mode} should specify only file permission bits.
 @xref{File permissions}.
 
-@item -Z @var{context}
-@itemx --context=@var{context}
+@item -Z [@var{context}]
+@itemx --context[=@var{context}]
 @opindex -Z
 @opindex --context
 @cindex SELinux
 @cindex security context
-Set the default SELinux security context to be used for created files.
+Set the default SELinux security context or use specified context for created files.
 
 @end table
 
diff -up coreutils-8.19/lib/selinux.c.restorecon coreutils-8.19/lib/selinux.c
--- coreutils-8.19/lib/selinux.c.restorecon	2012-10-19 15:37:13.460218486 -0400
+++ coreutils-8.19/lib/selinux.c	2012-10-19 15:37:13.461218487 -0400
@@ -0,0 +1,181 @@
+#include <selinux/selinux.h>
+#include <selinux/context.h>
+#include <libgen.h>
+#include "fts.h"
+security_class_t mode_to_security_class(mode_t m) {
+
+  if (S_ISREG(m))
+    return string_to_security_class("file");
+  if (S_ISDIR(m))
+    return string_to_security_class("dir");
+  if (S_ISCHR(m))
+    return string_to_security_class("chr_file");
+  if (S_ISBLK(m))
+    return string_to_security_class("blk_file");
+  if (S_ISFIFO(m))
+    return string_to_security_class("fifo_file");
+  if (S_ISLNK(m))
+    return string_to_security_class("lnk_file");
+  if (S_ISSOCK(m))
+    return string_to_security_class("sock_file");
+
+  errno=EINVAL;
+  return 0;
+}
+
+static int computecon(char const *path, mode_t mode, security_context_t *con) {
+  security_context_t scon = NULL;
+  security_context_t tcon = NULL;
+  security_class_t tclass;
+  int rc = -1;
+  
+  char *dir = strdup(path);
+  if (!dir) 
+    goto quit;
+  if (getcon(&scon) < 0)
+    goto quit;
+  if (getfilecon(dirname((char *) dir), &tcon) < 0)
+    goto quit;
+  tclass = mode_to_security_class(mode);
+  if (!tclass)
+    goto quit;
+  rc = security_compute_create(scon, tcon, tclass, con);
+
+quit:
+  free(dir);
+  freecon(scon);
+  freecon(tcon);
+  return rc;
+}
+
+int defaultcon (char const *path, mode_t mode) {
+  int rc = -1;
+  struct stat sb;
+  security_context_t scon = NULL, tcon = NULL;
+  context_t scontext = NULL, tcontext = NULL;
+  int fd;
+
+  rc = matchpathcon(path, mode,  &scon);
+  if (rc < 0)
+    goto quit;
+  rc = computecon(path, mode,  &tcon);
+  if (rc < 0)
+    goto quit;
+  scontext = context_new(scon);
+  rc = -1;
+  if (!scontext)
+    goto quit;
+  tcontext = context_new(tcon);
+  if (!tcontext)
+    goto quit;
+
+  context_type_set(tcontext, context_type_get(scontext));
+  rc = setfscreatecon (context_str(tcontext));
+//  printf("defaultcon %s %s\n", path, context_str(tcontext));
+quit:
+  close(fd);
+  if (scontext)
+    context_free(scontext);
+  if (scontext)
+    context_free(tcontext);
+  freecon(scon);
+  freecon(tcon);
+  return rc;
+}
+
+static int restorecon_private (char const *path) {
+  int rc = -1;
+  int link_file = false;
+  struct stat sb;
+  security_context_t scon = NULL, tcon = NULL;
+  context_t scontext = NULL, tcontext = NULL;
+  int fd;
+  fd = open (path, O_RDONLY | O_NOFOLLOW);
+  if (!fd && (errno != ELOOP)) 
+    goto quit;
+
+  if (fd) {
+    rc = fstat (fd, &sb);
+    if (rc < 0)
+      goto quit;
+  } else {
+    rc = lstat (path, &sb);
+    if (rc < 0)
+      goto quit;
+  }
+  
+  rc = matchpathcon(path, sb.st_mode,  &scon);
+  if (rc < 0)
+    goto quit;
+  scontext = context_new(scon);
+  rc = -1;
+  if (!scontext)
+    goto quit;
+
+  if (fd) {
+    rc = fgetfilecon (fd, &tcon);
+    if (!rc)
+      goto quit;
+  } else  {
+    rc = lgetfilecon (path, &tcon);
+    if (!rc)
+      goto quit;
+  }
+  tcontext = context_new(tcon);
+  if (!tcontext)
+    goto quit;
+
+  context_type_set(tcontext, context_type_get(scontext));
+
+  if (fd)
+        rc = fsetfilecon (fd, context_str(tcontext));
+  else
+        rc = lsetfilecon (path, context_str(tcontext));
+
+//  printf("restorcon %s %s\n", path, context_str(tcontext));
+quit:
+  close(fd);
+  if (scontext)
+    context_free(scontext);
+  if (scontext)
+    context_free(tcontext);
+  freecon(scon);
+  freecon(tcon);
+  return rc;
+}
+
+int restorecon (char const *path, int recurse) {
+  if (!recurse)
+    return restorecon_private(path);
+  const char *mypath[2] = { path, NULL };
+
+  FTS *fts = fts_open ((char *const *)mypath, FTS_PHYSICAL, NULL);
+  bool ok = true;
+
+  while (1)
+    {
+      FTSENT *ent;
+
+      ent = fts_read (fts);
+      if (ent == NULL)
+        {
+          if (errno != 0)
+            {
+              /* FIXME: try to give a better message  */
+              error (0, errno, _("fts_read failed"));
+              ok = false;
+            }
+          break;
+        }
+
+      ok &= restorecon_private(fts->fts_path);
+    }
+
+  if (fts_close (fts) != 0)
+    {
+      error (0, errno, _("fts_close failed"));
+      ok = false;
+    }
+
+  return ok;
+}
diff -up coreutils-8.19/lib/selinux.h.restorecon coreutils-8.19/lib/selinux.h
--- coreutils-8.19/lib/selinux.h.restorecon	2012-10-19 15:37:13.461218487 -0400
+++ coreutils-8.19/lib/selinux.h	2012-10-19 15:37:13.462218488 -0400
@@ -0,0 +1,28 @@
+/* Handle SELinux Labeling
+
+   Copyright (C) 2012 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 <http://www.gnu.org/licenses/>.  */
+
+/* Written by Daniel Walsh <dwalsh@redhat.com>. */
+
+#ifndef _GL_SELINUX_H
+#define _GL_SELINUX_H
+
+#include <sys/stat.h>
+int restorecon (char const *path, int recurse);
+int defaultcon (char const *path, mode_t mode);
+#include "selinux.c"
+#endif
diff -up coreutils-8.19/man/cp.1.restorecon coreutils-8.19/man/cp.1
--- coreutils-8.19/man/cp.1.restorecon	2012-08-20 02:14:14.000000000 -0400
+++ coreutils-8.19/man/cp.1	2012-10-19 17:14:38.831525002 -0400
@@ -1,5 +1,5 @@
 .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.35.
-.TH CP "1" "August 2012" "GNU coreutils 8.19" "User Commands"
+.TH CP "1" "October 2012" "GNU coreutils 8.19" "User Commands"
 .SH NAME
 cp \- copy files and directories
 .SH SYNOPSIS
@@ -70,6 +70,9 @@ mode,ownership,timestamps), if possible
 additional attributes: context, links, xattr,
 all
 .TP
+\fB\-c\fR
+same as \fB\-\-preserve\fR=\fIcontext\fR
+.TP
 \fB\-\-no\-preserve\fR=\fIATTR_LIST\fR
 don't preserve the specified attributes
 .TP
@@ -116,6 +119,9 @@ explain what is being done
 \fB\-x\fR, \fB\-\-one\-file\-system\fR
 stay on this file system
 .TP
+\fB\-Z\fR, \fB\-\-context[\fR=\fICONTEXT\fR]
+set default SELinux security context or specified CONTEXT on DEST
+.TP
 \fB\-\-help\fR
 display this help and exit
 .TP
diff -up coreutils-8.19/man/mkdir.1.restorecon coreutils-8.19/man/mkdir.1
--- coreutils-8.19/man/mkdir.1.restorecon	2012-08-20 02:14:14.000000000 -0400
+++ coreutils-8.19/man/mkdir.1	2012-10-19 17:16:15.433585135 -0400
@@ -21,9 +21,9 @@ no error if existing, make parent direct
 \fB\-v\fR, \fB\-\-verbose\fR
 print a message for each created directory
 .TP
-\fB\-Z\fR, \fB\-\-context\fR=\fICTX\fR
-set the SELinux security context of each created
-directory to CTX
+\fB\-Z\fR, \fB\-\-context\fR[=\fICTX\fR]
+set default SELinux security context or specified CTX on each created
+directory
 .TP
 \fB\-\-help\fR
 display this help and exit
diff -up coreutils-8.19/man/mkfifo.1.restorecon coreutils-8.19/man/mkfifo.1
--- coreutils-8.19/man/mkfifo.1.restorecon	2012-08-20 02:14:14.000000000 -0400
+++ coreutils-8.19/man/mkfifo.1	2012-10-19 17:16:39.195594030 -0400
@@ -15,8 +15,9 @@ Mandatory arguments to long options are
 \fB\-m\fR, \fB\-\-mode\fR=\fIMODE\fR
 set file permission bits to MODE, not a=rw \- umask
 .TP
-\fB\-Z\fR, \fB\-\-context\fR=\fICTX\fR
-set the SELinux security context of each NAME to CTX
+\fB\-Z\fR, \fB\-\-context\fR[=\fICTX\fR]
+set default SELinux security context or specified CTX on each created
+fifo
 .TP
 \fB\-\-help\fR
 display this help and exit
diff -up coreutils-8.19/man/mknod.1.restorecon coreutils-8.19/man/mknod.1
--- coreutils-8.19/man/mknod.1.restorecon	2012-08-20 02:14:14.000000000 -0400
+++ coreutils-8.19/man/mknod.1	2012-10-19 17:17:51.271623069 -0400
@@ -15,8 +15,9 @@ Mandatory arguments to long options are
 \fB\-m\fR, \fB\-\-mode\fR=\fIMODE\fR
 set file permission bits to MODE, not a=rw \- umask
 .TP
-\fB\-Z\fR, \fB\-\-context\fR=\fICTX\fR
-set the SELinux security context of NAME to CTX
+\fB\-Z\fR, \fB\-\-context\fR[=\fICTX\fR]
+set default SELinux security context or specified CTX on each created
+special file
 .TP
 \fB\-\-help\fR
 display this help and exit
diff -up coreutils-8.19/man/mv.1.restorecon coreutils-8.19/man/mv.1
--- coreutils-8.19/man/mv.1.restorecon	2012-10-19 17:08:27.601158408 -0400
+++ coreutils-8.19/man/mv.1	2012-10-19 17:11:47.591357536 -0400
@@ -56,6 +56,9 @@ destination file is missing
 \fB\-v\fR, \fB\-\-verbose\fR
 explain what is being done
 .TP
+\fB\-Z\fR, \fB\-\-context
+set default SELinux security context on DEST
+.TP
 \fB\-\-help\fR
 display this help and exit
 .TP
diff -up coreutils-8.19/src/copy.c.restorecon coreutils-8.19/src/copy.c
--- coreutils-8.19/src/copy.c.restorecon	2012-10-19 15:37:13.452218478 -0400
+++ coreutils-8.19/src/copy.c	2012-10-19 15:37:13.466218492 -0400
@@ -22,6 +22,7 @@
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <selinux/selinux.h>
+#include <selinux/context.h>
 
 #if HAVE_HURD_H
 # include <hurd.h>
@@ -60,6 +61,7 @@
 #include "write-any-file.h"
 #include "areadlink.h"
 #include "yesno.h"
+#include "selinux.h"
 
 #if USE_XATTR
 # include <attr/error_context.h>
@@ -844,34 +846,37 @@ copy_reg (char const *src_name, char con
           bool some_errors = !all_errors && !x->reduce_diagnostics;
           security_context_t con = NULL;
 
-          if (getfscreatecon (&con) < 0)
-            {
-              if (all_errors || (some_errors && !errno_unsupported (errno)))
-                error (0, errno, _("failed to get file system create context"));
-              if (x->require_preserve_context)
-                {
-                  return_val = false;
-                  goto close_src_and_dst_desc;
-                }
-            }
+          if (x->preserve_security_context) {
+                  if (getfscreatecon (&con) < 0)
+                  {
+                          if (all_errors || (some_errors && !errno_unsupported (errno)))
+                                  error (0, errno, _("failed to get file system create context"));
+                          return_val = false;
+                          goto close_src_and_dst_desc;
+                  }
+          } else {
+                  if (matchpathcon(dst_name, dst_mode,  &con) < 0) {
+                          if (all_errors || (some_errors && !errno_unsupported (errno)))
+                                  error (0, errno, _("failed to get file system create context"));
+                          return_val = false;
+                          goto close_src_and_dst_desc;
+                  }
+          }
 
-          if (con)
-            {
-              if (fsetfilecon (dest_desc, con) < 0)
-                {
+          if (fsetfilecon (dest_desc, con) < 0)
+          {
                   if (all_errors || (some_errors && !errno_unsupported (errno)))
-                    error (0, errno,
-                           _("failed to set the security context of %s to %s"),
-                           quote_n (0, dst_name), quote_n (1, con));
+                          error (0, errno,
+                                 _("failed to set the security context of %s to %s"),
+                                 quote_n (0, dst_name), quote_n (1, con));
                   if (x->require_preserve_context)
-                    {
-                      return_val = false;
-                      freecon (con);
-                      goto close_src_and_dst_desc;
-                    }
-                }
-              freecon (con);
-            }
+                  {
+                          return_val = false;
+                          freecon (con);
+                          goto close_src_and_dst_desc;
+                  }
+          }
+          freecon (con);
         }
 
       if (dest_desc < 0 && x->unlink_dest_after_failed_open)
@@ -892,6 +897,9 @@ copy_reg (char const *src_name, char con
 
   if (*new_dst)
     {
+      if (x->set_security_context && (! x->require_preserve_context))
+        defaultcon(dst_name, dst_mode);
+
     open_with_O_CREAT:;
 
       int open_flags = O_WRONLY | O_CREAT | O_BINARY;
@@ -936,6 +944,7 @@ copy_reg (char const *src_name, char con
       if (dest_desc < 0 && dest_errno == EISDIR
           && *dst_name && dst_name[strlen (dst_name) - 1] == '/')
         dest_errno = ENOTDIR;
+
     }
   else
     {
@@ -974,6 +983,9 @@ copy_reg (char const *src_name, char con
       goto close_src_and_dst_desc;
     }
 
+  if (x->set_security_context && ! x->preserve_security_context)
+    restorecon(dst_name, 1);
+
   /* --attributes-only overrides --reflink.  */
   if (data_copy_required && x->reflink_mode)
     {
@@ -2087,6 +2099,9 @@ copy_internal (char const *src_name, cha
             emit_verbose (src_name, dst_name,
                           backup_succeeded ? dst_backup : NULL);
 
+          if (x->set_security_context)
+            restorecon(dst_name, 1);
+
           if (rename_succeeded)
             *rename_succeeded = true;
 
@@ -2226,6 +2241,11 @@ copy_internal (char const *src_name, cha
             return false;
         }
     }
+  else
+  {
+    if (x->set_security_context)
+      restorecon(dst_name, 1);
+  }
 
   if (S_ISDIR (src_mode))
     {
diff -up coreutils-8.19/src/cp.c.restorecon coreutils-8.19/src/cp.c
--- coreutils-8.19/src/cp.c.restorecon	2012-10-19 15:37:13.453218479 -0400
+++ coreutils-8.19/src/cp.c	2012-10-19 15:37:13.467218493 -0400
@@ -141,7 +141,7 @@ static struct option const long_opts[] =
   {"target-directory", required_argument, NULL, 't'},
   {"update", no_argument, NULL, 'u'},
   {"verbose", no_argument, NULL, 'v'},
-  {"context", required_argument, NULL, 'Z'},
+  {GETOPT_SELINUX_CONTEXT_OPTION_DECL},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -233,7 +233,7 @@ Mandatory arguments to long options are
                                  destination file is missing\n\
   -v, --verbose                explain what is being done\n\
   -x, --one-file-system        stay on this file system\n\
-  -Z, --context=CONTEXT        set security context of copy to CONTEXT\n\
+  -Z, --context[=CONTEXT]      set security context of destination file to default type or to CONTEXT if specified\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -881,8 +881,10 @@ decode_preserve_arg (char const *arg, st
           break;
 
         case PRESERVE_CONTEXT:
-          x->preserve_security_context = on_off;
-          x->require_preserve_context = on_off;
+          if (! x->set_security_context) {
+            x->preserve_security_context = on_off;
+            x->require_preserve_context = on_off;
+          }
           break;
 
         case PRESERVE_XATTR:
@@ -895,7 +897,7 @@ decode_preserve_arg (char const *arg, st
           x->preserve_timestamps = on_off;
           x->preserve_ownership = on_off;
           x->preserve_links = on_off;
-          if (selinux_enabled)
+          if (selinux_enabled && (! x->set_security_context))
             x->preserve_security_context = on_off;
           x->preserve_xattr = on_off;
           break;
@@ -938,7 +940,7 @@ main (int argc, char **argv)
      we'll actually use backup_suffix_string.  */
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
 
-  while ((c = getopt_long (argc, argv, "abcdfHilLnprst:uvxPRS:TZ:",
+  while ((c = getopt_long (argc, argv, "abcdfHilLnprst:uvxPRS:TZ::",
                            long_opts, NULL))
          != -1)
     {
@@ -965,7 +967,7 @@ main (int argc, char **argv)
           x.preserve_mode = true;
           x.preserve_timestamps = true;
           x.require_preserve = true;
-          if (selinux_enabled)
+          if (selinux_enabled && (! x.set_security_context))
              x.preserve_security_context = true;
           x.preserve_xattr = true;
           x.reduce_diagnostics = true;
@@ -1113,18 +1115,16 @@ main (int argc, char **argv)
                               "It requires a SELinux enabled kernel.\n" );
              break;
          }
-         if ( x.preserve_security_context ) {
-            (void) fprintf(stderr, "%s: cannot force target context to '%s' and preserve it\n", argv[0], optarg);
-            exit( 1 );
-         }
+         if (optarg) {
+           /* if there's a security_context given set new path 
+              components to that context, too */
+           if ( setfscreatecon(optarg) < 0 ) {
+             (void) fprintf(stderr, _("cannot set default security context %s\n"), optarg);
+             exit( 1 );
+           }
+         } 
          x.set_security_context = true;
-         (void) fprintf(stderr, _("Warning, -Z/--context option is deprecated and will be removed soon!\nPlease use 'install' utility instead of cp for this functionality.\n"));
-         /* if there's a security_context given set new path 
-            components to that context, too */
-         if ( setfscreatecon(optarg) < 0 ) {
-            (void) fprintf(stderr, _("cannot set default security context %s\n"), optarg);
-            exit( 1 );
-         }
+         x.preserve_security_context = false;
          break;
 
         case 'S':
diff -up coreutils-8.19/src/install.c.restorecon coreutils-8.19/src/install.c
--- coreutils-8.19/src/install.c.restorecon	2012-10-19 15:37:13.415218441 -0400
+++ coreutils-8.19/src/install.c	2012-10-19 15:37:13.468218494 -0400
@@ -641,7 +641,7 @@ Mandatory arguments to long options are
 "), stdout);
       fputs (_("\
   -P, --preserve-context  preserve SELinux security context\n\
-  -Z, --context=CONTEXT  set SELinux security context of files and directories\
+  -Z, --context[=CONTEXT] set SELinux security context of files and directories\
 \n\
 "), stdout);
 
@@ -783,7 +783,7 @@ main (int argc, char **argv)
      we'll actually use backup_suffix_string.  */
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
 
-  while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pPt:TvS:Z:", long_options,
+  while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pPt:TvS:Z::", long_options,
                               NULL)) != -1)
     {
       switch (optc)
@@ -861,12 +861,11 @@ main (int argc, char **argv)
                              "this kernel is not SELinux-enabled"));
               break;
             }
-          if ( x.set_security_context ) {
+          if ( x.set_security_context || scontext ) {
              (void) fprintf(stderr, "%s: cannot force target context and preserve it\n", argv[0]);
              exit( 1 );
           }
           x.preserve_security_context = true;
-          use_default_selinux_context = false;
           break;
         case 'Z':
           if ( ! selinux_enabled)
@@ -875,9 +874,10 @@ main (int argc, char **argv)
                              "this kernel is not SELinux-enabled"));
               break;
             }
-          scontext = optarg;
-          x.set_security_context = true;
-          use_default_selinux_context = false;
+          if (optarg) 
+                  scontext = optarg;
+          else
+                  x.set_security_context = true;
           break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
diff -up coreutils-8.19/src/mkdir.c.restorecon coreutils-8.19/src/mkdir.c
--- coreutils-8.19/src/mkdir.c.restorecon	2012-10-19 15:37:13.420218446 -0400
+++ coreutils-8.19/src/mkdir.c	2012-10-19 15:37:13.469218495 -0400
@@ -29,6 +29,7 @@
 #include "prog-fprintf.h"
 #include "quote.h"
 #include "savewd.h"
+#include "selinux.h"
 
 /* The official name of this program (e.g., no 'g' prefix).  */
 #define PROGRAM_NAME "mkdir"
@@ -38,7 +39,6 @@
 static struct option const longopts[] =
 {
   {GETOPT_SELINUX_CONTEXT_OPTION_DECL},
-  {"context", required_argument, NULL, 'Z'},
   {"mode", required_argument, NULL, 'm'},
   {"parents", no_argument, NULL, 'p'},
   {"verbose", no_argument, NULL, 'v'},
@@ -66,8 +66,8 @@ Mandatory arguments to long options are
   -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask\n\
   -p, --parents     no error if existing, make parent directories as needed\n\
   -v, --verbose     print a message for each created directory\n\
-  -Z, --context=CTX  set the SELinux security context of each created\n\
-                      directory to CTX\n\
+  -Z, --context[=CTX]  set the SELinux security context of each created\n\
+                      directory to default type or to CTX if specified\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -92,6 +92,9 @@ struct mkdir_options
   /* File mode bits affected by MODE.  */
   mode_t mode_bits;
 
+  /* Set the SELinux File Context.  */
+  int set_security_context;
+
   /* If not null, format to use when reporting newly made directories.  */
   char const *created_directory_format;
 };
@@ -114,6 +117,9 @@ static int
 make_ancestor (char const *dir, char const *component, void *options)
 {
   struct mkdir_options const *o = options;
+
+  if (o->set_security_context)
+    defaultcon(dir, S_IFDIR);
   int r = mkdir (component, o->ancestor_mode);
   if (r == 0)
     {
@@ -147,6 +153,7 @@ main (int argc, char **argv)
   options.mode = S_IRWXUGO;
   options.mode_bits = 0;
   options.created_directory_format = NULL;
+  options.set_security_context = false;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -156,7 +163,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  while ((optc = getopt_long (argc, argv, "pm:vZ:", longopts, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "pm:vZ::", longopts, NULL)) != -1)
     {
       switch (optc)
         {
@@ -170,7 +177,10 @@ main (int argc, char **argv)
           options.created_directory_format = _("created directory %s");
           break;
         case 'Z':
-          scontext = optarg;
+          if (optarg)
+            scontext = optarg;
+          else 
+            options.set_security_context = true;
           break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
diff -up coreutils-8.19/src/mkfifo.c.restorecon coreutils-8.19/src/mkfifo.c
--- coreutils-8.19/src/mkfifo.c.restorecon	2012-07-21 10:54:31.000000000 -0400
+++ coreutils-8.19/src/mkfifo.c	2012-10-19 15:37:13.470218496 -0400
@@ -26,6 +26,7 @@
 #include "error.h"
 #include "modechange.h"
 #include "quote.h"
+#include "selinux.h"
 
 /* The official name of this program (e.g., no 'g' prefix).  */
 #define PROGRAM_NAME "mkfifo"
@@ -60,7 +61,7 @@ Mandatory arguments to long options are
   -m, --mode=MODE    set file permission bits to MODE, not a=rw - umask\n\
 "), stdout);
       fputs (_("\
-  -Z, --context=CTX  set the SELinux security context of each NAME to CTX\n\
+  -Z, --context[=CTX]  set the SELinux security context of each NAME to default type or CTX if specified\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -74,6 +75,7 @@ main (int argc, char **argv)
 {
   mode_t newmode;
   char const *specified_mode = NULL;
+  int set_security_context = false;
   int exit_status = EXIT_SUCCESS;
   int optc;
   security_context_t scontext = NULL;
@@ -86,7 +88,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  while ((optc = getopt_long (argc, argv, "m:Z:", longopts, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "m:Z::", longopts, NULL)) != -1)
     {
       switch (optc)
         {
@@ -94,7 +96,10 @@ main (int argc, char **argv)
           specified_mode = optarg;
           break;
         case 'Z':
-          scontext = optarg;
+          if (optarg)
+            scontext = optarg;
+          else 
+            set_security_context = true;
           break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -128,6 +133,8 @@ main (int argc, char **argv)
     }
 
   for (; optind < argc; ++optind)
+    if (set_security_context)
+      defaultcon(argv[optind], S_IFIFO);
     if (mkfifo (argv[optind], newmode) != 0)
       {
         error (0, errno, _("cannot create fifo %s"), quote (argv[optind]));
diff -up coreutils-8.19/src/mknod.c.restorecon coreutils-8.19/src/mknod.c
--- coreutils-8.19/src/mknod.c.restorecon	2012-10-19 15:37:13.420218446 -0400
+++ coreutils-8.19/src/mknod.c	2012-10-19 15:37:13.471218497 -0400
@@ -27,6 +27,7 @@
 #include "modechange.h"
 #include "quote.h"
 #include "xstrtol.h"
+#include "selinux.h"
 
 /* The official name of this program (e.g., no 'g' prefix).  */
 #define PROGRAM_NAME "mknod"
@@ -62,7 +63,7 @@ Mandatory arguments to long options are
   -m, --mode=MODE    set file permission bits to MODE, not a=rw - umask\n\
 "), stdout);
       fputs (_("\
-  -Z, --context=CTX  set the SELinux security context of NAME to CTX\n\
+  -Z, --context[=CTX]  set the SELinux security context of NAME to default type or to CTX if specified\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -94,6 +95,7 @@ main (int argc, char **argv)
   int expected_operands;
   mode_t node_type;
   security_context_t scontext = NULL;
+  int set_security_context = false;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -103,7 +105,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  while ((optc = getopt_long (argc, argv, "m:Z:", longopts, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "m:Z::", longopts, NULL)) != -1)
     {
       switch (optc)
         {
@@ -111,7 +113,10 @@ main (int argc, char **argv)
           specified_mode = optarg;
           break;
         case 'Z':
-          scontext = optarg;
+          if (optarg)
+            scontext = optarg;
+          else 
+            set_security_context = true;
           break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -212,6 +217,9 @@ main (int argc, char **argv)
           error (EXIT_FAILURE, 0, _("invalid device %s %s"), s_major, s_minor);
 #endif
 
+        if (set_security_context)
+          defaultcon(argv[optind], node_type);
+        
         if (mknod (argv[optind], newmode | node_type, device) != 0)
           error (EXIT_FAILURE, errno, "%s", quote (argv[optind]));
       }
diff -up coreutils-8.19/src/mv.c.restorecon coreutils-8.19/src/mv.c
--- coreutils-8.19/src/mv.c.restorecon	2012-10-19 15:37:13.421218447 -0400
+++ coreutils-8.19/src/mv.c	2012-10-19 15:37:13.472218498 -0400
@@ -55,6 +55,7 @@ static bool remove_trailing_slashes;
 static struct option const long_options[] =
 {
   {"backup", optional_argument, NULL, 'b'},
+  {"context", no_argument, NULL, 'Z'},
   {"force", no_argument, NULL, 'f'},
   {"interactive", no_argument, NULL, 'i'},
   {"no-clobber", no_argument, NULL, 'n'},
@@ -351,6 +352,7 @@ main (int argc, char **argv)
   bool no_target_directory = false;
   int n_files;
   char **file;
+  bool selinux_enabled = (0 < is_selinux_enabled ());
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -369,7 +371,7 @@ main (int argc, char **argv)
      we'll actually use backup_suffix_string.  */
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
 
-  while ((c = getopt_long (argc, argv, "bfint:uvS:T", long_options, NULL))
+  while ((c = getopt_long (argc, argv, "bfint:uvS:TZ", long_options, NULL))
          != -1)
     {
       switch (c)
@@ -418,6 +420,16 @@ main (int argc, char **argv)
           make_backups = true;
           backup_suffix_string = optarg;
           break;
+        case 'Z':
+          /* politely decline if we're not on a selinux-enabled kernel. */
+          if( !selinux_enabled ) {
+             fprintf( stderr, "Warning:  ignoring --context (-Z). "
+                              "It requires a SELinux enabled kernel.\n" );
+             break;
+          }
+          x.preserve_security_context = false;
+          x.set_security_context = true;
+          break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
         default:
diff -up coreutils-8.19/src/system.h.restorecon coreutils-8.19/src/system.h
--- coreutils-8.19/src/system.h.restorecon	2012-07-23 06:05:16.000000000 -0400
+++ coreutils-8.19/src/system.h	2012-10-19 15:37:13.473218499 -0400
@@ -330,7 +330,7 @@ enum
 #define GETOPT_VERSION_OPTION_DECL \
   "version", no_argument, NULL, GETOPT_VERSION_CHAR
 #define GETOPT_SELINUX_CONTEXT_OPTION_DECL \
-  "context", required_argument, NULL, 'Z'
+  "context", optional_argument, NULL, 'Z'
 
 #define case_GETOPT_HELP_CHAR			\
   case GETOPT_HELP_CHAR:			\

--------------040908060905070400030504--


From MAILER-DAEMON Sat Oct 20 04:54:05 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TPUon-00065P-ST
	for mharc-coreutils@gnu.org; Sat, 20 Oct 2012 04:54:05 -0400
Received: from eggs.gnu.org ([208.118.235.92]:57303)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TPUol-000657-4c
	for coreutils@gnu.org; Sat, 20 Oct 2012 04:54:04 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TPUoj-0002m8-UT
	for coreutils@gnu.org; Sat, 20 Oct 2012 04:54:03 -0400
Received: from mx.meyering.net ([88.168.87.75]:38440)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TPUoj-0002lx-J5
	for coreutils@gnu.org; Sat, 20 Oct 2012 04:54:01 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 6C2E860149;
	Sat, 20 Oct 2012 10:54:00 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Daniel J Walsh <dwalsh@redhat.com>
Subject: Re: Make mv work better with SELinux.
In-Reply-To: <5081CBB0.2020507@redhat.com> (Daniel J. Walsh's message of "Fri, 
	19 Oct 2012 17:52:48 -0400")
References: <50733664.5000503@redhat.com> <50733CC1.9000506@draigBrady.com>
	<87626jolel.fsf@rho.meyering.net> <507D5C87.3030501@redhat.com>
	<87wqyqwnik.fsf@rho.meyering.net> <5081CBB0.2020507@redhat.com>
Date: Sat, 20 Oct 2012 10:54:00 +0200
Message-ID: <877gqly15j.fsf@rho.meyering.net>
Lines: 94
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 20 Oct 2012 08:54:04 -0000

Daniel J Walsh wrote:
> On 10/16/2012 09:32 AM, Jim Meyering wrote:
>> Daniel J Walsh wrote:
>>> On 10/09/2012 08:54 AM, Jim Meyering wrote:
>>>> P=E1draig Brady wrote:
>>>>> On 10/08/2012 09:24 PM, Daniel J Walsh wrote:
>> ...
>>>> [in a follow-up]
>>>>> Thinking further, --context without an option, is not too clear to
>>>>> the user. They might think they were copying the original context
>>>>> rather than setting a new context.
>>>>
>>>>> Pity the long option wasn't called --new-context. I suppose we could
>>>>> have that as an alias for --context and deprecate the former?
>>>>
>>>> Sounds reasonable. Adjust the other --context=3DCTX commands, mkdir,
>>>> mkfifo, mknod at the same time.
>>>
>>> I just want to make sure that you guys are expecting a patch from me?
>>
>> I am.  That'd be great, especially if you can add NEWS entries and tests=
 to
>> exercise the new code.
>>
> Here is what I have thus far.  Major problem I have not figured out yet i=
s how
> to get selinux.c code to work in the library, so it is hacked to just be
> included as part of the selinux.h file.
>
> Just looking to get feedback that I am not going down the wrong path.
>
> Made -Z and --context take optional context for apps that have had these =
flags
> for a while
>
> mkdir, mkfifo, mknod and cp
>
> Added -Z --context to mv without optional flag.  ( I would love to dump t=
he
> optional flag but it has been in place for years.)
>
> Not sure how man pages get created so I modified in patch.  Also modified=
 info
> stuff.
>
> Basically there are two new functions, restorecon which fixed file labels
> after they are created, this is not optimal since there is a potential ra=
ce
> condition, but since mv does a rename this is all we can do.
>
> defaultcon will tell SELinux what to label a file before it is created.
>
> I have added the function mode_to_security_class to libselinux for Fedora=
 18,
> but it is not in all versions of libselinux.  I can back port this, but f=
or
> now left it in patch.

Thanks for the heads-up.

That function sounds like it should eventually be provided via a gnulib
module, so that it's transparent to gnulib-using applications.  For now,
it might be ok to duplicate the code.

About new files, with the revamped mostly-non-recursive-make build system,
you'll probably want to put them in src/, not in lib/, unless you are
inclined to make them into gnulib modules, in which case, you'd add
pieces in gl/{lib,m4,modules}.  Why?  Having package-specific files
in lib/ caused trouble when mixing with all of the gnulib-provided
ones that end up there, so since 8.19, I converted the few remaining
lib/*.[ch] pairs to new gnulib-style modules under gl/.

> This patch is based off of fedora package, not sure if I should have merg=
ed
> all SELinux changes into patch to send upstream.

I think someone else will have to do the real review,
but here are some guidelines:
  - make your patch relative to what's in git (what will shortly be 8.20)
  - use GNU C code formatting conventions, i.e., function name in column 1,
      space-before-open-paren in a function call, etc.

For each new function in say, selinux.c, please add a comment just prior
to each definition with a sentence or two describing what it does, and
using parameter names, e.g.,

/* Given stat.st_mode-style bits, M, return the corresponding SELinux
   security class.  If there is no such correspondence, return 0 and
   set errno to EINVAL.  */
security_class_t
mode_to_security_class (mode_t m)
{
  if (S_ISREG (m))
    return string_to_security_class ("file");
  ...

  errno =3D EINVAL;
  return 0;
}

> diff -up coreutils-8.19/doc/coreutils.texi.restorecon coreutils-8.19/doc/=
coreutils.texi
> --- coreutils-8.19/doc/coreutils.texi.restorecon	2012-10-19 17:41:30.0732=
19080 -0400
> +++ coreutils-8.19/doc/coreutils.texi	2012-10-19 17:41:31.151219479 -0400


From MAILER-DAEMON Mon Oct 22 08:06:15 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQGlr-0000yZ-Cj
	for mharc-coreutils@gnu.org; Mon, 22 Oct 2012 08:06:15 -0400
Received: from eggs.gnu.org ([208.118.235.92]:44300)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQGll-0000xv-AA
	for coreutils@gnu.org; Mon, 22 Oct 2012 08:06:14 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQGle-0003Kp-6h
	for coreutils@gnu.org; Mon, 22 Oct 2012 08:06:08 -0400
Received: from mx1.redhat.com ([209.132.183.28]:39408)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQGld-0003Jl-UA
	for coreutils@gnu.org; Mon, 22 Oct 2012 08:06:02 -0400
Received: from int-mx01.intmail.prod.int.phx2.redhat.com
	(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9MC5sDo026667
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Mon, 22 Oct 2012 08:05:55 -0400
Received: from pb-n5110.redhat.com (ovpn-116-57.ams2.redhat.com [10.36.116.57])
	by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9MC5row030707; Mon, 22 Oct 2012 08:05:54 -0400
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
To: coreutils@gnu.org
Subject: [PATCH] tests: correctly restrict factor test without GMP
Date: Mon, 22 Oct 2012 13:05:51 +0100
Message-Id: <1350907551-25377-1-git-send-email-P@draigBrady.com>
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Oct 2012 12:06:14 -0000

* tests/misc/factor.pl: Correct the precedence and
regular expression in the command to check for GMP.
---
 tests/misc/factor.pl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tests/misc/factor.pl b/tests/misc/factor.pl
index 8f6edaa..540984f 100755
--- a/tests/misc/factor.pl
+++ b/tests/misc/factor.pl
@@ -76,7 +76,7 @@ my @Tests =
     );
 
 # If we have GMP support, append tests to exercise it.
-system "grep -w HAVE_GMP $ENV{CONFIG_HEADER} > /dev/null" == 0
+(system "grep '^#define HAVE_GMP 1' $ENV{CONFIG_HEADER} > /dev/null") == 0
   and push (@Tests,
             ['bug-gmp-2_sup_128', '340282366920938463463374607431768211456',
              {OUT => '2 'x127 . '2'}],
-- 
1.7.6.4



From MAILER-DAEMON Mon Oct 22 08:15:41 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQGuz-0004Ng-Hp
	for mharc-coreutils@gnu.org; Mon, 22 Oct 2012 08:15:41 -0400
Received: from eggs.gnu.org ([208.118.235.92]:57918)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQGur-0004KY-DU
	for coreutils@gnu.org; Mon, 22 Oct 2012 08:15:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQGuc-0005j6-0j
	for coreutils@gnu.org; Mon, 22 Oct 2012 08:15:28 -0400
Received: from mx.meyering.net ([88.168.87.75]:44703)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQGub-0005dq-QW
	for coreutils@gnu.org; Mon, 22 Oct 2012 08:15:17 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 4FB3E60176;
	Mon, 22 Oct 2012 14:15:06 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: [PATCH] tests: correctly restrict factor test without GMP
In-Reply-To: <1350907551-25377-1-git-send-email-P@draigBrady.com>
	(=?iso-8859-1?Q?=22P=E1draig?=
	Brady"'s message of "Mon, 22 Oct 2012 13:05:51 +0100")
References: <1350907551-25377-1-git-send-email-P@draigBrady.com>
Date: Mon, 22 Oct 2012 14:15:06 +0200
Message-ID: <87r4oqzos5.fsf@rho.meyering.net>
Lines: 23
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Oct 2012 12:15:39 -0000

P=E1draig Brady wrote:
> * tests/misc/factor.pl: Correct the precedence and
> regular expression in the command to check for GMP.
> ---
>  tests/misc/factor.pl |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/tests/misc/factor.pl b/tests/misc/factor.pl
> index 8f6edaa..540984f 100755
> --- a/tests/misc/factor.pl
> +++ b/tests/misc/factor.pl
> @@ -76,7 +76,7 @@ my @Tests =3D
>      );
>
>  # If we have GMP support, append tests to exercise it.
> -system "grep -w HAVE_GMP $ENV{CONFIG_HEADER} > /dev/null" =3D=3D 0
> +(system "grep '^#define HAVE_GMP 1' $ENV{CONFIG_HEADER} > /dev/null") =
=3D=3D 0
>    and push (@Tests,
>              ['bug-gmp-2_sup_128', '3402823669209384634633746074317682114=
56',
>               {OUT =3D> '2 'x127 . '2'}],

Both fixes look fine.
Thanks for cleaning up after me.


From MAILER-DAEMON Mon Oct 22 09:21:24 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQHwa-0002vM-Eo
	for mharc-coreutils@gnu.org; Mon, 22 Oct 2012 09:21:24 -0400
Received: from eggs.gnu.org ([208.118.235.92]:35824)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQHwQ-0002tL-BW
	for coreutils@gnu.org; Mon, 22 Oct 2012 09:21:23 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQHwH-00023p-Ls
	for coreutils@gnu.org; Mon, 22 Oct 2012 09:21:14 -0400
Received: from mx1.redhat.com ([209.132.183.28]:7047)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQHwH-00023i-Dt
	for coreutils@gnu.org; Mon, 22 Oct 2012 09:21:05 -0400
Received: from int-mx01.intmail.prod.int.phx2.redhat.com
	(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9MDL3GY027812
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Mon, 22 Oct 2012 09:21:04 -0400
Received: from [10.36.116.57] (ovpn-116-57.ams2.redhat.com [10.36.116.57])
	by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9MDL15T027637
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <coreutils@gnu.org>; Mon, 22 Oct 2012 09:21:03 -0400
Message-ID: <5085483D.7040903@draigBrady.com>
Date: Mon, 22 Oct 2012 14:21:01 +0100
From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Coreutils <coreutils@gnu.org>
Subject: issues with new factor on sparc
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9MDL3GY027812
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Oct 2012 13:21:23 -0000

compile warning with gcc 3.4.3 on
SunOS login 5.10 Generic_147440-19 sun4v sparc SUNW,SPARC-Enterprise-T522=
0
  src/factor.c: In function `factor_using_pollard_rho2':
  src/factor.c:1535: warning: right shift count >=3D width of type
  src/factor.c:1558: warning: right shift count >=3D width of type
  src/factor.c:1568: warning: right shift count >=3D width of type

compile failure on niagra (sparc64) with gcc 4.3.2
  src/factor.c: In function 'factor_using_pollard_rho2':
  src/factor.c:1535: warning: right shift count >=3D width of type
  src/factor.c:1558: warning: right shift count >=3D width of type
  src/factor.c:1568: warning: right shift count >=3D width of type
  /tmp/ccjv79Tn.s:8713: Error: Architecture mismatch on "addc".
  /tmp/ccjv79Tn.s:8713:  (Requires v9|v9a|v9b; requested architecture is =
sparclite.)
  /tmp/ccjv79Tn.s:8755: Error: Architecture mismatch on "subccc".
  /tmp/ccjv79Tn.s:8755:  (Requires v9|v9a|v9b; requested architecture is =
sparclite.)
  /tmp/ccjv79Tn.s:8756: Error: Architecture mismatch on "subc".
  /tmp/ccjv79Tn.s:8756:  (Requires v9|v9a|v9b; requested architecture is =
sparclite.)

On niagra all tests pass if I avoid the issue with
configure --enable-no-install-program=3Dfactor

cheers,
P=C3=A1draig.


From MAILER-DAEMON Mon Oct 22 10:45:19 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQJFn-0006o3-2H
	for mharc-coreutils@gnu.org; Mon, 22 Oct 2012 10:45:19 -0400
Received: from eggs.gnu.org ([208.118.235.92]:50925)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQJFf-0006lG-5x
	for coreutils@gnu.org; Mon, 22 Oct 2012 10:45:17 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQJFV-0002Yx-0F
	for coreutils@gnu.org; Mon, 22 Oct 2012 10:45:11 -0400
Received: from mx1.redhat.com ([209.132.183.28]:52378)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQJFU-0002Yc-Om
	for coreutils@gnu.org; Mon, 22 Oct 2012 10:45:00 -0400
Received: from int-mx02.intmail.prod.int.phx2.redhat.com
	(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9MEixDR013053
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Mon, 22 Oct 2012 10:44:59 -0400
Received: from [10.36.116.57] (ovpn-116-57.ams2.redhat.com [10.36.116.57])
	by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9MEisLA028245
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <coreutils@gnu.org>; Mon, 22 Oct 2012 10:44:57 -0400
Message-ID: <50855BE6.5000602@draigBrady.com>
Date: Mon, 22 Oct 2012 15:44:54 +0100
From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: coreutils@gnu.org
Subject: Re: new snapshot available: coreutils-8.19.166-3131c
References: <874nlq1ynw.fsf@rho.meyering.net>
In-Reply-To: <874nlq1ynw.fsf@rho.meyering.net>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Oct 2012 14:45:17 -0000

On 10/19/2012 12:36 PM, Jim Meyering wrote:
> We plan to release coreutils-8.20 early next week, so any testing
> you can do between now and Monday would be most welcome.

Fedora 15 - x86_64
  coreutils
   # TOTAL: 532
   # PASS:  438
   # SKIP:  94
   # FAIL:  0
  gnulib
   # TOTAL: 315
   # PASS:  305
   # SKIP:  10
   # FAIL:  0

RHEL 6.1
   # TOTAL: 532
   # PASS:  432
   # SKIP:  100
   # FAIL:  0
  gnulib
   # TOTAL: 315
   # PASS:  296
   # SKIP:  19
   # FAIL:  0

solaris - sparc
  coreutils
   # TOTAL: 532
   # PASS:  395
   # SKIP:  130
   # FAIL:  6
   # ERROR: 1
    All the above due to: cp -a x y from within /tmp (swap)
    which warned about acl failures. truss shows:
     acl("y/x", SETACL, 4, 0x00042000)               Err#89
     acl("y/x", ACE_SETACL, 3, 0x00041FD0)           Err#89
    NFS didn't the same issue.

Debian 5.0.10 - sparc64
  coreutils
   # TOTAL: 532
   # PASS:  410
   # SKIP:  122
   # FAIL:  0

Debian 5.0.7 - x86_64
  coreutils
   # TOTAL: 532
   # PASS:  419
   # SKIP:  113
   # FAIL:  0
  gnulib
   # TOTAL: 315
   # PASS:  286
   # SKIP:  29
   # FAIL:  0


From MAILER-DAEMON Mon Oct 22 11:29:42 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQJwk-0003Ku-Kz
	for mharc-coreutils@gnu.org; Mon, 22 Oct 2012 11:29:42 -0400
Received: from eggs.gnu.org ([208.118.235.92]:50926)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQJwi-0003Is-44
	for coreutils@gnu.org; Mon, 22 Oct 2012 11:29:41 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQJwg-00029x-MO
	for coreutils@gnu.org; Mon, 22 Oct 2012 11:29:40 -0400
Received: from mx.meyering.net ([88.168.87.75]:45148)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQJwg-00029g-EV
	for coreutils@gnu.org; Mon, 22 Oct 2012 11:29:38 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 440EB600E3;
	Mon, 22 Oct 2012 17:29:37 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: new snapshot available: coreutils-8.19.166-3131c
In-Reply-To: <50855BE6.5000602@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?=
	=?iso-8859-1?Q?g?= Brady"'s message of
	"Mon, 22 Oct 2012 15:44:54 +0100")
References: <874nlq1ynw.fsf@rho.meyering.net> <50855BE6.5000602@draigBrady.com>
Date: Mon, 22 Oct 2012 17:29:37 +0200
Message-ID: <876262zfry.fsf@rho.meyering.net>
Lines: 64
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Oct 2012 15:29:41 -0000

P=E1draig Brady wrote:
> On 10/19/2012 12:36 PM, Jim Meyering wrote:
>> We plan to release coreutils-8.20 early next week, so any testing
>> you can do between now and Monday would be most welcome.
>
> Fedora 15 - x86_64
...
> RHEL 6.1
...
> solaris - sparc
...
> Debian 5.0.10 - sparc64
...
> Debian 5.0.7 - x86_64
...

Thanks for all the tests.
FYI, I've confirmed all tests pass on these (all x86_64):
  Fedora 17
  Fedora 18
  Fedora rawhide
  Debian unstable

Also just tested on an i386 with minimal Fedora 18
and saw this factor failure due to lack of libgmp:
(also note the high SKIP count)

    bug-gmp-2_sup_128...
    factor.pl: test bug-gmp-2_sup_128 failed: exit status mismatch:  expect=
ed 0, got 1
    bug-gmp-2_sup_256...
    factor.pl: test bug-gmp-2_sup_256 failed: exit status mismatch:  expect=
ed 0, got 1

  # TOTAL: 532
  # PASS:  433
  # SKIP:  98
  # XFAIL: 0
  # FAIL:  1
  # XPASS: 0
  # ERROR: 0

I manually applied your patch,
    Subject: [PATCH] tests: correctly restrict factor test without GMP
and reran the test, which then skipped that internal sub-test, as intended,
and then passed:

    $ make check -C tests TESTS=3Dmisc/factor                              =
        :
    ...
    make[5]: Entering directory `/tmp/coreutils-8.19.167-0aeaa'
    PASS: tests/misc/factor.pl
    ...

FTR, here are the gnulib test results there:

    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
    Testsuite summary for GNU coreutils 8.19.167-0aeaa
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
    # TOTAL: 315
    # PASS:  296
    # SKIP:  19
    # XFAIL: 0
    # FAIL:  0
    # XPASS: 0
    # ERROR: 0
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D


From MAILER-DAEMON Mon Oct 22 20:37:50 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQSVC-0004Av-2f
	for mharc-coreutils@gnu.org; Mon, 22 Oct 2012 20:37:50 -0400
Received: from eggs.gnu.org ([208.118.235.92]:32925)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQSV8-0004AZ-T6
	for coreutils@gnu.org; Mon, 22 Oct 2012 20:37:47 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQSV7-0003rj-Lt
	for coreutils@gnu.org; Mon, 22 Oct 2012 20:37:46 -0400
Received: from mx1.redhat.com ([209.132.183.28]:5887)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQSV7-0003rW-Df
	for coreutils@gnu.org; Mon, 22 Oct 2012 20:37:45 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9N0bhI6004064
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Mon, 22 Oct 2012 20:37:44 -0400
Received: from [10.36.116.57] (ovpn-116-57.ams2.redhat.com [10.36.116.57])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9N0bfrb021247
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO)
	for <coreutils@gnu.org>; Mon, 22 Oct 2012 20:37:43 -0400
Message-ID: <5085E6D5.9010706@draigBrady.com>
Date: Tue, 23 Oct 2012 01:37:41 +0100
From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Coreutils <coreutils@gnu.org>
Subject: Re: issues with new factor on sparc
References: <5085483D.7040903@draigBrady.com>
In-Reply-To: <5085483D.7040903@draigBrady.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9N0bhI6004064
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 00:37:48 -0000

On 10/22/2012 02:21 PM, P=C3=A1draig Brady wrote:
> compile warning with gcc 3.4.3 on
> SunOS login 5.10 Generic_147440-19 sun4v sparc SUNW,SPARC-Enterprise-T5=
220
>   src/factor.c: In function `factor_using_pollard_rho2':
>   src/factor.c:1535: warning: right shift count >=3D width of type
>   src/factor.c:1558: warning: right shift count >=3D width of type
>   src/factor.c:1568: warning: right shift count >=3D width of type
>
> compile failure on niagra (sparc64) with gcc 4.3.2
>   src/factor.c: In function 'factor_using_pollard_rho2':
>   src/factor.c:1535: warning: right shift count >=3D width of type
>   src/factor.c:1558: warning: right shift count >=3D width of type
>   src/factor.c:1568: warning: right shift count >=3D width of type

These warnings are alleviated with:

diff --git a/src/factor.c b/src/factor.c
index 73c59e9..e842556 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -1532,7 +1533,7 @@ factor_using_pollard_rho2 (uintmax_t n1, uintmax_t =
n0, unsigned long int a,
              {
                x0 =3D mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
                x1 =3D r1m;
-              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
+              addmod2 (x1, x0, x1, x0, 0, (uintmax_t) a, n1, n0);

                submod2 (t1, t0, z1, z0, x1, x0, n1, n0);
                P0 =3D mulredc2 (&r1m, P1, P0, t1, t0, n1, n0, ni);
@@ -1555,7 +1556,7 @@ factor_using_pollard_rho2 (uintmax_t n1, uintmax_t =
n0, unsigned long int a,
              {
                x0 =3D mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
                x1 =3D r1m;
-              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
+              addmod2 (x1, x0, x1, x0, 0, (uintmax_t) a, n1, n0);
              }
            y1 =3D x1; y0 =3D x0;
          }
@@ -1565,7 +1566,7 @@ factor_using_pollard_rho2 (uintmax_t n1, uintmax_t =
n0, unsigned long int a,
          {
            y0 =3D mulredc2 (&r1m, y1, y0, y1, y0, n1, n0, ni);
            y1 =3D r1m;
-          addmod2 (y1, y0, y1, y0, 0, a, n1, n0);
+          addmod2 (y1, y0, y1, y0, 0, (uintmax_t) a, n1, n0);

            submod2 (t1, t0, z1, z0, y1, y0, n1, n0);
            g0 =3D gcd2_odd (&g1, t1, t0, n1, n0);

>   /tmp/ccjv79Tn.s:8713: Error: Architecture mismatch on "addc".
>   /tmp/ccjv79Tn.s:8713:  (Requires v9|v9a|v9b; requested architecture i=
s sparclite.)
>   /tmp/ccjv79Tn.s:8755: Error: Architecture mismatch on "subccc".
>   /tmp/ccjv79Tn.s:8755:  (Requires v9|v9a|v9b; requested architecture i=
s sparclite.)
>   /tmp/ccjv79Tn.s:8756: Error: Architecture mismatch on "subc".
>   /tmp/ccjv79Tn.s:8756:  (Requires v9|v9a|v9b; requested architecture i=
s sparclite.)

So gcc on sparc defaults to v7, I.E. the most compatible,
and the compile succeeds with CFLAGS=3D-mcpu=3Dniagara.
So it seems best to protect these V9 specific instructions with:

diff --git a/src/longlong.h b/src/longlong.h
-#if defined (__sparc__) && W_TYPE_SIZE =3D=3D 64
+#if (defined (__sparc_v9) || defined (__sparc_v9__)) && W_TYPE_SIZE =3D=3D=
 64
  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \

Note I itemized the various distinguishing definitions available using:

$ for cpu in 'v7' 'cypress' 'v8' 'supersparc' 'sparclite' 'f930' 'f934' '=
hypersparc' \
    'sparclite86x' 'sparclet' 'tsc701' 'v9' 'ultrasparc' 'ultrasparc3' 'n=
iagara' 'niagara2'; do
   echo "--------- $cpu --------"
   cpp -mcpu=3D$cpu -dM /dev/null |
   grep -Ei '(sparc|niagra)' | grep -Ev 'sparc( |__)'
done

--------- v7 --------
--------- cypress --------
--------- v8 --------
#define __sparc_v8__ 1
--------- supersparc --------
#define __sparc_v8__ 1
--------- sparclite --------
#define __sparclite__ 1
--------- f930 --------
#define __sparclite__ 1
--------- f934 --------
#define __sparclite__ 1
--------- hypersparc --------
#define __sparc_v8__ 1
--------- sparclite86x --------
#define __sparclite86x__ 1
--------- sparclet --------
#define __sparclet__ 1
--------- tsc701 --------
#define __sparclet__ 1
--------- v9 --------
#define __sparc_v9__ 1
--------- ultrasparc --------
#define __sparc_v9__ 1
--------- ultrasparc3 --------
#define __sparc_v9__ 1
--------- niagara --------
#define __sparc_v9__ 1
--------- niagara2 --------
#define __sparc_v9__ 1

cheers,
P=C3=A1draig.


From MAILER-DAEMON Mon Oct 22 20:53:17 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQSk9-0005kr-I6
	for mharc-coreutils@gnu.org; Mon, 22 Oct 2012 20:53:17 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49620)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQSk7-0005kl-Mz
	for coreutils@gnu.org; Mon, 22 Oct 2012 20:53:16 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQSk6-0007ll-IW
	for coreutils@gnu.org; Mon, 22 Oct 2012 20:53:15 -0400
Received: from mx1.redhat.com ([209.132.183.28]:50730)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQSk6-0007lh-8s
	for coreutils@gnu.org; Mon, 22 Oct 2012 20:53:14 -0400
Received: from int-mx11.intmail.prod.int.phx2.redhat.com
	(int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9N0rBJ4001795
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Mon, 22 Oct 2012 20:53:11 -0400
Received: from [10.36.116.57] (ovpn-116-57.ams2.redhat.com [10.36.116.57])
	by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9N0r892017873
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Mon, 22 Oct 2012 20:53:10 -0400
Message-ID: <5085EA74.3080003@draigBrady.com>
Date: Tue, 23 Oct 2012 01:53:08 +0100
From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Coreutils <coreutils@gnu.org>
Subject: more compile warnings with new factor
References: <5085483D.7040903@draigBrady.com>
In-Reply-To: <5085483D.7040903@draigBrady.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9N0rBJ4001795
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: Torbjorn Granlund <tg@gmplib.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 00:53:16 -0000

If I manually undef HAVE_GMP at the top of factor.c, then...

$ make src/factor.o
src/factor.c:154:0: error: macro "__GMP_GNUC_PREREQ" is not used [-Werror=
=3Dunused-macros]

$ make CFLAGS=3D-m32 src/factor.o
src/factor.c: In function 'factor_using_division':
src/factor.c:755:33: error: variable 'lo' set but not used [-Werror=3Dunu=
sed-but-set-variable]
src/factor.c: In function 'mulredc':
src/factor.c:945:28: error: variable 'tl' set but not used [-Werror=3Dunu=
sed-but-set-variable]
src/factor.c: In function 'mulredc2':
src/factor.c:965:28: error: variable 'p0' set but not used [-Werror=3Dunu=
sed-but-set-variable]
src/factor.c: In function 'prime2_p':
src/factor.c:1323:17: error: variable '_p0' set but not used [-Werror=3Du=
nused-but-set-variable]
src/factor.c: In function 'factor_using_pollard_rho2':
src/factor.c:1579:11: error: variable '_p0' set but not used [-Werror=3Du=
nused-but-set-variable]
src/factor.c: In function 'factor_using_squfof':
src/factor.c:2146:19: error: variable '_p0' set but not used [-Werror=3Du=
nused-but-set-variable]

The above point to redundant processing in umul_ppmm()
(or at least our use of it).

src/factor.c: At top level:
src/factor.c:151:0: error: macro "ASSERT" is not used [-Werror=3Dunused-m=
acros]
src/factor.c:154:0: error: macro "__GMP_GNUC_PREREQ" is not used [-Werror=
=3Dunused-macros]

I'll clean up these tomorrow.

thanks,
P=C3=A1draig.


From MAILER-DAEMON Tue Oct 23 02:53:38 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQYMs-00051V-Ue
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 02:53:38 -0400
Received: from eggs.gnu.org ([208.118.235.92]:42472)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tg@gmplib.org>) id 1TQYMm-00050I-5c
	for coreutils@gnu.org; Tue, 23 Oct 2012 02:53:37 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <tg@gmplib.org>) id 1TQYMj-00011q-Hm
	for coreutils@gnu.org; Tue, 23 Oct 2012 02:53:32 -0400
Received: from gmplib-02.nada.kth.se ([130.237.222.242]:64937
	helo=shell.gmplib.org) by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <tg@gmplib.org>) id 1TQYMj-00011f-Ad
	for coreutils@gnu.org; Tue, 23 Oct 2012 02:53:29 -0400
Received: by shell.gmplib.org (Postfix, from userid 1001)
	id 307BFAE920; Tue, 23 Oct 2012 08:53:27 +0200 (CEST)
To: =?utf-8?Q?P=C3=A1draig?= Brady <P@draigBrady.com>
Subject: Re: more compile warnings with new factor
References: <5085483D.7040903@draigBrady.com> <5085EA74.3080003@draigBrady.com>
From: Torbjorn Granlund <tg@gmplib.org>
Sender: tg@gmplib.org
Date: Tue, 23 Oct 2012 08:53:27 +0200
In-Reply-To: <5085EA74.3080003@draigBrady.com> (=?utf-8?Q?=22P=C3=A1draig?=
	Brady"'s message of "Tue\, 23 Oct 2012 01\:53\:08 +0100")
Message-ID: <86ehkpof14.fsf@shell.gmplib.org>
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (berkeley-unix)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 130.237.222.242
Cc: Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 06:53:38 -0000

P=C3=A1draig Brady <P@draigBrady.com> writes:

  If I manually undef HAVE_GMP at the top of factor.c, then...
=20=20
  $ make src/factor.o
  src/factor.c:154:0: error: macro "__GMP_GNUC_PREREQ" is not used [-Werror=
=3Dunused-macros]
=20=20
It is used by some configs in longlong.h.  It cannot be removed unless
you fork longlong.h.

  $ make CFLAGS=3D-m32 src/factor.o
  src/factor.c: In function 'factor_using_division':
  src/factor.c:755:33: error: variable 'lo' set but not used [-Werror=3Dunu=
sed-but-set-variable]
  src/factor.c: In function 'mulredc':
  src/factor.c:945:28: error: variable 'tl' set but not used [-Werror=3Dunu=
sed-but-set-variable]
  src/factor.c: In function 'mulredc2':
  src/factor.c:965:28: error: variable 'p0' set but not used [-Werror=3Dunu=
sed-but-set-variable]
  src/factor.c: In function 'prime2_p':
  src/factor.c:1323:17: error: variable '_p0' set but not used [-Werror=3Du=
nused-but-set-variable]
  src/factor.c: In function 'factor_using_pollard_rho2':
  src/factor.c:1579:11: error: variable '_p0' set but not used [-Werror=3Du=
nused-but-set-variable]
  src/factor.c: In function 'factor_using_squfof':
  src/factor.c:2146:19: error: variable '_p0' set but not used [-Werror=3Du=
nused-but-set-variable]
=20=20
  The above point to redundant processing in umul_ppmm()
  (or at least our use of it).
=20=20
The code sometimes needs the upper half of a product, but umul_ppmm
generates the full product as two halves.  You could insert bogus
dependencies on the low half, most likely making generated code worse.
Or remove the bogus warning.

  src/factor.c: At top level:
  src/factor.c:151:0: error: macro "ASSERT" is not used [-Werror=3Dunused-m=
acros]
  src/factor.c:154:0: error: macro "__GMP_GNUC_PREREQ" is not used [-Werror=
=3Dunused-macros]
=20=20
I fail to understand how anybody can regard an unused macro as an
*error*.
=20=20
  I'll clean up these tomorrow.

Aren't this Draconian options ("ask the compiler to nag about everything
it can, then treat nagging as errors in the code") self-defeating?  You
need to avoid natural ways of writing things, and instead go for
contorted solutions.  I spent a few hours trying to satisfy your demands
in this area, and I am sure you maintainers have spent a lot of time on
it.

I for one prefer to spend my time on improving GNU, not define an
artifical goal like this one, and work on satifying that.

--=20
Torbj=C3=B6rn


From MAILER-DAEMON Tue Oct 23 03:47:00 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQZCW-0006D2-SU
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 03:47:00 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37291)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQZCU-0006Bo-2L
	for coreutils@gnu.org; Tue, 23 Oct 2012 03:46:59 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQZCR-0008JE-S7
	for coreutils@gnu.org; Tue, 23 Oct 2012 03:46:58 -0400
Received: from mx.meyering.net ([88.168.87.75]:47302)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQZCR-0008J6-GK
	for coreutils@gnu.org; Tue, 23 Oct 2012 03:46:55 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 7F48E600DF;
	Tue, 23 Oct 2012 09:46:54 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Torbjorn Granlund <tg@gmplib.org>
Subject: Re: more compile warnings with new factor
In-Reply-To: <86ehkpof14.fsf@shell.gmplib.org> (Torbjorn Granlund's message of
	"Tue, 23 Oct 2012 08:53:27 +0200")
References: <5085483D.7040903@draigBrady.com>
	<5085EA74.3080003@draigBrady.com> <86ehkpof14.fsf@shell.gmplib.org>
Date: Tue, 23 Oct 2012 09:46:54 +0200
Message-ID: <874nllwryp.fsf@rho.meyering.net>
Lines: 92
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 07:46:59 -0000

Torbjorn Granlund wrote:
> P=E1draig Brady <P@draigBrady.com> writes:
>
>   If I manually undef HAVE_GMP at the top of factor.c, then...
>
>   $ make src/factor.o
>   src/factor.c:154:0: error: macro "__GMP_GNUC_PREREQ" is not used
> [-Werror=3Dunused-macros]
>
> It is used by some configs in longlong.h.  It cannot be removed unless
> you fork longlong.h.

Hi Torbj=F6rn,

FYI, I made this small change to longlong.h a month ago:

    build: avoid warning about unused macro
    ...
    * src/longlong.h (__GMP_DECLSPEC): Define if not already defined.

+#ifndef __GMP_DECLSPEC
+#define __GMP_DECLSPEC /* empty */
+#endif
+

...
>   src/factor.c:2146:19: error: variable '_p0' set but not used
> [-Werror=3Dunused-but-set-variable]
>
>   The above point to redundant processing in umul_ppmm()
>   (or at least our use of it).
>
> The code sometimes needs the upper half of a product, but umul_ppmm
> generates the full product as two halves.  You could insert bogus
> dependencies on the low half, most likely making generated code worse.
> Or remove the bogus warning.

P=E1draig,
If you don't find a cleaner solution, I wouldn't mind marking those
variables with ATTRIBUTE_UNUSED when HAVE_GMP is not defined.  E.g.,

    #if HAVE_GMP
    # define UNUSED_WITH_NO_GMP /* empty */
    #else
    # define UNUSED_WITH_NO_GMP ATTRIBUTE_UNUSED
    #endif

Alternatively, and cleaner still, disable the -Wunused-but-set-variable
option when configure detects no GMP support.  These days, building
coreutils without GMP support seems less and less relevant.

Finally, the simplest option of all would be fine, too: do nothing,
and let those who configure with --enable-gcc-warnings figure out
that they can get past this by building with "make WERROR_CFLAGS=3D".

>   src/factor.c: At top level:
>   src/factor.c:151:0: error: macro "ASSERT" is not used [-Werror=3Dunused=
-macros]
>   src/factor.c:154:0: error: macro "__GMP_GNUC_PREREQ" is not used
> [-Werror=3Dunused-macros]
>
> I fail to understand how anybody can regard an unused macro as an
> *error*.

When configured with gcc and --enable-gcc-warnings we enable -Werror,
to ensure that no warnings slip by unnoticed.
That is not the default, though I'm tempted to make it
the default when building from git.

Yes, we have high standards.

>   I'll clean up these tomorrow.
>
> Aren't this Draconian options ("ask the compiler to nag about everything
> it can, then treat nagging as errors in the code") self-defeating?  You
> need to avoid natural ways of writing things, and instead go for
> contorted solutions.  I spent a few hours trying to satisfy your demands
> in this area, and I am sure you maintainers have spent a lot of time on
> it.

We've learned that while many of the warnings are
not about real bugs, some do indicate real problems.
An unused macro or variable could well indicate a typo
in the definition/declaration or in all uses.

> I for one prefer to spend my time on improving GNU, not define an
> artifical goal like this one, and work on satifying that.

We have moved to using very strict warning settings gradually over the
years, carefully disabling the few warning options for which the cost
consistently outweighs the benefit.

We really do believe that what we are doing is worthwhile.


From MAILER-DAEMON Tue Oct 23 04:56:47 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQaI3-00044n-47
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 04:56:47 -0400
Received: from eggs.gnu.org ([208.118.235.92]:43149)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQaHv-00043P-0e
	for coreutils@gnu.org; Tue, 23 Oct 2012 04:56:45 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQaHo-00042P-Rf
	for coreutils@gnu.org; Tue, 23 Oct 2012 04:56:38 -0400
Received: from mx1.redhat.com ([209.132.183.28]:48104)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQaHo-00042D-Jx
	for coreutils@gnu.org; Tue, 23 Oct 2012 04:56:32 -0400
Received: from int-mx01.intmail.prod.int.phx2.redhat.com
	(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9N8uTdA020980
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 23 Oct 2012 04:56:29 -0400
Received: from [10.36.116.65] (ovpn-116-65.ams2.redhat.com [10.36.116.65])
	by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9N8uPo9012298
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Tue, 23 Oct 2012 04:56:28 -0400
Message-ID: <50865BB9.4020602@draigBrady.com>
Date: Tue, 23 Oct 2012 09:56:25 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: more compile warnings with new factor
References: <5085483D.7040903@draigBrady.com> <5085EA74.3080003@draigBrady.com>
	<86ehkpof14.fsf@shell.gmplib.org> <874nllwryp.fsf@rho.meyering.net>
In-Reply-To: <874nllwryp.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9N8uTdA020980
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: Torbjorn Granlund <tg@gmplib.org>, Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 08:56:45 -0000

On 10/23/2012 08:46 AM, Jim Meyering wrote:
> Torbjorn Granlund wrote:
>> P=E1draig Brady <P@draigBrady.com> writes:
>>
>>    If I manually undef HAVE_GMP at the top of factor.c, then...
>>
>>    $ make src/factor.o
>>    src/factor.c:154:0: error: macro "__GMP_GNUC_PREREQ" is not used
>> [-Werror=3Dunused-macros]
>>
>> It is used by some configs in longlong.h.  It cannot be removed unless
>> you fork longlong.h.
>
> Hi Torbj=F6rn,
>
> FYI, I made this small change to longlong.h a month ago:
>
>      build: avoid warning about unused macro
>      ...
>      * src/longlong.h (__GMP_DECLSPEC): Define if not already defined.
>
> +#ifndef __GMP_DECLSPEC
> +#define __GMP_DECLSPEC /* empty */
> +#endif
> +
>
> ...
>>    src/factor.c:2146:19: error: variable '_p0' set but not used
>> [-Werror=3Dunused-but-set-variable]
>>
>>    The above point to redundant processing in umul_ppmm()
>>    (or at least our use of it).
>>
>> The code sometimes needs the upper half of a product, but umul_ppmm
>> generates the full product as two halves.  You could insert bogus
>> dependencies on the low half, most likely making generated code worse.
>> Or remove the bogus warning.

I'll remove the warnings without impacting code quality.

> P=E1draig,
> If you don't find a cleaner solution, I wouldn't mind marking those
> variables with ATTRIBUTE_UNUSED when HAVE_GMP is not defined.  E.g.,
>
>      #if HAVE_GMP
>      # define UNUSED_WITH_NO_GMP /* empty */
>      #else
>      # define UNUSED_WITH_NO_GMP ATTRIBUTE_UNUSED
>      #endif
>
> Alternatively, and cleaner still, disable the -Wunused-but-set-variable
> option when configure detects no GMP support.  These days, building
> coreutils without GMP support seems less and less relevant.
>
> Finally, the simplest option of all would be fine, too: do nothing,
> and let those who configure with --enable-gcc-warnings figure out
> that they can get past this by building with "make WERROR_CFLAGS=3D".
>
>>    src/factor.c: At top level:
>>    src/factor.c:151:0: error: macro "ASSERT" is not used [-Werror=3Dun=
used-macros]
>>    src/factor.c:154:0: error: macro "__GMP_GNUC_PREREQ" is not used
>> [-Werror=3Dunused-macros]
>>
>> I fail to understand how anybody can regard an unused macro as an
>> *error*.
>
> When configured with gcc and --enable-gcc-warnings we enable -Werror,
> to ensure that no warnings slip by unnoticed.
> That is not the default, though I'm tempted to make it
> the default when building from git.

Already the case since 47fd706, hence why a little more important to clea=
n up.

> Yes, we have high standards.
>
>>    I'll clean up these tomorrow.
>>
>> Aren't this Draconian options ("ask the compiler to nag about everythi=
ng
>> it can, then treat nagging as errors in the code") self-defeating?  Yo=
u
>> need to avoid natural ways of writing things, and instead go for
>> contorted solutions.  I spent a few hours trying to satisfy your deman=
ds
>> in this area, and I am sure you maintainers have spent a lot of time o=
n
>> it.
>
> We've learned that while many of the warnings are
> not about real bugs, some do indicate real problems.
> An unused macro or variable could well indicate a typo
> in the definition/declaration or in all uses.
>
>> I for one prefer to spend my time on improving GNU, not define an
>> artifical goal like this one, and work on satifying that.
>
> We have moved to using very strict warning settings gradually over the
> years, carefully disabling the few warning options for which the cost
> consistently outweighs the benefit.
>
> We really do believe that what we are doing is worthwhile.

The onus is on those who know the code (now),
to minimize warnings to ease maintenance down the line.

thanks,
P=E1draig.


From MAILER-DAEMON Tue Oct 23 05:44:48 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQb2W-0006pu-9Y
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 05:44:48 -0400
Received: from eggs.gnu.org ([208.118.235.92]:35681)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQb2Q-0006md-40
	for coreutils@gnu.org; Tue, 23 Oct 2012 05:44:46 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQb2L-0001A8-JJ
	for coreutils@gnu.org; Tue, 23 Oct 2012 05:44:42 -0400
Received: from mx.meyering.net ([88.168.87.75]:47544)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQb2L-0001A1-3s
	for coreutils@gnu.org; Tue, 23 Oct 2012 05:44:37 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id CD43B600BE;
	Tue, 23 Oct 2012 11:44:35 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: more compile warnings with new factor
In-Reply-To: <50865BB9.4020602@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?=
	=?iso-8859-1?Q?g?= Brady"'s message of
	"Tue, 23 Oct 2012 09:56:25 +0100")
References: <5085483D.7040903@draigBrady.com>
	<5085EA74.3080003@draigBrady.com> <86ehkpof14.fsf@shell.gmplib.org>
	<874nllwryp.fsf@rho.meyering.net> <50865BB9.4020602@draigBrady.com>
Date: Tue, 23 Oct 2012 11:44:35 +0200
Message-ID: <87y5ixv7y4.fsf@rho.meyering.net>
Lines: 198
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Torbjorn Granlund <tg@gmplib.org>, Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 09:44:46 -0000

P=E1draig Brady wrote:
> On 10/23/2012 08:46 AM, Jim Meyering wrote:
...
>> When configured with gcc and --enable-gcc-warnings we enable -Werror,
>> to ensure that no warnings slip by unnoticed.
>> That is not the default, though I'm tempted to make it
>> the default when building from git.
>
> Already the case since 47fd706, hence why a little more important to clea=
n up.

Thanks for the reminder.  Eric enabled that for coreutils, already.
I knew he'd done it for libvirt.  I even ACK'd it for coreutils.
The problem for me was that the same hadn't been done for other projects
I tend, so I always use --enable-gcc-warnings and thus hadn't noticed the
difference.

This is a good reason to enable that consistently.  Eric, since the
log (modulo small edits) and patch are yours, you're the author, so I'll
wait for your ACK before pushing these to their respective repositories.
In order, those are:

  grep
  diffutils
  idutils
  cppi
  parted

The logs are identical, as are the patches, modulo offsets.

>From 85eaa86258bbdc17894355a1720dc9efda9044ed Mon Sep 17 00:00:00 2001
From: Eric Blake <eblake@redhat.com>
Date: Tue, 23 Oct 2012 11:30:29 +0200
Subject: [PATCH] build: default to --enable-gcc-warnings in a git tree

Anyone building from cloned sources can be assumed to have a new
enough environment, such that enabling gcc warnings by default will
be useful.  Tarballs still default to no warnings, and the default
can still be overridden with --disable-gcc-warnings.
* configure.ac (gl_gcc_warnings): Set default based on environment.
---
 configure.ac | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index a6168c7..1e51ffc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -94,7 +94,11 @@ AC_ARG_ENABLE([gcc-warnings],
      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) =
;;
    esac
    gl_gcc_warnings=3D$enableval],
-  [gl_gcc_warnings=3Dno]
+  [if test -d "$srcdir"/.git; then
+     gl_gcc_warnings=3Dyes
+   else
+     gl_gcc_warnings=3Dno
+   fi]
 )

 if test "$gl_gcc_warnings" =3D yes; then
--
1.8.0

>From 01d92dba155d9ad87eaf0378876e0c67285c2075 Mon Sep 17 00:00:00 2001
From: Eric Blake <eblake@redhat.com>
Date: Tue, 23 Oct 2012 11:06:48 +0200
Subject: [PATCH] build: default to --enable-gcc-warnings in a git tree

Anyone building from cloned sources can be assumed to have a new
enough environment, such that enabling gcc warnings by default will
be useful.  Tarballs still default to no warnings, and the default
can still be overridden with --disable-gcc-warnings.
* configure.ac (gl_gcc_warnings): Set default based on environment.
---
 configure.ac | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index d6e52c4..18ff554 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,7 +47,11 @@ AC_ARG_ENABLE([gcc-warnings],
      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) =
;;
    esac
    gl_gcc_warnings=3D$enableval],
-  [gl_gcc_warnings=3Dno]
+  [if test -d "$srcdir"/.git; then
+     gl_gcc_warnings=3Dyes
+   else
+     gl_gcc_warnings=3Dno
+   fi]
 )

 if test "$gl_gcc_warnings" =3D yes; then
--
1.8.0

>From a6211c988649214a6cfaa10ba13d77b8e65a8fff Mon Sep 17 00:00:00 2001
From: Eric Blake <eblake@redhat.com>
Date: Tue, 23 Oct 2012 11:08:51 +0200
Subject: [PATCH] build: default to --enable-gcc-warnings in a git tree

Anyone building from cloned sources can be assumed to have a new
enough environment, such that enabling gcc warnings by default will
be useful.  Tarballs still default to no warnings, and the default
can still be overridden with --disable-gcc-warnings.
* configure.ac (gl_gcc_warnings): Set default based on environment.
---
 configure.ac | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 4716744..b80a85d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,7 +29,11 @@ AC_ARG_ENABLE([gcc-warnings],
      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) =
;;
    esac
    gl_gcc_warnings=3D$enableval],
-  [gl_gcc_warnings=3Dno]
+  [if test -d "$srcdir"/.git; then
+     gl_gcc_warnings=3Dyes
+   else
+     gl_gcc_warnings=3Dno
+   fi]
 )

 if test "$gl_gcc_warnings" =3D yes; then
--
1.8.0

>From 27a0e658f90a39b7f85371918486738306f8b11d Mon Sep 17 00:00:00 2001
From: Eric Blake <eblake@redhat.com>
Date: Tue, 23 Oct 2012 11:08:17 +0200
Subject: [PATCH] build: default to --enable-gcc-warnings in a git tree

Anyone building from cloned sources can be assumed to have a new
enough environment, such that enabling gcc warnings by default will
be useful.  Tarballs still default to no warnings, and the default
can still be overridden with --disable-gcc-warnings.
* configure.ac (gl_gcc_warnings): Set default based on environment.
---
 configure.ac | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 7897f5b..81e5fbb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,7 +28,11 @@ AC_ARG_ENABLE([gcc-warnings],
      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) =
;;
    esac
    gl_gcc_warnings=3D$enableval],
-  [gl_gcc_warnings=3Dno]
+  [if test -d "$srcdir"/.git; then
+     gl_gcc_warnings=3Dyes
+   else
+     gl_gcc_warnings=3Dno
+   fi]
 )

 if test "$gl_gcc_warnings" =3D yes; then
--
1.8.0

>From d3a81337ff149294b7cf63c45a61ffa24fa542c5 Mon Sep 17 00:00:00 2001
From: Eric Blake <eblake@redhat.com>
Date: Tue, 23 Oct 2012 11:07:29 +0200
Subject: [PATCH] build: default to --enable-gcc-warnings in a git tree

Anyone building from cloned sources can be assumed to have a new
enough environment, such that enabling gcc warnings by default will
be useful.  Tarballs still default to no warnings, and the default
can still be overridden with --disable-gcc-warnings.
* configure.ac (gl_gcc_warnings): Set default based on environment.
---
 configure.ac | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 832fc20..417f325 100644
--- a/configure.ac
+++ b/configure.ac
@@ -187,7 +187,11 @@ AC_ARG_ENABLE([gcc-warnings],
      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) =
;;
    esac
    gl_gcc_warnings=3D$enableval],
-  [gl_gcc_warnings=3Dno]
+  [if test -d "$srcdir"/.git; then
+     gl_gcc_warnings=3Dyes
+   else
+     gl_gcc_warnings=3Dno
+   fi]
 )

 if test "$gl_gcc_warnings" =3D yes; then
--
1.8.0


From MAILER-DAEMON Tue Oct 23 06:21:08 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQbbg-000139-Hm
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 06:21:08 -0400
Received: from eggs.gnu.org ([208.118.235.92]:53173)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQbbY-000109-Rf
	for coreutils@gnu.org; Tue, 23 Oct 2012 06:21:07 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQbbS-0003aj-Ff
	for coreutils@gnu.org; Tue, 23 Oct 2012 06:21:00 -0400
Received: from mx.meyering.net ([88.168.87.75]:47622)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQbbS-0003aZ-1d
	for coreutils@gnu.org; Tue, 23 Oct 2012 06:20:54 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 538B360081;
	Tue, 23 Oct 2012 12:20:53 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: more compile warnings with new factor
In-Reply-To: <50865BB9.4020602@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?=
	=?iso-8859-1?Q?g?= Brady"'s message of
	"Tue, 23 Oct 2012 09:56:25 +0100")
References: <5085483D.7040903@draigBrady.com>
	<5085EA74.3080003@draigBrady.com> <86ehkpof14.fsf@shell.gmplib.org>
	<874nllwryp.fsf@rho.meyering.net> <50865BB9.4020602@draigBrady.com>
Date: Tue, 23 Oct 2012 12:20:53 +0200
Message-ID: <87sj95v69m.fsf@rho.meyering.net>
Lines: 92
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Torbjorn Granlund <tg@gmplib.org>, Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 10:21:07 -0000

P=E1draig Brady wrote:
> On 10/23/2012 08:46 AM, Jim Meyering wrote:
>> Torbjorn Granlund wrote:
>>> P=E1draig Brady <P@draigBrady.com> writes:
...
>>> Aren't this Draconian options ("ask the compiler to nag about everything
>>> it can, then treat nagging as errors in the code") self-defeating?  You
>>> need to avoid natural ways of writing things, and instead go for
>>> contorted solutions.  I spent a few hours trying to satisfy your demands
>>> in this area, and I am sure you maintainers have spent a lot of time on
>>> it.
>>
>> We've learned that while many of the warnings are
>> not about real bugs, some do indicate real problems.
>> An unused macro or variable could well indicate a typo
>> in the definition/declaration or in all uses.
>>
>>> I for one prefer to spend my time on improving GNU, not define an
>>> artifical goal like this one, and work on satifying that.
>>
>> We have moved to using very strict warning settings gradually over the
>> years, carefully disabling the few warning options for which the cost
>> consistently outweighs the benefit.
>>
>> We really do believe that what we are doing is worthwhile.
>
> The onus is on those who know the code (now),
> to minimize warnings to ease maintenance down the line.

Precisely.  We are in the unusual position of being able to take
a very long view of software "health".  That puts a large weight
on long-term maintainability, sharing responsibility, documenting, etc.

In that spirit, and considering the little pang :-) I felt last night at
the dearth of comments in factor.c, we should add more comments there.
Each function should have a comment that describes what it does
in terms of its arguments.  To see a list of candidates, run this

    grep -A1 -B3 '^static' src/factor.c

Many of its macros deserve comments, too.

I'll start:
(just writing the comment for factor made me see
that I would prefer to have it take an algorithm-specifying
parameter rather than use that global variable.)

>From 225f340c367e2618b3e7d56c506893ea1c6e567f Mon Sep 17 00:00:00 2001
From: Jim Meyering <jim@meyering.net>
Date: Tue, 23 Oct 2012 12:08:58 +0200
Subject: [PATCH] factor: add comments

* src/factor.c (is_square): Use active voice in comment, not passive.
(factor): Add function-describing comment.
(mp_factor): Likewise.
---
 src/factor.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/factor.c b/src/factor.c
index 73c59e9..e7d152b 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -1792,7 +1792,7 @@ isqrt2 (uintmax_t nh, uintmax_t nl)
 #define MAGIC65 ((uint64_t) 0x218a019866014613ULL)
 #define MAGIC11 0x23b

-/* Returns the square root if the input is a square, otherwise 0. */
+/* Return the square root if the input is a square, otherwise 0. */
 static uintmax_t _GL_ATTRIBUTE_CONST
 is_square (uintmax_t x)
 {
@@ -2167,6 +2167,8 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, stru=
ct factors *factors)
   return false;
 }

+/* Compute the prime factors of the 128-bit number (T1,T0), and put the
+   results in FACTORS.  Use the algorithm selected by the global ALG.  */
 static void
 factor (uintmax_t t1, uintmax_t t0, struct factors *factors)
 {
@@ -2197,6 +2199,8 @@ factor (uintmax_t t1, uintmax_t t0, struct factors *f=
actors)
 }

 #if HAVE_GMP
+/* Use Pollard-rho to compute the prime factors of
+   arbitrary-precision T, and put the results in FACTORS.  */
 static void
 mp_factor (mpz_t t, struct mp_factors *factors)
 {
--
1.8.0


From MAILER-DAEMON Tue Oct 23 07:23:25 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQcZx-0002Kd-8N
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 07:23:25 -0400
Received: from eggs.gnu.org ([208.118.235.92]:54819)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQcZu-0002KX-VT
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:23 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQcZu-00051R-2p
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:22 -0400
Received: from mx1.redhat.com ([209.132.183.28]:2730)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQcZt-00051D-QV
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:21 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9NBNKkf017288
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Tue, 23 Oct 2012 07:23:20 -0400
Received: from pb-n5110.redhat.com (ovpn-116-36.ams2.redhat.com [10.36.116.36])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9NBNIYH023455
	for <coreutils@gnu.org>; Tue, 23 Oct 2012 07:23:19 -0400
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
To: coreutils@gnu.org
Subject: Re: more compile warnings with new factor
Date: Tue, 23 Oct 2012 12:23:12 +0100
Message-Id: <1350991395-12350-1-git-send-email-P@draigBrady.com>
In-Reply-To: <50865BB9.4020602@draigBrady.com>
References: <50865BB9.4020602@draigBrady.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9NBNKkf017288
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 11:23:23 -0000

This patchset should address all factor
compiler issues in this thread.

cheers,
P=C3=A1draig.



From MAILER-DAEMON Tue Oct 23 07:23:36 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQca8-0002QY-DL
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 07:23:36 -0400
Received: from eggs.gnu.org ([208.118.235.92]:54863)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQca1-0002OS-J5
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:35 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQcZv-00051r-OE
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:29 -0400
Received: from mx1.redhat.com ([209.132.183.28]:53991)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQcZv-00051f-G6
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:23 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9NBNLqS020042
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 23 Oct 2012 07:23:21 -0400
Received: from pb-n5110.redhat.com (ovpn-116-36.ams2.redhat.com [10.36.116.36])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9NBNIYI023455; Tue, 23 Oct 2012 07:23:20 -0400
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
To: coreutils@gnu.org
Subject: [PATCH 1/3] build: avoid build failure on some sparc systems
Date: Tue, 23 Oct 2012 12:23:13 +0100
Message-Id: <1350991395-12350-2-git-send-email-P@draigBrady.com>
In-Reply-To: <1350991395-12350-1-git-send-email-P@draigBrady.com>
References: <50865BB9.4020602@draigBrady.com>
	<1350991395-12350-1-git-send-email-P@draigBrady.com>
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 11:23:35 -0000

* src/longlong.h: Restrict some sparc assembly variants
to sparc V9. This was seen to be an issue with newer
sparc systems with default gcc CPU options.
---
 src/longlong.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/longlong.h b/src/longlong.h
index 510f40e..173afb9 100644
--- a/src/longlong.h
+++ b/src/longlong.h
@@ -1745,7 +1745,7 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, UWtype);
 #endif /* udiv_qrnnd */
 #endif /* __sparc__ */
 
-#if defined (__sparc__) && W_TYPE_SIZE == 64
+#if (defined (__sparc_v9) || defined (__sparc_v9__)) && W_TYPE_SIZE == 64
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ (								\
        "addcc	%r4,%5,%1\n"						\
-- 
1.7.6.4



From MAILER-DAEMON Tue Oct 23 07:23:38 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQcaA-0002T5-Gi
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 07:23:38 -0400
Received: from eggs.gnu.org ([208.118.235.92]:54868)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQca2-0002OT-SO
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:36 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQcZw-000526-Bt
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:30 -0400
Received: from mx1.redhat.com ([209.132.183.28]:58840)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQcZw-00051v-3n
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:24 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9NBNMs5020048
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 23 Oct 2012 07:23:22 -0400
Received: from pb-n5110.redhat.com (ovpn-116-36.ams2.redhat.com [10.36.116.36])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9NBNIYJ023455; Tue, 23 Oct 2012 07:23:21 -0400
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
To: coreutils@gnu.org
Subject: [PATCH 2/3] build: avoid compile warnings in factor.c on some systems
Date: Tue, 23 Oct 2012 12:23:14 +0100
Message-Id: <1350991395-12350-3-git-send-email-P@draigBrady.com>
In-Reply-To: <1350991395-12350-1-git-send-email-P@draigBrady.com>
References: <50865BB9.4020602@draigBrady.com>
	<1350991395-12350-1-git-send-email-P@draigBrady.com>
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 11:23:36 -0000

* src/factor.c (factor_using_pollard_rho2): On some systems
(like sparc) we need to promote all addmod2() parameters
to uintmax_t to avoid warnings.
---
 src/factor.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/factor.c b/src/factor.c
index 73c59e9..539a686 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -1532,7 +1532,7 @@ factor_using_pollard_rho2 (uintmax_t n1, uintmax_t n0, unsigned long int a,
             {
               x0 = mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
               x1 = r1m;
-              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
+              addmod2 (x1, x0, x1, x0, 0, (uintmax_t) a, n1, n0);
 
               submod2 (t1, t0, z1, z0, x1, x0, n1, n0);
               P0 = mulredc2 (&r1m, P1, P0, t1, t0, n1, n0, ni);
@@ -1555,7 +1555,7 @@ factor_using_pollard_rho2 (uintmax_t n1, uintmax_t n0, unsigned long int a,
             {
               x0 = mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
               x1 = r1m;
-              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
+              addmod2 (x1, x0, x1, x0, 0, (uintmax_t) a, n1, n0);
             }
           y1 = x1; y0 = x0;
         }
@@ -1565,7 +1565,7 @@ factor_using_pollard_rho2 (uintmax_t n1, uintmax_t n0, unsigned long int a,
         {
           y0 = mulredc2 (&r1m, y1, y0, y1, y0, n1, n0, ni);
           y1 = r1m;
-          addmod2 (y1, y0, y1, y0, 0, a, n1, n0);
+          addmod2 (y1, y0, y1, y0, 0, (uintmax_t) a, n1, n0);
 
           submod2 (t1, t0, z1, z0, y1, y0, n1, n0);
           g0 = gcd2_odd (&g1, t1, t0, n1, n0);
-- 
1.7.6.4



From MAILER-DAEMON Tue Oct 23 07:23:39 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQcaB-0002XM-RZ
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 07:23:39 -0400
Received: from eggs.gnu.org ([208.118.235.92]:54875)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQca4-0002OU-8o
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:38 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQcZx-00052O-Kr
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:32 -0400
Received: from mx1.redhat.com ([209.132.183.28]:41376)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQcZx-00052D-CU
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:23:25 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9NBNNlD017301
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 23 Oct 2012 07:23:23 -0400
Received: from pb-n5110.redhat.com (ovpn-116-36.ams2.redhat.com [10.36.116.36])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9NBNIYK023455; Tue, 23 Oct 2012 07:23:22 -0400
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
To: coreutils@gnu.org
Subject: [PATCH 3/3] build: avoid warnings about unused variables and macros
Date: Tue, 23 Oct 2012 12:23:15 +0100
Message-Id: <1350991395-12350-4-git-send-email-P@draigBrady.com>
In-Reply-To: <1350991395-12350-1-git-send-email-P@draigBrady.com>
References: <50865BB9.4020602@draigBrady.com>
	<1350991395-12350-1-git-send-email-P@draigBrady.com>
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 11:23:38 -0000

src/factor.c (__GMP_DECLSPEC): Move back from longlong.h
to treat consistently with other stub macros.
(__GMP_GNUC_PREREQ): Reference to avoid -Wunused-macros warning.
(__GMP_DECLSPEC): Likewise.
(ASSERT): Likewise.
(__clz_tab): Likewise.
(factor_using_division): Mark variable as unused.
(mulredc): Likewise.
(mulredc2): Likewise.
(divexact_21): Likewise.
---
 src/factor.c   |   18 +++++++++++++-----
 src/longlong.h |    4 ----
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/factor.c b/src/factor.c
index 539a686..db7fd95 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -148,10 +148,19 @@ typedef unsigned long int UDItype;
 # endif
 # define LONGLONG_STANDALONE     /* Don't require GMP's longlong.h mdep files */
 # define ASSERT(x)               /* FIXME make longlong.h really standalone */
+# define __GMP_DECLSPEC          /* FIXME make longlong.h really standalone */
 # define __clz_tab factor_clz_tab /* Rename to avoid glibc collision */
 # ifndef __GMP_GNUC_PREREQ
 #  define __GMP_GNUC_PREREQ(a,b) 1
 # endif
+
+/* These stub macros are only used in longlong.h in certain system compiler
+   combinations, so ensure usage to avoid -Wunused-macros warnings.  */
+# if __GMP_GNUC_PREREQ(1,1) && defined (__clz_tab)
+ASSERT (1)
+__GMP_DECLSPEC
+# endif
+
 # if _ARCH_PPC
 #  define HAVE_HOST_CPU_FAMILY_powerpc 1
 # endif
@@ -168,7 +177,6 @@ const unsigned char factor_clz_tab[129] =
 # endif
 
 #else /* not USE_LONGLONG_H */
-
 # define W_TYPE_SIZE (8 * sizeof (uintmax_t))
 # define __ll_B ((uintmax_t) 1 << (W_TYPE_SIZE / 2))
 # define __ll_lowpart(t)  ((uintmax_t) (t) & (__ll_B - 1))
@@ -751,7 +759,7 @@ factor_using_division (uintmax_t *t1p, uintmax_t t1, uintmax_t t0,
     {
       for (;;)
         {
-          uintmax_t q1, q0, hi, lo;
+          uintmax_t q1, q0, hi, lo ATTRIBUTE_UNUSED;
 
           q0 = t0 * primes_dtab[i].binv;
           umul_ppmm (hi, lo, q0, p);
@@ -893,7 +901,7 @@ static const unsigned char  binvert_table[128] =
     _q0 = (u0) * _di;                                                   \
     if ((u1) >= (d))                                                    \
       {                                                                 \
-        uintmax_t _p1, _p0;                                             \
+        uintmax_t _p1, _p0 ATTRIBUTE_UNUSED;                            \
         umul_ppmm (_p1, _p0, _q0, d);                                   \
         (q1) = ((u1) - _p1) * _di;                                      \
         (q0) = _q0;                                                     \
@@ -941,7 +949,7 @@ static const unsigned char  binvert_table[128] =
 static inline uintmax_t
 mulredc (uintmax_t a, uintmax_t b, uintmax_t m, uintmax_t mi)
 {
-  uintmax_t rh, rl, q, th, tl, xh;
+  uintmax_t rh, rl, q, th, tl ATTRIBUTE_UNUSED, xh;
 
   umul_ppmm (rh, rl, a, b);
   q = rl * mi;
@@ -961,7 +969,7 @@ mulredc2 (uintmax_t *r1p,
           uintmax_t a1, uintmax_t a0, uintmax_t b1, uintmax_t b0,
           uintmax_t m1, uintmax_t m0, uintmax_t mi)
 {
-  uintmax_t r1, r0, q, p1, p0, t1, t0, s1, s0;
+  uintmax_t r1, r0, q, p1, p0 ATTRIBUTE_UNUSED, t1, t0, s1, s0;
   mi = -mi;
   assert ( (a1 >> (W_TYPE_SIZE - 1)) == 0);
   assert ( (b1 >> (W_TYPE_SIZE - 1)) == 0);
diff --git a/src/longlong.h b/src/longlong.h
index 173afb9..8d71611 100644
--- a/src/longlong.h
+++ b/src/longlong.h
@@ -2055,10 +2055,6 @@ extern UWtype mpn_udiv_qrnnd_r (UWtype, UWtype, UWtype, UWtype *);
 __GMP_DECLSPEC UWtype __MPN(udiv_w_sdiv) (UWtype *, UWtype, UWtype, UWtype);
 #endif
 
-#ifndef __GMP_DECLSPEC
-#define __GMP_DECLSPEC /* empty */
-#endif
-
 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
 #if !defined (udiv_qrnnd)
 #define UDIV_NEEDS_NORMALIZATION 1
-- 
1.7.6.4



From MAILER-DAEMON Tue Oct 23 07:42:26 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQcsM-0007iv-Rb
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 07:42:26 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58039)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQcsK-0007hv-OZ
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:42:25 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQcsE-0002EL-Ja
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:42:24 -0400
Received: from mx.meyering.net ([88.168.87.75]:47787)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQcsE-0002DX-C9
	for coreutils@gnu.org; Tue, 23 Oct 2012 07:42:18 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 316566009D;
	Tue, 23 Oct 2012 13:42:16 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: [PATCH 3/3] build: avoid warnings about unused variables and
	macros
In-Reply-To: <1350991395-12350-4-git-send-email-P@draigBrady.com>
	(=?iso-8859-1?Q?=22P=E1draig?=
	Brady"'s message of "Tue, 23 Oct 2012 12:23:15 +0100")
References: <50865BB9.4020602@draigBrady.com>
	<1350991395-12350-1-git-send-email-P@draigBrady.com>
	<1350991395-12350-4-git-send-email-P@draigBrady.com>
Date: Tue, 23 Oct 2012 13:42:16 +0200
Message-ID: <87d309v2hz.fsf@rho.meyering.net>
Lines: 26
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 11:42:25 -0000

P=E1draig Brady wrote:
> src/factor.c (__GMP_DECLSPEC): Move back from longlong.h
> to treat consistently with other stub macros.
> (__GMP_GNUC_PREREQ): Reference to avoid -Wunused-macros warning.
> (__GMP_DECLSPEC): Likewise.
> (ASSERT): Likewise.
> (__clz_tab): Likewise.
> (factor_using_division): Mark variable as unused.

Thanks for addressing these!

Really tiny nit, but s/Mark/Mark a/
I mention it only because as-is, it made me think
factor_using_division was the "variable", when in fact it is merely
the function that contains the affected declaration.

> (mulredc): Likewise.
> (mulredc2): Likewise.
> (divexact_21): Likewise.
...
> @@ -751,7 +759,7 @@ factor_using_division (uintmax_t *t1p, uintmax_t t1, =
uintmax_t t0,
>      {
>        for (;;)
>          {
> -          uintmax_t q1, q0, hi, lo;
> +          uintmax_t q1, q0, hi, lo ATTRIBUTE_UNUSED;


From MAILER-DAEMON Tue Oct 23 08:14:20 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQdNE-0004Mp-04
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 08:14:20 -0400
Received: from eggs.gnu.org ([208.118.235.92]:36282)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdN3-0004M8-8w
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:14:18 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdMt-0003yp-Ow
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:14:09 -0400
Received: from mx.meyering.net ([88.168.87.75]:47865)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdMt-0003wN-HV
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:13:59 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id BD65060085;
	Tue, 23 Oct 2012 14:13:57 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: [PATCH 2/3] build: avoid compile warnings in factor.c on some
	systems
In-Reply-To: <1350991395-12350-3-git-send-email-P@draigBrady.com>
	(=?iso-8859-1?Q?=22P=E1draig?=
	Brady"'s message of "Tue, 23 Oct 2012 12:23:14 +0100")
References: <50865BB9.4020602@draigBrady.com>
	<1350991395-12350-1-git-send-email-P@draigBrady.com>
	<1350991395-12350-3-git-send-email-P@draigBrady.com>
Date: Tue, 23 Oct 2012 14:13:57 +0200
Message-ID: <877gqhv116.fsf@rho.meyering.net>
Lines: 48
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 12:14:18 -0000

P=E1draig Brady wrote:
> * src/factor.c (factor_using_pollard_rho2): On some systems
> (like sparc) we need to promote all addmod2() parameters
> to uintmax_t to avoid warnings.
> ---
>  src/factor.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/factor.c b/src/factor.c
> index 73c59e9..539a686 100644
> --- a/src/factor.c
> +++ b/src/factor.c
> @@ -1532,7 +1532,7 @@ factor_using_pollard_rho2 (uintmax_t n1, uintmax_t =
n0, unsigned long int a,
>              {
>                x0 =3D mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
>                x1 =3D r1m;
> -              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
> +              addmod2 (x1, x0, x1, x0, 0, (uintmax_t) a, n1, n0);
>
>                submod2 (t1, t0, z1, z0, x1, x0, n1, n0);
>                P0 =3D mulredc2 (&r1m, P1, P0, t1, t0, n1, n0, ni);
> @@ -1555,7 +1555,7 @@ factor_using_pollard_rho2 (uintmax_t n1, uintmax_t =
n0, unsigned long int a,
>              {
>                x0 =3D mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
>                x1 =3D r1m;
> -              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
> +              addmod2 (x1, x0, x1, x0, 0, (uintmax_t) a, n1, n0);
>              }
>            y1 =3D x1; y0 =3D x0;
>          }
> @@ -1565,7 +1565,7 @@ factor_using_pollard_rho2 (uintmax_t n1, uintmax_t =
n0, unsigned long int a,
>          {
>            y0 =3D mulredc2 (&r1m, y1, y0, y1, y0, n1, n0, ni);
>            y1 =3D r1m;
> -          addmod2 (y1, y0, y1, y0, 0, a, n1, n0);
> +          addmod2 (y1, y0, y1, y0, 0, (uintmax_t) a, n1, n0);
>
>            submod2 (t1, t0, z1, z0, y1, y0, n1, n0);
>            g0 =3D gcd2_odd (&g1, t1, t0, n1, n0);

Thanks.
I confirmed that this addresses the problem.

Did you consider other ways of addressing it,
say without adding that cast?  Imagine that
someone adds another addmod2 use in this code...
They will have to know to widen any argument that may
be narrower than uintmax_t.


From MAILER-DAEMON Tue Oct 23 08:17:22 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQdQA-0006KE-5q
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 08:17:22 -0400
Received: from eggs.gnu.org ([208.118.235.92]:50057)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdQ2-00067E-So
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:17:20 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdPx-00053t-1s
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:17:14 -0400
Received: from mx.meyering.net ([88.168.87.75]:47878)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdPw-00053f-RW
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:17:08 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 8DB3360128;
	Tue, 23 Oct 2012 14:17:07 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: [PATCH 1/3] build: avoid build failure on some sparc systems
In-Reply-To: <1350991395-12350-2-git-send-email-P@draigBrady.com>
	(=?iso-8859-1?Q?=22P=E1draig?=
	Brady"'s message of "Tue, 23 Oct 2012 12:23:13 +0100")
References: <50865BB9.4020602@draigBrady.com>
	<1350991395-12350-1-git-send-email-P@draigBrady.com>
	<1350991395-12350-2-git-send-email-P@draigBrady.com>
Date: Tue, 23 Oct 2012 14:17:07 +0200
Message-ID: <871ugpv0vw.fsf@rho.meyering.net>
Lines: 20
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 12:17:20 -0000

P=E1draig Brady wrote:
> * src/longlong.h: Restrict some sparc assembly variants
> to sparc V9. This was seen to be an issue with newer
> sparc systems with default gcc CPU options.
> ---
>  src/longlong.h |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/src/longlong.h b/src/longlong.h
> index 510f40e..173afb9 100644
> --- a/src/longlong.h
> +++ b/src/longlong.h
> @@ -1745,7 +1745,7 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, =
UWtype, UWtype);
>  #endif /* udiv_qrnnd */
>  #endif /* __sparc__ */
>
> -#if defined (__sparc__) && W_TYPE_SIZE =3D=3D 64
> +#if (defined (__sparc_v9) || defined (__sparc_v9__)) && W_TYPE_SIZE =3D=
=3D 64

Nice work.  Thank you.


From MAILER-DAEMON Tue Oct 23 08:28:12 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQdae-0006UC-R8
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 08:28:12 -0400
Received: from eggs.gnu.org ([208.118.235.92]:43315)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eblake@redhat.com>) id 1TQdaZ-0006T8-9u
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:28:11 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <eblake@redhat.com>) id 1TQdaU-0008So-Tn
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:28:07 -0400
Received: from mx1.redhat.com ([209.132.183.28]:45533)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eblake@redhat.com>) id 1TQdaU-0008Sf-MA
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:28:02 -0400
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9NCRvbh013116
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 23 Oct 2012 08:27:57 -0400
Received: from [10.3.113.32] (ovpn-113-32.phx2.redhat.com [10.3.113.32])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9NCRuv3027375; Tue, 23 Oct 2012 08:27:56 -0400
Message-ID: <50868D4B.8030503@redhat.com>
Date: Tue, 23 Oct 2012 06:27:55 -0600
From: Eric Blake <eblake@redhat.com>
Organization: Red Hat
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121016 Thunderbird/16.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: more compile warnings with new factor
References: <5085483D.7040903@draigBrady.com> <5085EA74.3080003@draigBrady.com>
	<86ehkpof14.fsf@shell.gmplib.org> <874nllwryp.fsf@rho.meyering.net>
	<50865BB9.4020602@draigBrady.com> <87y5ixv7y4.fsf@rho.meyering.net>
In-Reply-To: <87y5ixv7y4.fsf@rho.meyering.net>
X-Enigmail-Version: 1.4.5
OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature";
	boundary="------------enig8B62D47AD5FA91BE4DDEFEE4"
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: Torbjorn Granlund <tg@gmplib.org>, Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 12:28:12 -0000

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig8B62D47AD5FA91BE4DDEFEE4
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On 10/23/2012 03:44 AM, Jim Meyering wrote:

> This is a good reason to enable that consistently.  Eric, since the
> log (modulo small edits) and patch are yours, you're the author, so I'l=
l
> wait for your ACK before pushing these to their respective repositories=
=2E

Sure - go for it in all of these projects.

> In order, those are:
>=20
>   grep
>   diffutils
>   idutils
>   cppi
>   parted
>=20
> The logs are identical, as are the patches, modulo offsets.
>=20
>>From 85eaa86258bbdc17894355a1720dc9efda9044ed Mon Sep 17 00:00:00 2001
> From: Eric Blake <eblake@redhat.com>
> Date: Tue, 23 Oct 2012 11:30:29 +0200
> Subject: [PATCH] build: default to --enable-gcc-warnings in a git tree
>=20
> Anyone building from cloned sources can be assumed to have a new
> enough environment, such that enabling gcc warnings by default will
> be useful.  Tarballs still default to no warnings, and the default
> can still be overridden with --disable-gcc-warnings.
> * configure.ac (gl_gcc_warnings): Set default based on environment.

--=20
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


--------------enig8B62D47AD5FA91BE4DDEFEE4
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQEcBAEBCAAGBQJQho1LAAoJEKeha0olJ0NqYlcH/Rpt6dXtEkalJPuOXd3whjlY
bh3tGPJrKkqnS8mI6dXCw+ij9zbmatZlpNLuP9KW1PU2WAyBdfXX61TknqEFO1pv
mZKxY1UHmv4MfB/Sg8KweAgVwPR1yNU4Gcbx1B8Hy5fVfPRn4f+lcw2nWRxGJuG6
3FhSbkCTGAoCDHXOfegjRj8CMEdKrAASuJBn4jqz6qI9lqJfdkigowV4RDjqJLob
O25LtMF085SEIOTOswjDhd2J7AgEV51kI87gtSt4eA0gawNue9gveTK8nDnhIThu
puWlAr5/qOKsL7svS8JQbOpYIA3aKf095DRTp8Bvj6PSy4jpUdt9+H6HXdl7V3g=
=oGGq
-----END PGP SIGNATURE-----

--------------enig8B62D47AD5FA91BE4DDEFEE4--


From MAILER-DAEMON Tue Oct 23 08:34:52 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQdh6-00014N-5h
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 08:34:52 -0400
Received: from eggs.gnu.org ([208.118.235.92]:43599)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQdgy-0000t3-Mr
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:34:50 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQdgs-0002Gv-Kc
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:34:44 -0400
Received: from mx1.redhat.com ([209.132.183.28]:55125)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQdgs-0002Gq-D3
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:34:38 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9NCYagt012572
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 23 Oct 2012 08:34:36 -0400
Received: from [10.36.116.36] (ovpn-116-36.ams2.redhat.com [10.36.116.36])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9NCYYgZ019039
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Tue, 23 Oct 2012 08:34:35 -0400
Message-ID: <50868ED9.3040406@draigBrady.com>
Date: Tue, 23 Oct 2012 13:34:33 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: [PATCH 2/3] build: avoid compile warnings in factor.c on some
	systems
References: <50865BB9.4020602@draigBrady.com>
	<1350991395-12350-1-git-send-email-P@draigBrady.com>
	<1350991395-12350-3-git-send-email-P@draigBrady.com>
	<877gqhv116.fsf@rho.meyering.net>
In-Reply-To: <877gqhv116.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9NCYagt012572
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 12:34:50 -0000

On 10/23/2012 01:13 PM, Jim Meyering wrote:
> Thanks.
> I confirmed that this addresses the problem.
>
> Did you consider other ways of addressing it,
> say without adding that cast?  Imagine that
> someone adds another addmod2 use in this code...
> They will have to know to widen any argument that may
> be narrower than uintmax_t.

I agree it's not ideal,
though I couldn't really come up with anything really clean,
since it's a mixture of assembly and C.

I'd already pushed before I saw this comment.

thanks,
P=E1draig.


From MAILER-DAEMON Tue Oct 23 08:36:17 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQdiT-0001N1-PQ
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 08:36:17 -0400
Received: from eggs.gnu.org ([208.118.235.92]:55941)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQdiL-0001Mj-PT
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:36:16 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQdiF-0002tk-C4
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:36:09 -0400
Received: from mx1.redhat.com ([209.132.183.28]:18594)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQdiF-0002tf-3K
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:36:03 -0400
Received: from int-mx02.intmail.prod.int.phx2.redhat.com
	(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9NCa0Fb007360
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 23 Oct 2012 08:36:00 -0400
Received: from [10.36.116.36] (ovpn-116-36.ams2.redhat.com [10.36.116.36])
	by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9NCZuSn022901
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Tue, 23 Oct 2012 08:35:59 -0400
Message-ID: <50868F2C.9040301@draigBrady.com>
Date: Tue, 23 Oct 2012 13:35:56 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: more compile warnings with new factor
References: <5085483D.7040903@draigBrady.com> <5085EA74.3080003@draigBrady.com>
	<86ehkpof14.fsf@shell.gmplib.org> <874nllwryp.fsf@rho.meyering.net>
	<50865BB9.4020602@draigBrady.com> <87sj95v69m.fsf@rho.meyering.net>
In-Reply-To: <87sj95v69m.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9NCa0Fb007360
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: Torbjorn Granlund <tg@gmplib.org>, Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 12:36:16 -0000

On 10/23/2012 11:20 AM, Jim Meyering wrote:
> P=E1draig Brady wrote:
>> On 10/23/2012 08:46 AM, Jim Meyering wrote:
>>> Torbjorn Granlund wrote:
>>>> P=E1draig Brady <P@draigBrady.com> writes:
> ...
>>>> Aren't this Draconian options ("ask the compiler to nag about everyt=
hing
>>>> it can, then treat nagging as errors in the code") self-defeating?  =
You
>>>> need to avoid natural ways of writing things, and instead go for
>>>> contorted solutions.  I spent a few hours trying to satisfy your dem=
ands
>>>> in this area, and I am sure you maintainers have spent a lot of time=
 on
>>>> it.
>>>
>>> We've learned that while many of the warnings are
>>> not about real bugs, some do indicate real problems.
>>> An unused macro or variable could well indicate a typo
>>> in the definition/declaration or in all uses.
>>>
>>>> I for one prefer to spend my time on improving GNU, not define an
>>>> artifical goal like this one, and work on satifying that.
>>>
>>> We have moved to using very strict warning settings gradually over th=
e
>>> years, carefully disabling the few warning options for which the cost
>>> consistently outweighs the benefit.
>>>
>>> We really do believe that what we are doing is worthwhile.
>>
>> The onus is on those who know the code (now),
>> to minimize warnings to ease maintenance down the line.
>
> Precisely.  We are in the unusual position of being able to take
> a very long view of software "health".  That puts a large weight
> on long-term maintainability, sharing responsibility, documenting, etc.
>
> In that spirit, and considering the little pang :-) I felt last night a=
t
> the dearth of comments in factor.c, we should add more comments there.
> Each function should have a comment that describes what it does
> in terms of its arguments.  To see a list of candidates, run this
>
>      grep -A1 -B3 '^static' src/factor.c
>
> Many of its macros deserve comments, too.
>
> I'll start:
> (just writing the comment for factor made me see
> that I would prefer to have it take an algorithm-specifying
> parameter rather than use that global variable.)
>
>>From 225f340c367e2618b3e7d56c506893ea1c6e567f Mon Sep 17 00:00:00 2001
> From: Jim Meyering <jim@meyering.net>
> Date: Tue, 23 Oct 2012 12:08:58 +0200
> Subject: [PATCH] factor: add comments
>
> * src/factor.c (is_square): Use active voice in comment, not passive.
> (factor): Add function-describing comment.
> (mp_factor): Likewise.
> ---
>   src/factor.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/factor.c b/src/factor.c
> index 73c59e9..e7d152b 100644
> --- a/src/factor.c
> +++ b/src/factor.c
> @@ -1792,7 +1792,7 @@ isqrt2 (uintmax_t nh, uintmax_t nl)
>   #define MAGIC65 ((uint64_t) 0x218a019866014613ULL)
>   #define MAGIC11 0x23b
>
> -/* Returns the square root if the input is a square, otherwise 0. */
> +/* Return the square root if the input is a square, otherwise 0. */
>   static uintmax_t _GL_ATTRIBUTE_CONST
>   is_square (uintmax_t x)
>   {
> @@ -2167,6 +2167,8 @@ factor_using_squfof (uintmax_t n1, uintmax_t n0, =
struct factors *factors)
>     return false;
>   }
>
> +/* Compute the prime factors of the 128-bit number (T1,T0), and put th=
e
> +   results in FACTORS.  Use the algorithm selected by the global ALG. =
 */
>   static void
>   factor (uintmax_t t1, uintmax_t t0, struct factors *factors)
>   {
> @@ -2197,6 +2199,8 @@ factor (uintmax_t t1, uintmax_t t0, struct factor=
s *factors)
>   }
>
>   #if HAVE_GMP
> +/* Use Pollard-rho to compute the prime factors of
> +   arbitrary-precision T, and put the results in FACTORS.  */
>   static void
>   mp_factor (mpz_t t, struct mp_factors *factors)
>   {
> --
> 1.8.0
>

Yes these comments are appreciated,
as I needed to dig into the code a bit
mode that I would like to figure out things.

Please push.

thanks,
P=E1draig.


From MAILER-DAEMON Tue Oct 23 08:40:08 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQdmC-0003d5-T8
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 08:40:08 -0400
Received: from eggs.gnu.org ([208.118.235.92]:55073)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdm4-0003Yo-VC
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:40:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdm2-0003rB-36
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:40:00 -0400
Received: from mx.meyering.net ([88.168.87.75]:47932)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdm1-0003r0-SP
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:39:58 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 402096009D;
	Tue, 23 Oct 2012 14:39:57 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: more compile warnings with new factor
In-Reply-To: <50868F2C.9040301@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?=
	=?iso-8859-1?Q?g?= Brady"'s message of
	"Tue, 23 Oct 2012 13:35:56 +0100")
References: <5085483D.7040903@draigBrady.com>
	<5085EA74.3080003@draigBrady.com> <86ehkpof14.fsf@shell.gmplib.org>
	<874nllwryp.fsf@rho.meyering.net> <50865BB9.4020602@draigBrady.com>
	<87sj95v69m.fsf@rho.meyering.net> <50868F2C.9040301@draigBrady.com>
Date: Tue, 23 Oct 2012 14:39:57 +0200
Message-ID: <87a9vdtl9e.fsf@rho.meyering.net>
Lines: 8
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Torbjorn Granlund <tg@gmplib.org>, Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 12:40:06 -0000

P=E1draig Brady wrote:
> Yes these comments are appreciated,
> as I needed to dig into the code a bit
> mode that I would like to figure out things.
>
> Please push.

Done.


From MAILER-DAEMON Tue Oct 23 08:41:36 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQdnc-00042h-KA
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 08:41:36 -0400
Received: from eggs.gnu.org ([208.118.235.92]:55340)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdnW-00040L-0P
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:41:35 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdnQ-0004a1-2s
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:41:29 -0400
Received: from mx.meyering.net ([88.168.87.75]:47941)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQdnP-0004Zu-Rw
	for coreutils@gnu.org; Tue, 23 Oct 2012 08:41:23 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 0A14B6009D;
	Tue, 23 Oct 2012 14:41:23 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: [PATCH 2/3] build: avoid compile warnings in factor.c on some
	systems
In-Reply-To: <50868ED9.3040406@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?=
	=?iso-8859-1?Q?g?= Brady"'s message of
	"Tue, 23 Oct 2012 13:34:33 +0100")
References: <50865BB9.4020602@draigBrady.com>
	<1350991395-12350-1-git-send-email-P@draigBrady.com>
	<1350991395-12350-3-git-send-email-P@draigBrady.com>
	<877gqhv116.fsf@rho.meyering.net> <50868ED9.3040406@draigBrady.com>
Date: Tue, 23 Oct 2012 14:41:23 +0200
Message-ID: <874nlltl70.fsf@rho.meyering.net>
Lines: 18
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 12:41:35 -0000

P=E1draig Brady wrote:
> On 10/23/2012 01:13 PM, Jim Meyering wrote:
>> Thanks.
>> I confirmed that this addresses the problem.
>>
>> Did you consider other ways of addressing it,
>> say without adding that cast?  Imagine that
>> someone adds another addmod2 use in this code...
>> They will have to know to widen any argument that may
>> be narrower than uintmax_t.
>
> I agree it's not ideal,
> though I couldn't really come up with anything really clean,
> since it's a mixture of assembly and C.
>
> I'd already pushed before I saw this comment.

No problem.


From MAILER-DAEMON Tue Oct 23 13:46:12 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQiYO-0001K6-H5
	for mharc-coreutils@gnu.org; Tue, 23 Oct 2012 13:46:12 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49087)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQiYH-0001Gm-1A
	for coreutils@gnu.org; Tue, 23 Oct 2012 13:46:11 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQiYB-0003NQ-JF
	for coreutils@gnu.org; Tue, 23 Oct 2012 13:46:04 -0400
Received: from mx1.redhat.com ([209.132.183.28]:29500)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>)
	id 1TQiY3-0003J2-Sd; Tue, 23 Oct 2012 13:45:52 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9NHjnxI016346
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 23 Oct 2012 13:45:50 -0400
Received: from [10.36.116.36] (ovpn-116-36.ams2.redhat.com [10.36.116.36])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9NHgdBO030565
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Tue, 23 Oct 2012 13:42:40 -0400
Message-ID: <5086D70E.6050004@draigBrady.com>
Date: Tue, 23 Oct 2012 18:42:38 +0100
From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: info-gnu@gnu.org
Subject: coreutils-8.20 released [stable]
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9NHjnxI016346
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coordinator@translationproject.org, coreutils@gnu.org,
	coreutils-announce@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Oct 2012 17:46:11 -0000

This is to announce coreutils-8.20, a stable release.

There have been 173 commits by 15 people in the 9 weeks since 8.19.

Executive summary: 8.20 is mainly a bug fix release, including an importa=
nt
regression fix for cp since 8.11, where cp could corrupt copies on very
fragmented sparse input files.  A regression fix for factor since 7.0 was
included where it could output some composite numbers as prime.
The core of factor was rewritten to be much faster, and seq also
received a large performance boost (up to 70x) in the common case of
integers being incremented by 1.

See the NEWS below for a brief summary.

Thanks to everyone who has contributed!
The following people contributed changes to this release:

   Benno Schulenberg (3)
   Bernhard Voelker (4)
   Eric Blake (2)
   Erik Auerswald (1)
   Jim Meyering (60)
   Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy (1)
   Nick Alcock (1)
   Niels M=C3=B6ller (1)
   Nikolas Kallis (1)
   Ondrej Oprala (3)
   Pozs=C3=A1r Bal=C3=A1zs (1)
   P=C3=A1draig Brady (14)
   Rob Day (1)
   Stefano Lattarini (78)
   Torbj=C3=B6rn Granlund (3)

P=C3=A1draig [on behalf of the coreutils maintainers]
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Here is the GNU coreutils home page:
     http://gnu.org/s/coreutils/

For a summary of changes and contributors, see:
   http://git.sv.gnu.org/gitweb/?p=3Dcoreutils.git;a=3Dshortlog;h=3Dv8.20
or run this command from a git-cloned coreutils directory:
   git shortlog v8.19..v8.20

To summarize the 94 gnulib-related changes, run these commands
 From a git-cloned coreutils directory:
   git checkout v8.20
   git submodule summary v8.19

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


Here are the compressed sources and a GPG detached signature[*]:
   http://ftp.gnu.org/gnu/coreutils/coreutils-8.20.tar.xz
   http://ftp.gnu.org/gnu/coreutils/coreutils-8.20.tar.xz.sig

Use a mirror for higher download bandwidth:
   http://ftpmirror.gnu.org/coreutils/coreutils-8.20.tar.xz
   http://ftpmirror.gnu.org/coreutils/coreutils-8.20.tar.xz.sig

[*] Use a .sig file to verify that the corresponding file (without the
.sig suffix) is intact.  First, be sure to download both the .sig file
and the corresponding tarball.  Then, run a command like this:

   gpg --verify coreutils-8.20.tar.xz.sig

If that command fails because you don't have the required public key,
then run this command to import it:

   gpg --keyserver keys.gnupg.net --recv-keys DF6FD971306037D9

and rerun the 'gpg --verify' command.

This release was bootstrapped with the following tools:
   Autoconf 2.68
   Automake 1.11.6
   Gnulib v0.0-7675-gd245e6d
   Bison 2.4.3

NEWS

* Noteworthy changes in release 8.20 (2012-10-23) [stable]

** New features

   dd now accepts 'status=3Dnone' to suppress all informational output.

   md5sum now accepts the --tag option to print BSD-style output with GNU
   file name escaping.  This also affects sha1sum, sha224sum, sha256sum,
   sha384sum and sha512sum.

** Bug fixes

   cp could read from freed memory and could even make corrupt copies.
   This could happen with a very fragmented and sparse input file,
   on GNU/Linux file systems supporting fiemap extent scanning.
   This bug also affects mv when it resorts to copying, and install.
   [bug introduced in coreutils-8.11]

   cp --no-preserve=3Dmode now no longer preserves the original file's
   permissions but correctly sets mode specified by 0666 & ~umask

   du no longer emits a "disk-corrupted"-style diagnostic when it detects
   a directory cycle that is due to a bind-mounted directory.  Instead,
   it detects this precise type of cycle, diagnoses it as such and
   eventually exits nonzero.

   factor (when using gmp) would mistakenly declare some composite number=
s
   to be prime, e.g., 465658903, 2242724851, 6635692801 and many more.
   The fix makes factor somewhat slower (~25%) for ranges of consecutive
   numbers, and up to 8 times slower for some worst-case individual numbe=
rs.
   [bug introduced in coreutils-7.0, with GNU MP support]

   ls now correctly colors dangling symlinks when listing their containin=
g
   directories, with orphaned symlink coloring disabled in LS_COLORS.
   [bug introduced in coreutils-8.14]

   rm -i -d now prompts the user then removes an empty directory, rather
   than ignoring the -d option and failing with an 'Is a directory' error.
   [bug introduced in coreutils-8.19, with the addition of --dir (-d)]

   rm -r S/ (where S is a symlink-to-directory) no longer gives the inval=
id
   "Too many levels of symbolic links" diagnostic.
   [bug introduced in coreutils-8.6]

   seq now handles arbitrarily long non-negative whole numbers when the
   increment is 1 and when no format-changing option is specified.
   Before, this would infloop:
     b=3D100000000000000000000; seq $b $b
   [the bug dates back to the initial implementation]

** Changes in behavior

   nproc now diagnoses with an error, non option command line parameters.

** Improvements

   factor's core has been rewritten for speed and increased range.
   It can now factor numbers up to 2^128, even without GMP support.
   Its speed is from a few times better (for small numbers) to over
   10,000 times better (just below 2^64).  The new code also runs a
   deterministic primality test for each prime factor, not just a
   probabilistic test.

   seq is now up to 70 times faster than it was in coreutils-8.19 and pri=
or,
   but only with non-negative whole numbers, an increment of 1, and no
   format-changing options.

   stat and tail know about ZFS, VZFS and VMHGFS.  stat -f --format=3D%T =
now
   reports the file system type, and tail -f now uses inotify for files o=
n
   ZFS and VZFS file systems, rather than the default (for unknown file
   system types) of issuing a warning and reverting to polling.  tail -f
   still uses polling for files on VMHGFS file systems.

** Build-related

   root-only tests now check for permissions of our dummy user,
   $NON_ROOT_USERNAME, before trying to run binaries from the build direc=
tory.
   Before, we would get hard-to-diagnose reports of failing root-only tes=
ts.
   Now, those tests are skipped with a useful diagnostic when the root te=
sts
   are run without following the instructions in README.

   We now build most directories using non-recursive make rules.  I.e.,
   rather than running make in man/, lib/, src/, tests/, instead, the top
   level Makefile.am includes a $dir/local.mk that describes how to build
   the targets in the corresponding directory.  Two directories remain
   unconverted: po/, gnulib-tests/.  One nice side-effect is that the mor=
e
   accurate dependencies have eliminated a nagging occasional failure tha=
t
   was seen when running parallel "make syntax-check".

-----
also posted as: https://savannah.gnu.org/forum/forum.php?forum_id=3D7407


From MAILER-DAEMON Wed Oct 24 03:56:37 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQvpN-00028r-4p
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 03:56:37 -0400
Received: from eggs.gnu.org ([208.118.235.92]:43068)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQvpF-00028l-Da
	for coreutils@gnu.org; Wed, 24 Oct 2012 03:56:35 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQvp9-0004iU-Js
	for coreutils@gnu.org; Wed, 24 Oct 2012 03:56:29 -0400
Received: from mx.meyering.net ([88.168.87.75]:50452)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQvp9-0004iK-Am
	for coreutils@gnu.org; Wed, 24 Oct 2012 03:56:23 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 2C35A600EE;
	Wed, 24 Oct 2012 09:56:21 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Mike Frysinger <vapier@gentoo.org>
Subject: Re: [PATCH] build: do not require help2man at build-from-tarball time
In-Reply-To: <874nmytix4.fsf@rho.meyering.net> (Jim Meyering's message of
	"Sun, 16 Sep 2012 11:29:27 +0200")
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net>
Date: Wed, 24 Oct 2012 09:56:21 +0200
Message-ID: <87zk3cl2vu.fsf@rho.meyering.net>
Lines: 50
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 07:56:36 -0000

Jim Meyering wrote:
> Mike Frysinger wrote:
> ...
>>> I have mixed feelings.  If someone is modifying sources and expecting
>>> to be able to rebuild, they'd better have developer tools like perl.
>>>
>>> On the other hand, I dislike distributing a deliberately hamstrung
>>> Makefile.in, even though this wart is only in a generated file, that
>>> could easily be regenerated without the reduced dependency -- again,
>>> assuming proper tools.
>>>
>>> An added bonus of your approach: we would no longer need to distribute
>>> the man/*.1 files, and instead would generate them unconditionally, even
>>> from tarballs.
>>
>> i think this is a step backwards.  some people think of no perl as being
>> crippled while others think of it as pointless bloat.
>
> Yes, this dichotomy is what I'm most leery of.
>
>> if the man page already exists in the dist, i don't see why we'd actively
>> replace it with a man page that is known to be significantly worse to the point
>> of uselessness.
>
> That would be a problem, but let's examine the conditions
> required for that to happen:
>
>     Someone starts from a release tarball, changes source and then wants
>     to regenerated a man/*.1 file, yet they do not have perl installed.
>
> One consequence of not having perl is that they are unable to run
> a significant number of tests.  While there are comparatively
> few .pl test scripts, each typically runs many more tests than
> the average .sh test script.
>
> Hence, I conclude that perl is already a build prerequisite for
> any packager/installer who applies patches and expects to test their
> result.  Whether it is officially listed as a build-prerequisite in
> every distro's packaging system is another matter entirely.
>
> This is making me think that it is almost an obligation
> (force patchers to DRTR ;-) for us to list perl as a build-time
> prerequisite...
>
> I'll sleep on it.

Would anyone object to making perl a build-time prerequisite?
I.e., would this cause serious inconvenience?
If you're building on a system for which you do not run all of
the perl-dependent tests, you can't be very serious about quality.


From MAILER-DAEMON Wed Oct 24 04:03:23 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQvvv-00056G-3z
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 04:03:23 -0400
Received: from eggs.gnu.org ([208.118.235.92]:33147)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TQvvp-00054E-OZ
	for coreutils@gnu.org; Wed, 24 Oct 2012 04:03:22 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TQvvg-0006rK-Ay
	for coreutils@gnu.org; Wed, 24 Oct 2012 04:03:17 -0400
Received: from mx1.redhat.com ([209.132.183.28]:5293)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TQvvg-0006r5-2b
	for coreutils@gnu.org; Wed, 24 Oct 2012 04:03:08 -0400
Received: from int-mx01.intmail.prod.int.phx2.redhat.com
	(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9O836x1020167
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Wed, 24 Oct 2012 04:03:07 -0400
Received: from [10.34.4.104] (unused-4-104.brq.redhat.com [10.34.4.104])
	by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9O835iY032017
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <coreutils@gnu.org>; Wed, 24 Oct 2012 04:03:06 -0400
Message-ID: <5087A0B8.9090906@redhat.com>
Date: Wed, 24 Oct 2012 10:03:04 +0200
From: Ondrej Oprala <ooprala@redhat.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121009 Thunderbird/16.0
MIME-Version: 1.0
To: coreutils@gnu.org
Subject: pr: floating-point error
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 08:03:22 -0000

Hello,
one of our customers made a bug report, stating that pr -nNUM FILE
causes a floating point exception if NUM >= 32
and I would really like to hear your opinion on how to solve this.
The easiest solution would be to document the <32 limit for the -n option.
The more difficult one would be to support numbers of arbitrary length.
I was thinking about the second solution and  AFAIK the line number is not
used in any arithmetic (apart from incrementation), so it could be 
represented as
an array of digits, with a function incrementing the array from the 
rightmost element
as needed. Then we would just print out the array one element at a time. 
It would
probably cause a performance penalty though.
Thanks in advance for any advice or suggestions.

Cheers,
Ondrej


From MAILER-DAEMON Wed Oct 24 04:33:16 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQwOq-0001Iw-Sd
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 04:33:16 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37052)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQwOl-0001Ha-Ma
	for coreutils@gnu.org; Wed, 24 Oct 2012 04:33:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQwOf-00076Y-RZ
	for coreutils@gnu.org; Wed, 24 Oct 2012 04:33:11 -0400
Received: from mx1.redhat.com ([209.132.183.28]:27630)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQwOf-00076O-Je
	for coreutils@gnu.org; Wed, 24 Oct 2012 04:33:05 -0400
Received: from int-mx02.intmail.prod.int.phx2.redhat.com
	(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9O8X1ll008082
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Wed, 24 Oct 2012 04:33:01 -0400
Received: from [10.36.116.73] (ovpn-116-73.ams2.redhat.com [10.36.116.73])
	by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9O8WxtV008967
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Wed, 24 Oct 2012 04:33:00 -0400
Message-ID: <5087A7BA.4070405@draigBrady.com>
Date: Wed, 24 Oct 2012 09:32:58 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: [PATCH] build: do not require help2man at build-from-tarball time
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
In-Reply-To: <87zk3cl2vu.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9O8X1ll008082
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 08:33:15 -0000

On 10/24/2012 08:56 AM, Jim Meyering wrote:
> Would anyone object to making perl a build-time prerequisite?
> I.e., would this cause serious inconvenience?

Probably less inconvenience than a broken make -j ;)

> If you're building on a system for which you do not run all of
> the perl-dependent tests, you can't be very serious about quality.

If `make check` needs it, then it's a requirement IMHO.

Now I do really like the idea of minimizing dependencies,
so for graceful degradation without perl, I suppose
the best approach would be to skip the .pl tests and
`echo "warning"; touch $manpage`.

cheers,
P=E1draig.


From MAILER-DAEMON Wed Oct 24 04:54:28 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQwjM-0004n1-D5
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 04:54:28 -0400
Received: from eggs.gnu.org ([208.118.235.92]:35786)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQwjG-0004mp-VG
	for coreutils@gnu.org; Wed, 24 Oct 2012 04:54:27 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQwjB-0005Pi-80
	for coreutils@gnu.org; Wed, 24 Oct 2012 04:54:22 -0400
Received: from mx.meyering.net ([88.168.87.75]:50573)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQwjA-0005Pc-UJ
	for coreutils@gnu.org; Wed, 24 Oct 2012 04:54:17 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 63EC660128;
	Wed, 24 Oct 2012 10:54:15 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: [PATCH] build: do not require help2man at build-from-tarball time
In-Reply-To: <5087A7BA.4070405@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?=
	=?iso-8859-1?Q?g?= Brady"'s message of
	"Wed, 24 Oct 2012 09:32:58 +0100")
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com>
Date: Wed, 24 Oct 2012 10:54:15 +0200
Message-ID: <87txtkl07c.fsf@rho.meyering.net>
Lines: 36
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 08:54:27 -0000

P=E1draig Brady wrote:
> On 10/24/2012 08:56 AM, Jim Meyering wrote:
>> Would anyone object to making perl a build-time prerequisite?
>> I.e., would this cause serious inconvenience?
>
> Probably less inconvenience than a broken make -j ;)

Note that it is broken only when building from a tarball-based
build in which you have modified a source file.
However, with most distributions, that's precisely the use case:
download tarball, unpack, apply distro-specific patches and build.

>> If you're building on a system for which you do not run all of
>> the perl-dependent tests, you can't be very serious about quality.
>
> If `make check` needs it, then it's a requirement IMHO.

Depends on the definition of "need".
In order to run a decent percentage of tests, perl is needed.
However, it is not needed if all you care about is "make check" exiting
successfully (even though all perl-using tests were skipped).

> Now I do really like the idea of minimizing dependencies,
> so for graceful degradation without perl, I suppose
> the best approach would be to skip the .pl tests and

That is already done.

> `echo "warning"; touch $manpage`.

Sounds good.  I.e., it sounds like we want Stefano's patch, after all.

As you recall, a nice side effect is that we will
no longer distribute the generated man/*.1 files.

Stefano, would you care to rebase your patch?


From MAILER-DAEMON Wed Oct 24 05:12:48 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQx16-0007JT-Jh
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 05:12:48 -0400
Received: from eggs.gnu.org ([208.118.235.92]:33991)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TQx0y-0007IO-A3
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:12:48 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TQx0w-0002y4-RJ
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:12:40 -0400
Received: from mx1.redhat.com ([209.132.183.28]:47173)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TQx0w-0002xz-Iq
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:12:38 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9O9Cb15011746
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Wed, 24 Oct 2012 05:12:37 -0400
Received: from [10.34.4.104] (unused-4-104.brq.redhat.com [10.34.4.104])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9O9CZPL019937
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO)
	for <coreutils@gnu.org>; Wed, 24 Oct 2012 05:12:36 -0400
Message-ID: <5087B102.4020301@redhat.com>
Date: Wed, 24 Oct 2012 11:12:34 +0200
From: Ondrej Oprala <ooprala@redhat.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121009 Thunderbird/16.0
MIME-Version: 1.0
To: coreutils@gnu.org
Subject: pr: leading zeros omitted with certain arguments to the -n option
Content-Type: multipart/mixed; boundary="------------090308050801020805020905"
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 09:12:48 -0000

This is a multi-part message in MIME format.
--------------090308050801020805020905
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,
we've had a bug report from one of our customers recently, saying
pr -nNUM doesn't zero-pad line numbers on output with certain
values of NUM (for example 1-11, 13-14, 16-17...). The problem
seems to be the faulty format string that I fixed in the patch
attached. I've also added 2 test cases in tests/misc/pr.pl to
exercise the output with problematic as well as ok NUM values.
Cheers,
Ondrej

--------------090308050801020805020905
Content-Type: text/plain; charset=UTF-8;
 name="DIFF"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="DIFF"

>From 78e32d37ba174a50dad86b5b6d557a76755b957d Mon Sep 17 00:00:00 2001
From: Ondrej Oprala <ooprala@redhat.com>
Date: Wed, 24 Oct 2012 10:49:05 +0200
Subject: [PATCH] pr: fix omitted leading zeros with particular arguments to
 -n option

* NEWS: Mention the fix.
* src/pr.c (add_line_number): Change sprintf format string.
* tests/misc/pr.pl: Add a test case to exercise the change.
---
 NEWS             | 5 +++++
 src/pr.c         | 2 +-
 tests/misc/pr.pl | 6 +++++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 04721da..6b1a99b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Bug fixes
+
+  pr now properly zero-pads line numbers with arbitrary integer
+  arguments to the -n option.
+
 
 * Noteworthy changes in release 8.20 (2012-10-23) [stable]
 
diff --git a/src/pr.c b/src/pr.c
index e97c434..45e80e1 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -2034,7 +2034,7 @@ add_line_number (COLUMN *p)
   /* Cutting off the higher-order digits is more informative than
      lower-order cut off*/
   if (line_number < power_10)
-    sprintf (number_buff, "%*d", chars_per_number, line_number);
+    sprintf (number_buff, "%0*d", chars_per_number, line_number);
   else
     {
       left_cut = line_number % power_10;
diff --git a/tests/misc/pr.pl b/tests/misc/pr.pl
index 0f25e25..383b4ef 100755
--- a/tests/misc/pr.pl
+++ b/tests/misc/pr.pl
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# Exercise a bug with pr -m -s
+# Exercise a bug with pr -m -s and -n
 
 # Copyright (C) 2007-2012 Free Software Foundation, Inc.
 
@@ -33,6 +33,10 @@ my @Tests =
     {IN=>{2=>"m\tn\to\n"}},
     {IN=>{3=>"x\ty\tz\n"}},
      {OUT=>join("\t", qw(a b c m n o x y z)) . "\n"} ],
+   ['zeros1', '-n10 -t',
+    {IN=>"abc\n"}, {OUT=>"0000000001	abc\n"}],
+   ['zeros2', '-n12 -t',
+    {IN=>"abc\n"}, {OUT=>"000000000001	abc\n"}],
   );
 
 my $save_temps = $ENV{DEBUG};
-- 
1.7.11.7


--------------090308050801020805020905--


From MAILER-DAEMON Wed Oct 24 05:26:35 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQxER-0004B8-O1
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 05:26:35 -0400
Received: from eggs.gnu.org ([208.118.235.92]:60505)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQxEJ-00049A-SL
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:26:33 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQxE9-0007gj-4Q
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:26:27 -0400
Received: from mx1.redhat.com ([209.132.183.28]:19323)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQxE8-0007gd-Rz
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:26:17 -0400
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9O9QFtF026985
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Wed, 24 Oct 2012 05:26:16 -0400
Received: from [10.36.116.73] (ovpn-116-73.ams2.redhat.com [10.36.116.73])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9O9QDgD000472
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Wed, 24 Oct 2012 05:26:15 -0400
Message-ID: <5087B435.2090803@draigBrady.com>
Date: Wed, 24 Oct 2012 10:26:13 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Ondrej Oprala <ooprala@redhat.com>
Subject: Re: pr: floating-point error
References: <5087A0B8.9090906@redhat.com>
In-Reply-To: <5087A0B8.9090906@redhat.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9O9QFtF026985
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 09:26:34 -0000

On 10/24/2012 09:03 AM, Ondrej Oprala wrote:
> Hello,
> one of our customers made a bug report, stating that pr -nNUM FILE
> causes a floating point exception if NUM >=3D 32
> and I would really like to hear your opinion on how to solve this.
> The easiest solution would be to document the <32 limit for the -n opti=
on.
> The more difficult one would be to support numbers of arbitrary length.
> I was thinking about the second solution and  AFAIK the line number is =
not
> used in any arithmetic (apart from incrementation), so it could be repr=
esented as
> an array of digits, with a function incrementing the array from the rig=
htmost element
> as needed. Then we would just print out the array one element at a time=
. It would
> probably cause a performance penalty though.
> Thanks in advance for any advice or suggestions.

Ouch. Confirmed that this dumps core:

   echo . | pr -T -n.32

We can fix that up with something like the following.
I'll add a test and commit.

cheers,
P=E1draig.

diff --git a/src/pr.c b/src/pr.c
index e97c434..3fada19 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -630,10 +630,6 @@ static uintmax_t page_number;
     2    moo     4       hoo     6       zoo */
  static int line_number;

-/* With line_number overflow, we use power_10 to cut off the higher-orde=
r
-   digits of the line_number */
-static int power_10;
-
  /* (-n) True means lines should be preceded by numbers. */
  static bool numbered_lines =3D false;

@@ -1289,12 +1285,6 @@ init_parameters (int number_of_files)
           printing files in parallel. */
        if (parallel_files)
          chars_used_by_number =3D number_width;
-
-      /* We use power_10 to cut off the higher-order digits of the
-         line_number in function add_line_number */
-      tmp_i =3D chars_per_number;
-      for (power_10 =3D 1; tmp_i > 0; --tmp_i)
-        power_10 =3D 10 * power_10;
      }

    chars_per_column =3D (chars_per_line - chars_used_by_number
@@ -1306,7 +1296,8 @@ init_parameters (int number_of_files)
    if (numbered_lines)
      {
        free (number_buff);
-      number_buff =3D xmalloc (2 * chars_per_number);
+      number_buff =3D xmalloc (MAX (chars_per_number,
+                                  INT_BUFSIZE_BOUND (line_number)) + 1);
      }

    /* Pick the maximum between the tab width and the width of an
@@ -2029,19 +2020,13 @@ add_line_number (COLUMN *p)
  {
    int i;
    char *s;
-  int left_cut;
+  int num_width;

    /* Cutting off the higher-order digits is more informative than
-     lower-order cut off*/
-  if (line_number < power_10)
-    sprintf (number_buff, "%*d", chars_per_number, line_number);
-  else
-    {
-      left_cut =3D line_number % power_10;
-      sprintf (number_buff, "%0*d", chars_per_number, left_cut);
-    }
+     lower-order cut off. */
+  num_width =3D sprintf (number_buff, "%*d", chars_per_number, line_numb=
er);
    line_number++;
-  s =3D number_buff;
+  s =3D number_buff + (num_width - chars_per_number);
    for (i =3D chars_per_number; i > 0; i--)
      (p->char_func) (*s++);



From MAILER-DAEMON Wed Oct 24 05:32:16 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQxJw-0005ke-4b
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 05:32:16 -0400
Received: from eggs.gnu.org ([208.118.235.92]:55813)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TQxJs-0005kX-0O
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:32:14 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TQxJm-00011i-1w
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:32:11 -0400
Received: from mail-la0-f41.google.com ([209.85.215.41]:43294)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TQxJl-00011V-QW
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:32:05 -0400
Received: by mail-la0-f41.google.com with SMTP id p5so207046lag.0
	for <coreutils@gnu.org>; Wed, 24 Oct 2012 02:32:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=message-id:date:from:mime-version:to:cc:subject:references
	:in-reply-to:content-type:content-transfer-encoding;
	bh=zH8w1jeNFdsbTVMBk1yzPfHFrTLVCTJDqdKIVz5piRI=;
	b=eGMngkLhIIF+qvWPN/uEUa63/ujiNMn1sBj3ays9BZLhogt4sseA8BkxuDj97Owa0n
	9OSIZuD8/S96OCYhdE4d5xxuIXTaGNYaxix+WznN6vQueOMp6HyuoJLJdliyQSA59Ows
	16hWr5ZgkqaS3FhNura2Oorgvec0Gy1mpuTW71VQ7Uz62pmjjcH4nSL1lwirGtDwSL+n
	VKRj1hoXzlTSdR1AuolgrlUe8WF6tSOkomwgNltumOJ8ndpqObxwYJXq1YvSb97TsyT8
	MRTDr+ZrsADiFaTtonPt272xOqeGTCrboX4wG+8XVrCuqkDlTeu6fiGYG90ZdrmZkpHQ
	N5Cw==
Received: by 10.152.47.112 with SMTP id c16mr14017027lan.50.1351071122132;
	Wed, 24 Oct 2012 02:32:02 -0700 (PDT)
Received: from [192.168.178.21]
	(host247-100-dynamic.8-87-r.retail.telecomitalia.it. [87.8.100.247])
	by mx.google.com with ESMTPS id ps11sm4757247lab.12.2012.10.24.02.32.00
	(version=SSLv3 cipher=OTHER); Wed, 24 Oct 2012 02:32:01 -0700 (PDT)
Message-ID: <5087B58E.2040401@gmail.com>
Date: Wed, 24 Oct 2012 11:31:58 +0200
From: Stefano Lattarini <stefano.lattarini@gmail.com>
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: [PATCH] build: do not require help2man at build-from-tarball time
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com> <87txtkl07c.fsf@rho.meyering.net>
In-Reply-To: <87txtkl07c.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.85.215.41
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 09:32:15 -0000

On 10/24/2012 10:54 AM, Jim Meyering wrote:
> Pádraig Brady wrote:
>
>> `echo "warning"; touch $manpage`.
> 
> Sounds good.  I.e., it sounds like we want Stefano's patch, after all.
> 
> As you recall, a nice side effect is that we will
> no longer distribute the generated man/*.1 files.
> 
> Stefano, would you care to rebase your patch?
>
Will do soon.  Just give me some time to also re-test it ...

Regards,
  Stefano


From MAILER-DAEMON Wed Oct 24 05:47:58 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQxZ8-0000aS-V3
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 05:47:58 -0400
Received: from eggs.gnu.org ([208.118.235.92]:43566)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQxZ3-0000a3-0g
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:47:57 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQxYr-0005Y3-B4
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:47:52 -0400
Received: from mx1.redhat.com ([209.132.183.28]:7370)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQxYr-0005Xk-37
	for coreutils@gnu.org; Wed, 24 Oct 2012 05:47:41 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9O9ldGk025242
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Wed, 24 Oct 2012 05:47:39 -0400
Received: from [10.36.116.73] (ovpn-116-73.ams2.redhat.com [10.36.116.73])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9O9lb2E008874
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Wed, 24 Oct 2012 05:47:38 -0400
Message-ID: <5087B939.3080200@draigBrady.com>
Date: Wed, 24 Oct 2012 10:47:37 +0100
From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Ondrej Oprala <ooprala@redhat.com>
Subject: Re: pr: leading zeros omitted with certain arguments to the -n option
References: <5087B102.4020301@redhat.com>
In-Reply-To: <5087B102.4020301@redhat.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9O9ldGk025242
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 09:47:57 -0000

On 10/24/2012 10:12 AM, Ondrej Oprala wrote:
> Hi,
> we've had a bug report from one of our customers recently, saying
> pr -nNUM doesn't zero-pad line numbers on output with certain
> values of NUM (for example 1-11, 13-14, 16-17...). The problem
> seems to be the faulty format string that I fixed in the patch
> attached. I've also added 2 test cases in tests/misc/pr.pl to
> exercise the output with problematic as well as ok NUM values.

I think the leading zeros is the inconsistent case.
I also checked solaris and netbsd and they pad with spaces.
So my previous patch to handle arbitrary -n should suffice.

thanks,
P=C3=A1draig.


From MAILER-DAEMON Wed Oct 24 06:07:52 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQxsN-0008Py-W0
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 06:07:51 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37093)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQxsL-0008PI-6S
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:07:50 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQxsD-0002dF-3R
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:07:49 -0400
Received: from mx1.redhat.com ([209.132.183.28]:34674)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TQxsC-0002dB-RV
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:07:41 -0400
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9OA7bg2000758
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Wed, 24 Oct 2012 06:07:37 -0400
Received: from [10.36.116.73] (ovpn-116-73.ams2.redhat.com [10.36.116.73])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9OA7Zgi016157
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Wed, 24 Oct 2012 06:07:36 -0400
Message-ID: <5087BDE6.2070203@draigBrady.com>
Date: Wed, 24 Oct 2012 11:07:34 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: [PATCH] build: do not require help2man at build-from-tarball time
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com> <87txtkl07c.fsf@rho.meyering.net>
In-Reply-To: <87txtkl07c.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9OA7bg2000758
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 10:07:50 -0000

On 10/24/2012 09:54 AM, Jim Meyering wrote:
> Sounds good.  I.e., it sounds like we want Stefano's patch, after all.
>
> As you recall, a nice side effect is that we will
> no longer distribute the generated man/*.1 files.

Well if we don't distribute the .1 files,
wouldn't perl would be a hard requirement?

It might be better to insert a warning like:
   "warning perl unavailable: this manpage may be out of date"
at the bottom of man pages but only for source files
that actually were updated?

cheers,
P=E1draig.


From MAILER-DAEMON Wed Oct 24 06:33:53 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQyHZ-0006cT-FE
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 06:33:53 -0400
Received: from eggs.gnu.org ([208.118.235.92]:42011)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQyHO-0006ZD-HD
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:33:52 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQy8P-0007ZS-1q
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:25:52 -0400
Received: from mx.meyering.net ([88.168.87.75]:50755)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TQy8O-0007Z4-Px
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:24:24 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 0943A60098;
	Wed, 24 Oct 2012 12:24:24 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: [PATCH] build: do not require help2man at build-from-tarball time
In-Reply-To: <5087BDE6.2070203@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?=
	=?iso-8859-1?Q?g?= Brady"'s message of
	"Wed, 24 Oct 2012 11:07:34 +0100")
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com> <87txtkl07c.fsf@rho.meyering.net>
	<5087BDE6.2070203@draigBrady.com>
Date: Wed, 24 Oct 2012 12:24:24 +0200
Message-ID: <876260kw13.fsf@rho.meyering.net>
Lines: 17
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 10:33:52 -0000

P=E1draig Brady wrote:
> On 10/24/2012 09:54 AM, Jim Meyering wrote:
>> Sounds good.  I.e., it sounds like we want Stefano's patch, after all.
>>
>> As you recall, a nice side effect is that we will
>> no longer distribute the generated man/*.1 files.
>
> Well if we don't distribute the .1 files,
> wouldn't perl would be a hard requirement?

Oh, you're right.  Oh well...

> It might be better to insert a warning like:
>   "warning perl unavailable: this manpage may be out of date"
> at the bottom of man pages but only for source files

That sounds good, being careful to insert it only once per file.


From MAILER-DAEMON Wed Oct 24 06:38:23 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQyLv-00085x-Pz
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 06:38:23 -0400
Received: from eggs.gnu.org ([208.118.235.92]:52240)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TQyLp-00083T-Lz
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:38:22 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TQyLn-00030x-Ck
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:38:17 -0400
Received: from mail-bk0-f41.google.com ([209.85.214.41]:55406)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TQyLm-00030l-U5
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:38:15 -0400
Received: by mail-bk0-f41.google.com with SMTP id jm1so156026bkc.0
	for <coreutils@gnu.org>; Wed, 24 Oct 2012 03:38:13 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=message-id:date:from:mime-version:to:cc:subject:references
	:in-reply-to:content-type:content-transfer-encoding;
	bh=i+nVLgx/vOTqXCFzZQ6ail/McGDiVDSoV4Kja32TBxg=;
	b=PoPYwfZidiJcR1hCAPI3KJRb8AhUNIUyJGQ+wFXnuMT9M26BJEsTRppJMxFEmrxocn
	psBTfVX9cZkqaQgVW5GBl6X6PoZ/skxXQfPbTY+3HU1B8dpxf4gHHHvfnpuqZyaCBS3m
	3hjWcPItBxpNQ/wTFoChKVRyUAYNwJUXh7gAwUXbF+T7hhQikzZBmDHDVeqVR197nsPH
	7QU2w1XH8ZGl5qVS5bRIxaIzGpOs95NjXw4/7dJ4+7FVo7/ZMDwQo0/NTBVKN/VZ8Xkt
	wm5j6PZsyNQNmJE1G7rJoLlLn4nfOaoYDWxs5aLcXXfsc9zpotKvuyoRjOySMdseUSUs
	RN+w==
Received: by 10.204.148.12 with SMTP id n12mr4490139bkv.62.1351075093316;
	Wed, 24 Oct 2012 03:38:13 -0700 (PDT)
Received: from [192.168.178.21]
	(host247-100-dynamic.8-87-r.retail.telecomitalia.it. [87.8.100.247])
	by mx.google.com with ESMTPS id r15sm7633215bkw.9.2012.10.24.03.38.11
	(version=SSLv3 cipher=OTHER); Wed, 24 Oct 2012 03:38:12 -0700 (PDT)
Message-ID: <5087C511.4050907@gmail.com>
Date: Wed, 24 Oct 2012 12:38:09 +0200
From: Stefano Lattarini <stefano.lattarini@gmail.com>
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: [PATCH] build: do not require help2man at build-from-tarball time
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com>
	<87txtkl07c.fsf@rho.meyering.net> <5087B58E.2040401@gmail.com>
In-Reply-To: <5087B58E.2040401@gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.85.214.41
Cc: coreutils@gnu.org, 12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 10:38:22 -0000

On 10/24/2012 11:31 AM, Stefano Lattarini wrote:
> On 10/24/2012 10:54 AM, Jim Meyering wrote:
>> Pádraig Brady wrote:
>>
>>> `echo "warning"; touch $manpage`.
>>
>> Sounds good.  I.e., it sounds like we want Stefano's patch, after all.
>>
>> As you recall, a nice side effect is that we will
>> no longer distribute the generated man/*.1 files.
>>
>> Stefano, would you care to rebase your patch?
>>
> Will do soon.  Just give me some time to also re-test it ...
> 
Done.  The patch is inlined below.

Regards,
  Stefano

----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----

>From 6f35e53d98e6dc0c7843b9e434addf81d901aefa Mon Sep 17 00:00:00 2001
Message-Id: <6f35e53d98e6dc0c7843b9e434addf81d901aefa.1351075054.git.stefano.lattarini@gmail.com>
From: Stefano Lattarini <stefano.lattarini@gmail.com>
Date: Tue, 11 Sep 2012 20:54:30 +0200
Subject: [PATCH] build: graceful degradation in man pages generation if perl
 is lacking

Fixes coreutils bug#12715.

Since commit v8.19-118-g57da212, our 'dist-hook' rule tweaks the
distributed Makefile.in so that each man page 'man/foo.1' depends
on the corresponding source 'man/foo.c' rather than the corresponding
program 'man/foo'.  That is done to accommodate inferior systems that,
lacking perl, cannot run 'help2man' to regenerate the manpage after
its corresponding program has been built.

This seems a right and proper graceful degradation, in that the
man pages dependencies are still 100% correct in a git checkout,
while being laxer but "more portable" in a distribution tarball.

Alas, that is not the case in practice, as it turns out the tweaked
Makefile makes the building of man pages unreliable and potentially
incorrect!

In fact, assume that instead of the correct a dependency:

    man/ls.1: src/ls

we have the laxer one:

    man/ls.1: src/ls.c

and think of what happens if a user modifies, say, 'src/ls.c', and then
runs "make -j4" to rebuild everything.  The make process will see that
it has to rebuild the man page 'man/ls.1' (because its prerequisite
'src/ls.c' has changed), but won't see that it has to rebuild 'src/ls'
*before* re-running 'help2man' to generate that man page; so, if
'man/ls.1' is rebuilt before 'src/ls' (which can happen with concurrent
make), our user will get either a build error (if 'src/ls' did non
exist) or, worse, a man page with an up-to-date timestamp but an
out-of-date content.  And what's even worse in all of this is that
this problem will be present also for users who have perl installed:
this is not a "graceful degradation" at all!

In our situation, the best and simplest way to implement a graceful
degradation it to keep the correct dependencies for man pages (that
is, "man/ls.1: src/ls"), and if perl is not present, just generate
dummy man pages reporting that built-time issue and redirecting the
user back to either the info documentation or the '--help' output.

As a consequence of this change, we also stop distributing man pages,
since they would be anyway unconditionally rebuilt

* Makefile.am (do-not-require-help2man): Remove.
(dist-hook): Don't depend on it.
* man/local.mk: Remove an obsolete comment.
(EXTRA_DIST): Stop distributing generated man pages.
($(EXTRA_MANS)): This no longer needs to depend on $(all_programs).
(MAINTAINERCLEANFILES): $(ALL_MANS) should not be listed here ...
(CLEANFILES): ... but here.
(.x.1): Instead of warning if perl is missing, but then trying to run
'help2man' unconditionally, simply run ...
(run_help2man): ... the command referenced by this new variable, that
expands to a proper invocation of 'help2man' if perl is present, and
to an invocation of a shell script generating a dummy manpage if it's
not.
(EXTRA_DIST): Distribute that shell script.
* man/dummy-man: Be that shell script
---
 Makefile.am   | 20 +----------------
 man/dummy-man | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/local.mk  | 25 +++++++++++----------
 3 files changed, 86 insertions(+), 31 deletions(-)
 create mode 100755 man/dummy-man

diff --git a/Makefile.am b/Makefile.am
index 0232090..5eaa45b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -93,29 +93,11 @@ BUILT_SOURCES = .version
 .version:
 	$(AM_V_GEN)echo $(VERSION) > $@-t && mv $@-t $@

-# In general, we run help2man to build a man page from the binary's --help
-# output, but when building from a just-unpacked distribution tarball, we
-# must not do that, since help2man uses perl.  We don't want to depend on
-# perl in that case.  In general, the .1 file does indeed depend on the
-# binary.  I.e., for cat, we have this Makefile dependency:
-#   man/cat.1: src/cat
-# That means that once we build src/cat, we would trigger the .x.1
-# rule which runs help2man.  The trick is simply to change the RHS to
-# "src/cat.c" in the $(distdir) that we're about to tar and compress.
-# Also handle the three exceptions corresponding to the three binaries
-# for which there is no like-named .c file: dir, vdir, ginstall.
-.PHONY: do-not-require-help2man
-do-not-require-help2man:
-	perl -pi -e 's,^(man/.+?\.1:\s*src/.+?)$$,$$1.c,;'		\
-	    -e  's,^(man/.+?\.1:\s*src)/ginstall\.c$$,$$1/install.c,;'	\
-	    -e  's,^(man/.+?\.1:\s*src)/v?dir\.c$$,$$1/ls.c,;'		\
-          $(distdir)/Makefile.in
-
 # Arrange so that .tarball-version appears only in the distribution
 # tarball, and never in a checked-out repository.
 # The perl substitution is to change some key uses of "rm" to "/bin/rm".
 # See the rm_subst comment for details.
-dist-hook: gen-ChangeLog do-not-require-help2man
+dist-hook: gen-ChangeLog
 	$(AM_V_GEN)echo $(VERSION) > $(distdir)/.tarball-version
 	$(AM_V_at)perl -pi -e '$(rm_subst)' $(distdir)/Makefile.in

diff --git a/man/dummy-man b/man/dummy-man
new file mode 100755
index 0000000..cba661c
--- /dev/null
+++ b/man/dummy-man
@@ -0,0 +1,72 @@
+#!/bin/sh
+# Poor place holder for help2man invocation on systems lacking perl;
+# it generates a dummy manpage stating that as proper manpage could
+# not be generated, and redirecting the user back to either the info
+# documentation or the '--help' output.
+
+set -e; set -u
+
+fatal_ ()
+{
+  printf '%s: %s\n' "$0" "$*" >&2
+  exit 1
+}
+
+basename_ ()
+{
+  printf '%s\n' "$1" | sed 's,.*/,,'
+}
+
+output=
+source="GNU coreutils"
+while test $# -gt 0; do
+  case $1 in
+    # Help2man options we recognize handle.
+    --output=*) output=`expr x"$1" : x'--output=\(.*\)'`;;
+    --output) shift; output=$1;;
+    --source=*) source=`expr x"$1" : x'--source=\(.*\)'`;;
+    --source) shift; source=$1;;
+    # Recognize (as no-op) other help2man options that might be used
+    # in the makefile.
+    --include=*);;
+    --include) shift;;
+    -*) fatal_ "invalid or unrecognized help2man option '$1'";;
+    --) shift; break;;
+     *) break;;
+  esac
+  shift
+done
+
+test $# -gt 0 || fatal_ "missing argument"
+test $# -le 1 || fatal_ "too many non-option arguments"
+
+baseout=`basename "$output"`
+sed 's/^/WARNING: /' >&2 <<END
+Cannot create proper man page '$baseout' since perl is missing or
+inadequate on this system.  Will create a stub man page instead.
+END
+
+progname=`basename_ "$1"`
+year=`LC_ALL=C date +%Y`
+bs='\'
+
+cat >"$output" <<END
+.TH "$progname" 1 "$year" "$source" "User Commands"
+.SH NAME
+$progname $bs- a GNU coreutils program
+.SH DESCRIPTION
+.B OOOPS!
+Due to lack of perl on your system, the GNU coreutils build system
+hasn't been able to create the manual page for
+.B $progname.
+For a quick help about that program, try running
+.IP
+.B env $progname --help
+.PP
+The full documentation for
+.B $progname
+is maintained as a Texinfo manual, which you might be accessible
+on your system with the command
+.IP
+.B info coreutils $bs(aq$progname invocation$bs(aq
+END
diff --git a/man/local.mk b/man/local.mk
index ebc111d..2c05bb6 100644
--- a/man/local.mk
+++ b/man/local.mk
@@ -16,17 +16,24 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

-EXTRA_DIST += man/help2man
+EXTRA_DIST += man/help2man man/dummy-man
+
+## Graceful degradation for systems lacking perl.
+if HAVE_PERL
+run_help2man = $(PERL) -- $(srcdir)/man/help2man
+else
+run_help2man = $(SHELL) $(srcdir)/man/dummy-man
+endif

 man1_MANS = @man1_MANS@
-EXTRA_DIST += $(man1_MANS) $(man1_MANS:.1=.x)
+EXTRA_DIST += $(man1_MANS:.1=.x)

 EXTRA_MANS = @EXTRA_MANS@
-EXTRA_DIST += $(EXTRA_MANS) $(EXTRA_MANS:.1=.x)
+EXTRA_DIST += $(EXTRA_MANS:.1=.x)

 ALL_MANS = $(man1_MANS) $(EXTRA_MANS)

-MAINTAINERCLEANFILES += $(ALL_MANS)
+CLEANFILES += $(ALL_MANS)

 # This is required because we have subtle inter-directory dependencies:
 # in order to generate all man pages, even those for which we don't
@@ -161,13 +168,7 @@ man/whoami.1:    src/whoami
 man/yes.1:       src/yes

 .x.1:
-	$(AM_V_GEN)case '$(PERL)' in				\
-	  *"/missing "*)					\
-	    echo 'WARNING: cannot update man page $@ since perl is missing' \
-	      'or inadequate' 1>&2				\
-	    exit 0;;						\
-	esac; \
-	name=`echo $@ | sed -e 's|.*/||' -e 's|\.1$$||'` || exit 1;	\
+	$(AM_V_GEN)name=`echo $@ | sed 's|.*/||; s|\.1$$||'` || exit 1;	\
 ## Ensure that help2man runs the 'src/ginstall' binary as 'install' when
 ## creating 'install.1'.  Similarly, ensure that it uses the 'src/[' binary
 ## to create 'test.1'.
@@ -184,7 +185,7 @@ man/yes.1:       src/yes
 	  && rm -rf $$t							\
 	  && $(MKDIR_P) $$t						\
 	  && (cd $$t && $(LN_S) '$(abs_top_builddir)/src/'$$prog $$name) \
-	  && $(PERL) -- $(srcdir)/man/help2man				\
+	  && $(run_help2man)						\
 		     --source='$(PACKAGE_STRING)'			\
 		     --include=$(srcdir)/man/$$name.x			\
 		     --output=$$t/$$name.1 $$t/$$name			\
-- 
1.8.0.rc2.11.gd25c58c


From MAILER-DAEMON Wed Oct 24 06:47:13 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TQyUT-0003X1-EQ
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 06:47:13 -0400
Received: from eggs.gnu.org ([208.118.235.92]:33846)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TQyUF-0003PV-Lo
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:47:11 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TQyTs-0006d6-47
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:46:59 -0400
Received: from mail-bk0-f41.google.com ([209.85.214.41]:54738)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TQyTr-0006cu-OX
	for coreutils@gnu.org; Wed, 24 Oct 2012 06:46:36 -0400
Received: by mail-bk0-f41.google.com with SMTP id jm1so160297bkc.0
	for <coreutils@gnu.org>; Wed, 24 Oct 2012 03:46:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=message-id:date:from:mime-version:to:cc:subject:references
	:in-reply-to:content-type:content-transfer-encoding;
	bh=Da7yLt8lSM6UQjd5uGaeCmYUXhIyF24l55+qHJMdmho=;
	b=kuDqzim1HfmTqrr1Br3iLQGKn8aJkF7INFR21fY4ffu6s2Op83aN0eiNoc/CDO5KEO
	1Fro/4nA1J9YhRNbsMcTtM+yqcxw/S9LtOpMYWLW3Ef7WRBmXNdrqwE7OHmh/tCNioRe
	ZGS06/QNYPy9M8z2W9etcf/VtRxBczobuvQuEtwraJPeXf2iFfJgTeq1oFVlEOKYOH4h
	3QckjzjTRRqcaEUHkoofVgxlHuoZWqgG5u4uxiUe0yvT3K+kdh+PzpS/AUFej/GehjTx
	Lw6wNhBVk/ier1fUmbdSUcpEKNIJEDFWGqcya9hA7y4UnefuF2jZjvXCp2dAvDX7VzKB
	PNBw==
Received: by 10.204.148.146 with SMTP id p18mr4748138bkv.51.1351075594790;
	Wed, 24 Oct 2012 03:46:34 -0700 (PDT)
Received: from [192.168.178.21]
	(host247-100-dynamic.8-87-r.retail.telecomitalia.it. [87.8.100.247])
	by mx.google.com with ESMTPS id x13sm7733589bkv.16.2012.10.24.03.46.32
	(version=SSLv3 cipher=OTHER); Wed, 24 Oct 2012 03:46:34 -0700 (PDT)
Message-ID: <5087C706.3050205@gmail.com>
Date: Wed, 24 Oct 2012 12:46:30 +0200
From: Stefano Lattarini <stefano.lattarini@gmail.com>
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: [PATCH] build: do not require help2man at build-from-tarball time
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com>
	<87txtkl07c.fsf@rho.meyering.net> <5087B58E.2040401@gmail.com>
	<5087C511.4050907@gmail.com>
In-Reply-To: <5087C511.4050907@gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.85.214.41
Cc: coreutils@gnu.org, 12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 10:47:12 -0000

On 10/24/2012 12:38 PM, Stefano Lattarini wrote:
> On 10/24/2012 11:31 AM, Stefano Lattarini wrote:
>> On 10/24/2012 10:54 AM, Jim Meyering wrote:
>>> Pádraig Brady wrote:
>>>
>>>> `echo "warning"; touch $manpage`.
>>>
>>> Sounds good.  I.e., it sounds like we want Stefano's patch, after all.
>>>
>>> As you recall, a nice side effect is that we will
>>> no longer distribute the generated man/*.1 files.
>>>
>>> Stefano, would you care to rebase your patch?
>>>
>> Will do soon.  Just give me some time to also re-test it ...
>>
> Done.  The patch is inlined below.
> 
Yikes, some blunders slipped in.  We need at least the following diffs
squashed in:

-*-*-*-

diff --git a/man/dummy-man b/man/dummy-man
index cba661c..2e32320 100755
--- a/man/dummy-man
+++ b/man/dummy-man
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Poor place holder for help2man invocation on systems lacking perl;
+# Poor placeholder for help2man invocation on systems lacking perl;
 # it generates a dummy manpage stating that as proper manpage could
 # not be generated, and redirecting the user back to either the info
 # documentation or the '--help' output.
@@ -21,7 +21,7 @@ output=
 source="GNU coreutils"
 while test $# -gt 0; do
   case $1 in
-    # Help2man options we recognize handle.
+    # Help2man options we recognize and handle.
     --output=*) output=`expr x"$1" : x'--output=\(.*\)'`;;
     --output) shift; output=$1;;
     --source=*) source=`expr x"$1" : x'--source=\(.*\)'`;;
@@ -40,7 +40,7 @@ done
 test $# -gt 0 || fatal_ "missing argument"
 test $# -le 1 || fatal_ "too many non-option arguments"

-baseout=`basename "$output"`
+baseout=`basename_ "$output"`
 sed 's/^/WARNING: /' >&2 <<END
 Cannot create proper man page '$baseout' since perl is missing or
 inadequate on this system.  Will create a stub man page instead.

-*-*-*-

Here is the updated patch.  Sorry for the noise,
  Stefano

----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----

>From f61dcb763975c1aab299fa9678ea180d70db6acf Mon Sep 17 00:00:00 2001
Message-Id: <f61dcb763975c1aab299fa9678ea180d70db6acf.1351075572.git.stefano.lattarini@gmail.com>
From: Stefano Lattarini <stefano.lattarini@gmail.com>
Date: Tue, 11 Sep 2012 20:54:30 +0200
Subject: [PATCH] build: graceful degradation in man pages generation if perl
 is lacking

Fixes coreutils bug#12715.

Since commit v8.19-118-g57da212, our 'dist-hook' rule tweaks the
distributed Makefile.in so that each man page 'man/foo.1' depends
on the corresponding source 'man/foo.c' rather than the corresponding
program 'man/foo'.  That is done to accommodate inferior systems that,
lacking perl, cannot run 'help2man' to regenerate the manpage after
its corresponding program has been built.

This seems a right and proper graceful degradation, in that the
man pages dependencies are still 100% correct in a git checkout,
while being laxer but "more portable" in a distribution tarball.

Alas, that is not the case in practice, as it turns out the tweaked
Makefile makes the building of man pages unreliable and potentially
incorrect!

In fact, assume that instead of the correct a dependency:

    man/ls.1: src/ls

we have the laxer one:

    man/ls.1: src/ls.c

and think of what happens if a user modifies, say, 'src/ls.c', and then
runs "make -j4" to rebuild everything.  The make process will see that
it has to rebuild the man page 'man/ls.1' (because its prerequisite
'src/ls.c' has changed), but won't see that it has to rebuild 'src/ls'
*before* re-running 'help2man' to generate that man page; so, if
'man/ls.1' is rebuilt before 'src/ls' (which can happen with concurrent
make), our user will get either a build error (if 'src/ls' did non
exist) or, worse, a man page with an up-to-date timestamp but an
out-of-date content.  And what's even worse in all of this is that
this problem will be present also for users who have perl installed:
this is not a "graceful degradation" at all!

In our situation, the best and simplest way to implement a graceful
degradation it to keep the correct dependencies for man pages (that
is, "man/ls.1: src/ls"), and if perl is not present, just generate
dummy man pages reporting that built-time issue and redirecting the
user back to either the info documentation or the '--help' output.

As a consequence of this change, we also stop distributing man pages,
since they would be anyway unconditionally rebuilt

* Makefile.am (do-not-require-help2man): Remove.
(dist-hook): Don't depend on it.
* man/local.mk: Remove an obsolete comment.
(EXTRA_DIST): Stop distributing generated man pages.
($(EXTRA_MANS)): This no longer needs to depend on $(all_programs).
(MAINTAINERCLEANFILES): $(ALL_MANS) should not be listed here ...
(CLEANFILES): ... but here.
(.x.1): Instead of warning if perl is missing, but then trying to run
'help2man' unconditionally, simply run ...
(run_help2man): ... the command referenced by this new variable, that
expands to a proper invocation of 'help2man' if perl is present, and
to an invocation of a shell script generating a dummy manpage if it's
not.
(EXTRA_DIST): Distribute that shell script.
* man/dummy-man: Be that shell script
---
 Makefile.am   | 20 +----------------
 man/dummy-man | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/local.mk  | 25 +++++++++++----------
 3 files changed, 86 insertions(+), 31 deletions(-)
 create mode 100755 man/dummy-man

diff --git a/Makefile.am b/Makefile.am
index 0232090..5eaa45b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -93,29 +93,11 @@ BUILT_SOURCES = .version
 .version:
 	$(AM_V_GEN)echo $(VERSION) > $@-t && mv $@-t $@

-# In general, we run help2man to build a man page from the binary's --help
-# output, but when building from a just-unpacked distribution tarball, we
-# must not do that, since help2man uses perl.  We don't want to depend on
-# perl in that case.  In general, the .1 file does indeed depend on the
-# binary.  I.e., for cat, we have this Makefile dependency:
-#   man/cat.1: src/cat
-# That means that once we build src/cat, we would trigger the .x.1
-# rule which runs help2man.  The trick is simply to change the RHS to
-# "src/cat.c" in the $(distdir) that we're about to tar and compress.
-# Also handle the three exceptions corresponding to the three binaries
-# for which there is no like-named .c file: dir, vdir, ginstall.
-.PHONY: do-not-require-help2man
-do-not-require-help2man:
-	perl -pi -e 's,^(man/.+?\.1:\s*src/.+?)$$,$$1.c,;'		\
-	    -e  's,^(man/.+?\.1:\s*src)/ginstall\.c$$,$$1/install.c,;'	\
-	    -e  's,^(man/.+?\.1:\s*src)/v?dir\.c$$,$$1/ls.c,;'		\
-          $(distdir)/Makefile.in
-
 # Arrange so that .tarball-version appears only in the distribution
 # tarball, and never in a checked-out repository.
 # The perl substitution is to change some key uses of "rm" to "/bin/rm".
 # See the rm_subst comment for details.
-dist-hook: gen-ChangeLog do-not-require-help2man
+dist-hook: gen-ChangeLog
 	$(AM_V_GEN)echo $(VERSION) > $(distdir)/.tarball-version
 	$(AM_V_at)perl -pi -e '$(rm_subst)' $(distdir)/Makefile.in

diff --git a/man/dummy-man b/man/dummy-man
new file mode 100755
index 0000000..2e32320
--- /dev/null
+++ b/man/dummy-man
@@ -0,0 +1,72 @@
+#!/bin/sh
+# Poor placeholder for help2man invocation on systems lacking perl;
+# it generates a dummy manpage stating that as proper manpage could
+# not be generated, and redirecting the user back to either the info
+# documentation or the '--help' output.
+
+set -e; set -u
+
+fatal_ ()
+{
+  printf '%s: %s\n' "$0" "$*" >&2
+  exit 1
+}
+
+basename_ ()
+{
+  printf '%s\n' "$1" | sed 's,.*/,,'
+}
+
+output=
+source="GNU coreutils"
+while test $# -gt 0; do
+  case $1 in
+    # Help2man options we recognize and handle.
+    --output=*) output=`expr x"$1" : x'--output=\(.*\)'`;;
+    --output) shift; output=$1;;
+    --source=*) source=`expr x"$1" : x'--source=\(.*\)'`;;
+    --source) shift; source=$1;;
+    # Recognize (as no-op) other help2man options that might be used
+    # in the makefile.
+    --include=*);;
+    --include) shift;;
+    -*) fatal_ "invalid or unrecognized help2man option '$1'";;
+    --) shift; break;;
+     *) break;;
+  esac
+  shift
+done
+
+test $# -gt 0 || fatal_ "missing argument"
+test $# -le 1 || fatal_ "too many non-option arguments"
+
+baseout=`basename_ "$output"`
+sed 's/^/WARNING: /' >&2 <<END
+Cannot create proper man page '$baseout' since perl is missing or
+inadequate on this system.  Will create a stub man page instead.
+END
+
+progname=`basename_ "$1"`
+year=`LC_ALL=C date +%Y`
+bs='\'
+
+cat >"$output" <<END
+.TH "$progname" 1 "$year" "$source" "User Commands"
+.SH NAME
+$progname $bs- a GNU coreutils program
+.SH DESCRIPTION
+.B OOOPS!
+Due to lack of perl on your system, the GNU coreutils build system
+hasn't been able to create the manual page for
+.B $progname.
+For a quick help about that program, try running
+.IP
+.B env $progname --help
+.PP
+The full documentation for
+.B $progname
+is maintained as a Texinfo manual, which you might be accessible
+on your system with the command
+.IP
+.B info coreutils $bs(aq$progname invocation$bs(aq
+END
diff --git a/man/local.mk b/man/local.mk
index ebc111d..2c05bb6 100644
--- a/man/local.mk
+++ b/man/local.mk
@@ -16,17 +16,24 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

-EXTRA_DIST += man/help2man
+EXTRA_DIST += man/help2man man/dummy-man
+
+## Graceful degradation for systems lacking perl.
+if HAVE_PERL
+run_help2man = $(PERL) -- $(srcdir)/man/help2man
+else
+run_help2man = $(SHELL) $(srcdir)/man/dummy-man
+endif

 man1_MANS = @man1_MANS@
-EXTRA_DIST += $(man1_MANS) $(man1_MANS:.1=.x)
+EXTRA_DIST += $(man1_MANS:.1=.x)

 EXTRA_MANS = @EXTRA_MANS@
-EXTRA_DIST += $(EXTRA_MANS) $(EXTRA_MANS:.1=.x)
+EXTRA_DIST += $(EXTRA_MANS:.1=.x)

 ALL_MANS = $(man1_MANS) $(EXTRA_MANS)

-MAINTAINERCLEANFILES += $(ALL_MANS)
+CLEANFILES += $(ALL_MANS)

 # This is required because we have subtle inter-directory dependencies:
 # in order to generate all man pages, even those for which we don't
@@ -161,13 +168,7 @@ man/whoami.1:    src/whoami
 man/yes.1:       src/yes

 .x.1:
-	$(AM_V_GEN)case '$(PERL)' in				\
-	  *"/missing "*)					\
-	    echo 'WARNING: cannot update man page $@ since perl is missing' \
-	      'or inadequate' 1>&2				\
-	    exit 0;;						\
-	esac; \
-	name=`echo $@ | sed -e 's|.*/||' -e 's|\.1$$||'` || exit 1;	\
+	$(AM_V_GEN)name=`echo $@ | sed 's|.*/||; s|\.1$$||'` || exit 1;	\
 ## Ensure that help2man runs the 'src/ginstall' binary as 'install' when
 ## creating 'install.1'.  Similarly, ensure that it uses the 'src/[' binary
 ## to create 'test.1'.
@@ -184,7 +185,7 @@ man/yes.1:       src/yes
 	  && rm -rf $$t							\
 	  && $(MKDIR_P) $$t						\
 	  && (cd $$t && $(LN_S) '$(abs_top_builddir)/src/'$$prog $$name) \
-	  && $(PERL) -- $(srcdir)/man/help2man				\
+	  && $(run_help2man)						\
 		     --source='$(PACKAGE_STRING)'			\
 		     --include=$(srcdir)/man/$$name.x			\
 		     --output=$$t/$$name.1 $$t/$$name			\
-- 
1.8.0.rc2.11.gd25c58c



From MAILER-DAEMON Wed Oct 24 09:07:41 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TR0gP-0001Na-Et
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 09:07:41 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37066)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TR0gD-0001N3-Tf
	for coreutils@gnu.org; Wed, 24 Oct 2012 09:07:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TR0g3-0005NN-Qg
	for coreutils@gnu.org; Wed, 24 Oct 2012 09:07:29 -0400
Received: from mx.meyering.net ([88.168.87.75]:51074)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TR0g3-0005N6-GF
	for coreutils@gnu.org; Wed, 24 Oct 2012 09:07:19 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 1E8F160085;
	Wed, 24 Oct 2012 15:07:18 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Stefano Lattarini <stefano.lattarini@gmail.com>
Subject: Re: [PATCH] build: do not require help2man at build-from-tarball time
In-Reply-To: <5087C706.3050205@gmail.com> (Stefano Lattarini's message of
	"Wed, 24 Oct 2012 12:46:30 +0200")
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com> <87txtkl07c.fsf@rho.meyering.net>
	<5087B58E.2040401@gmail.com> <5087C511.4050907@gmail.com>
	<5087C706.3050205@gmail.com>
Date: Wed, 24 Oct 2012 15:07:18 +0200
Message-ID: <87ipa0j9x5.fsf@rho.meyering.net>
Lines: 78
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org, 12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 13:07:39 -0000

Stefano Lattarini wrote:
> Here is the updated patch.  Sorry for the noise,
...
> Subject: [PATCH] build: graceful degradation in man pages generation if p=
erl
>  is lacking

Thank you for the updated patch.

> Fixes coreutils bug#12715.
>
> Since commit v8.19-118-g57da212, our 'dist-hook' rule tweaks the
> distributed Makefile.in so that each man page 'man/foo.1' depends
> on the corresponding source 'man/foo.c' rather than the corresponding
> program 'man/foo'.  That is done to accommodate inferior systems that,
> lacking perl, cannot run 'help2man' to regenerate the manpage after
> its corresponding program has been built.
>
> This seems a right and proper graceful degradation, in that the
> man pages dependencies are still 100% correct in a git checkout,
> while being laxer but "more portable" in a distribution tarball.
>
> Alas, that is not the case in practice, as it turns out the tweaked
> Makefile makes the building of man pages unreliable and potentially
> incorrect!
>
> In fact, assume that instead of the correct a dependency:
>
>     man/ls.1: src/ls
>
> we have the laxer one:
>
>     man/ls.1: src/ls.c
>
> and think of what happens if a user modifies, say, 'src/ls.c', and then
> runs "make -j4" to rebuild everything.  The make process will see that
> it has to rebuild the man page 'man/ls.1' (because its prerequisite
> 'src/ls.c' has changed), but won't see that it has to rebuild 'src/ls'
> *before* re-running 'help2man' to generate that man page; so, if
> 'man/ls.1' is rebuilt before 'src/ls' (which can happen with concurrent
> make), our user will get either a build error (if 'src/ls' did non
> exist) or, worse, a man page with an up-to-date timestamp but an
> out-of-date content.  And what's even worse in all of this is that
> this problem will be present also for users who have perl installed:
> this is not a "graceful degradation" at all!
>
> In our situation, the best and simplest way to implement a graceful
> degradation it to keep the correct dependencies for man pages (that
> is, "man/ls.1: src/ls"), and if perl is not present, just generate
> dummy man pages reporting that built-time issue and redirecting the
> user back to either the info documentation or the '--help' output.
>
> As a consequence of this change, we also stop distributing man pages,
> since they would be anyway unconditionally rebuilt

This is simpler than what P=E1draig suggested (distribute
.1 files and insert warning if needed), but I'm inclined to
agree that simpler is better.

Does anyone know of a well-known environment/distro in which
coreutils is built without perl?  I.e., if virtually no one
builds coreutils without perl, then any attempt to coddle those
users is wasted complexity.

> * Makefile.am (do-not-require-help2man): Remove.
> (dist-hook): Don't depend on it.
> * man/local.mk: Remove an obsolete comment.
> (EXTRA_DIST): Stop distributing generated man pages.
> ($(EXTRA_MANS)): This no longer needs to depend on $(all_programs).
> (MAINTAINERCLEANFILES): $(ALL_MANS) should not be listed here ...
> (CLEANFILES): ... but here.
> (.x.1): Instead of warning if perl is missing, but then trying to run
> 'help2man' unconditionally, simply run ...
> (run_help2man): ... the command referenced by this new variable, that
> expands to a proper invocation of 'help2man' if perl is present, and
> to an invocation of a shell script generating a dummy manpage if it's
> not.
> (EXTRA_DIST): Distribute that shell script.
> * man/dummy-man: Be that shell script


From MAILER-DAEMON Wed Oct 24 10:04:26 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TR1ZK-0002KX-P1
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 10:04:26 -0400
Received: from eggs.gnu.org ([208.118.235.92]:39241)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <g.esp@free.fr>) id 1TR1ZC-00020r-Nb
	for coreutils@gnu.org; Wed, 24 Oct 2012 10:04:24 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <g.esp@free.fr>) id 1TR1Z8-0005Z8-I5
	for coreutils@gnu.org; Wed, 24 Oct 2012 10:04:18 -0400
Received: from smtp1-g21.free.fr ([212.27.42.1]:37328)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <g.esp@free.fr>) id 1TR1Z7-0005Yj-V3
	for coreutils@gnu.org; Wed, 24 Oct 2012 10:04:14 -0400
Received: from zimbra33-e6.priv.proxad.net (unknown [172.20.243.183])
	by smtp1-g21.free.fr (Postfix) with ESMTP id C37C6940024;
	Wed, 24 Oct 2012 16:04:06 +0200 (CEST)
Date: Wed, 24 Oct 2012 16:04:05 +0200 (CEST)
From: g.esp@free.fr
To: Jim Meyering <jim@meyering.net>
Message-ID: <1135860962.327089500.1351087445654.JavaMail.root@zimbra33-e6.priv.proxad.net>
In-Reply-To: <87ipa0j9x5.fsf@rho.meyering.net>
Subject: Re: bug#12715: [PATCH] build: do not require help2man at
	build-from-tarball time
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Originating-IP: [163.116.6.12]
X-Mailer: Zimbra 7.2.0-GA2598 (ZimbraWebClient - FF3.0 (Win)/7.2.0-GA2598)
X-Authenticated-User: g.esp@free.fr
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3)
X-Received-From: 212.27.42.1
Cc: coreutils@gnu.org, Stefano Lattarini <stefano.lattarini@gmail.com>,
	12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 14:04:25 -0000



----- Mail original -----
> De: "Jim Meyering" <jim@meyering.net>
> =C3=80: "Stefano Lattarini" <stefano.lattarini@gmail.com>
> Cc: "P=C3=A1draig Brady" <P@draigBrady.com>, "Mike Frysinger" <vapier@gen=
too.org>, coreutils@gnu.org,
> 12715@debbugs.gnu.org
> Envoy=C3=A9: Mercredi 24 Octobre 2012 15:07:18
> Objet: bug#12715: [PATCH] build: do not require help2man at=09build-from-=
tarball time
>=20
> Stefano Lattarini wrote:
> > Here is the updated patch.  Sorry for the noise,
> ...
> > Subject: [PATCH] build: graceful degradation in man pages
> > generation if perl
> >  is lacking
>=20

>=20
> Does anyone know of a well-known environment/distro in which
> coreutils is built without perl?  I.e., if virtually no one
> builds coreutils without perl, then any attempt to coddle those
> users is wasted complexity.
>=20
Speaking for what I know, this is not an issue with 'linux from scratch' ba=
sed systems.
- perl is an host requirement (coreutils is build a first time on toolchain=
 stage),
- perl is build on toolchain stage before final coreutils is build.


Any toolchain that really cross-compile often avoid perl as notoriously har=
d to cross-compile.
Often busybox is used instead of coreutils. Openwrt for example does that.
Openwrt could optionally build coreutils. The build script use 8.16 and pat=
ch to not build the doc.

Gilles


From MAILER-DAEMON Wed Oct 24 10:17:33 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TR1m1-0004Vh-EG
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 10:17:33 -0400
Received: from eggs.gnu.org ([208.118.235.92]:40907)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TR1lw-0004TM-FD
	for coreutils@gnu.org; Wed, 24 Oct 2012 10:17:32 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TR1ls-0000t1-6e
	for coreutils@gnu.org; Wed, 24 Oct 2012 10:17:28 -0400
Received: from mx.meyering.net ([88.168.87.75]:51228)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TR1lr-0000su-V3
	for coreutils@gnu.org; Wed, 24 Oct 2012 10:17:24 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 182BB600FE;
	Wed, 24 Oct 2012 16:17:23 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: g.esp@free.fr
Subject: Re: bug#12715: [PATCH] build: do not require help2man at
	build-from-tarball time
In-Reply-To: <1135860962.327089500.1351087445654.JavaMail.root@zimbra33-e6.priv.proxad.net>
	(g. esp's message of "Wed, 24 Oct 2012 16:04:05 +0200 (CEST)")
References: <1135860962.327089500.1351087445654.JavaMail.root@zimbra33-e6.priv.proxad.net>
Date: Wed, 24 Oct 2012 16:17:23 +0200
Message-ID: <87d308j6oc.fsf@rho.meyering.net>
Lines: 37
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org, Stefano Lattarini <stefano.lattarini@gmail.com>,
	12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 14:17:32 -0000

g.esp@free.fr wrote:
> ----- Mail original -----
>> De: "Jim Meyering" <jim@meyering.net>
>> =C0: "Stefano Lattarini" <stefano.lattarini@gmail.com>
>> Cc: "P=E1draig Brady" <P@draigBrady.com>, "Mike Frysinger"
>> <vapier@gentoo.org>, coreutils@gnu.org,
>> 12715@debbugs.gnu.org
>> Envoy=E9: Mercredi 24 Octobre 2012 15:07:18
>> Objet: bug#12715: [PATCH] build: do not require help2man at
>> build-from-tarball time
>>
>> Stefano Lattarini wrote:
>> > Here is the updated patch.  Sorry for the noise,
>> ...
>> > Subject: [PATCH] build: graceful degradation in man pages
>> > generation if perl
>> >  is lacking
>>
>> Does anyone know of a well-known environment/distro in which
>> coreutils is built without perl?  I.e., if virtually no one
>> builds coreutils without perl, then any attempt to coddle those
>> users is wasted complexity.
>>
> Speaking for what I know, this is not an issue with 'linux from
> scratch' based systems.
> - perl is an host requirement (coreutils is build a first time on
> toolchain stage),
> - perl is build on toolchain stage before final coreutils is build.
>
> Any toolchain that really cross-compile often avoid perl as
> notoriously hard to cross-compile.
> Often busybox is used instead of coreutils. Openwrt for example does that.
> Openwrt could optionally build coreutils. The build script use 8.16
> and patch to not build the doc.

Nice.  That's reassuring.
Thanks for the info.


From MAILER-DAEMON Wed Oct 24 17:58:46 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TR8yM-0004qs-EV
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 17:58:46 -0400
Received: from eggs.gnu.org ([208.118.235.92]:45701)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TR8yJ-0004pw-PH
	for coreutils@gnu.org; Wed, 24 Oct 2012 17:58:45 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TR8yH-0000Rj-RC
	for coreutils@gnu.org; Wed, 24 Oct 2012 17:58:43 -0400
Received: from mx1.redhat.com ([209.132.183.28]:54980)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TR8yH-0000RN-HM
	for coreutils@gnu.org; Wed, 24 Oct 2012 17:58:41 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9OLweO7029026
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <coreutils@gnu.org>; Wed, 24 Oct 2012 17:58:40 -0400
Received: from [10.36.116.60] (ovpn-116-60.ams2.redhat.com [10.36.116.60])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9OLwbP6018075
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Wed, 24 Oct 2012 17:58:39 -0400
Message-ID: <5088648D.1050400@draigBrady.com>
Date: Wed, 24 Oct 2012 22:58:37 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Ondrej Oprala <ooprala@redhat.com>
Subject: Re: pr: floating-point error
References: <5087A0B8.9090906@redhat.com> <5087B435.2090803@draigBrady.com>
In-Reply-To: <5087B435.2090803@draigBrady.com>
Content-Type: multipart/mixed; boundary="------------040407030407060606050501"
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 21:58:45 -0000

This is a multi-part message in MIME format.
--------------040407030407060606050501
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id q9OLweO7029026

On 10/24/2012 10:26 AM, P=E1draig Brady wrote:
> On 10/24/2012 09:03 AM, Ondrej Oprala wrote:
>> Hello,
>> one of our customers made a bug report, stating that pr -nNUM FILE
>> causes a floating point exception if NUM >=3D 32
>> and I would really like to hear your opinion on how to solve this.
>> The easiest solution would be to document the <32 limit for the -n opt=
ion.
>> The more difficult one would be to support numbers of arbitrary length.
>> I was thinking about the second solution and  AFAIK the line number is=
 not
>> used in any arithmetic (apart from incrementation), so it could be rep=
resented as
>> an array of digits, with a function incrementing the array from the ri=
ghtmost element
>> as needed. Then we would just print out the array one element at a tim=
e. It would
>> probably cause a performance penalty though.
>> Thanks in advance for any advice or suggestions.
>
> Ouch. Confirmed that this dumps core:
>
>    echo . | pr -T -n.32
>
> We can fix that up with something like the following.
> I'll add a test and commit.

Complete proposed patch is attached.

thanks,
P=E1draig.

--------------040407030407060606050501
Content-Type: text/x-patch;
 name="pr-n-crash.diff"
Content-Disposition: attachment;
 filename="pr-n-crash.diff"
Content-Transfer-Encoding: 7bit

>From 9dc0bffd25a4d202d8beb875290901834c33d873 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
Date: Wed, 24 Oct 2012 10:55:13 +0100
Subject: [PATCH] pr: fix -n to pad consistently and not crash

* src/pr.c: Replace the code to truncate the most significant
digits of line numbers, with much simpler string manipulation
that supports arbitrary widths.  Before this, specifying a
width >= 32 to -n would result in a divide by zero error.
Also remove the inconsistent padding with zeros and spaces, which
would result in zero padding for widths 12 and 15.
* tests/pr/pr-tests.pl: Added a test to ensure no zero padding,
and also a test for the divide by zero case.
* NEWS: Mentioned the fix
Reported by Ondrej Oprala
---
 NEWS                 |    6 ++++++
 src/pr.c             |   28 ++++++----------------------
 tests/pr/pr-tests.pl |    7 +++++++
 3 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/NEWS b/NEWS
index 04721da..e13ba22 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,12 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Bug fixes
+
+  pr -n no longer crashes when passed values >= 32.  Also line numbers are
+  consistently padded with spaces, rather than with zeros for certain widths.
+  [bug introduced in TEXTUTILS-1_22i]
+
 
 * Noteworthy changes in release 8.20 (2012-10-23) [stable]
 
diff --git a/src/pr.c b/src/pr.c
index e97c434..3e40167 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -630,10 +630,6 @@ static uintmax_t page_number;
    2    moo     4       hoo     6       zoo */
 static int line_number;
 
-/* With line_number overflow, we use power_10 to cut off the higher-order
-   digits of the line_number */
-static int power_10;
-
 /* (-n) True means lines should be preceded by numbers. */
 static bool numbered_lines = false;
 
@@ -1268,7 +1264,6 @@ init_parameters (int number_of_files)
 
   if (numbered_lines)
     {
-      int tmp_i;
       int chars_per_default_tab = 8;
 
       line_count = start_line_num;
@@ -1289,12 +1284,6 @@ init_parameters (int number_of_files)
          printing files in parallel. */
       if (parallel_files)
         chars_used_by_number = number_width;
-
-      /* We use power_10 to cut off the higher-order digits of the
-         line_number in function add_line_number */
-      tmp_i = chars_per_number;
-      for (power_10 = 1; tmp_i > 0; --tmp_i)
-        power_10 = 10 * power_10;
     }
 
   chars_per_column = (chars_per_line - chars_used_by_number
@@ -1306,7 +1295,8 @@ init_parameters (int number_of_files)
   if (numbered_lines)
     {
       free (number_buff);
-      number_buff = xmalloc (2 * chars_per_number);
+      number_buff = xmalloc (MAX (chars_per_number,
+                                  INT_STRLEN_BOUND (line_number)) + 1);
     }
 
   /* Pick the maximum between the tab width and the width of an
@@ -2029,19 +2019,13 @@ add_line_number (COLUMN *p)
 {
   int i;
   char *s;
-  int left_cut;
+  int num_width;
 
   /* Cutting off the higher-order digits is more informative than
-     lower-order cut off*/
-  if (line_number < power_10)
-    sprintf (number_buff, "%*d", chars_per_number, line_number);
-  else
-    {
-      left_cut = line_number % power_10;
-      sprintf (number_buff, "%0*d", chars_per_number, left_cut);
-    }
+     lower-order cut off. */
+  num_width = sprintf (number_buff, "%*d", chars_per_number, line_number);
   line_number++;
-  s = number_buff;
+  s = number_buff + (num_width - chars_per_number);
   for (i = chars_per_number; i > 0; i--)
     (p->char_func) (*s++);
 
diff --git a/tests/pr/pr-tests.pl b/tests/pr/pr-tests.pl
index f202414..aeaa7fe 100755
--- a/tests/pr/pr-tests.pl
+++ b/tests/pr/pr-tests.pl
@@ -407,6 +407,13 @@ my @tv = (
 # Before coreutils-8.13 page numbers were not handled correctly when
 # headers were not printed (when -l <= 10 or -t or -T specified)
 ['page-range', '+1:1 -2 -l1 -s" "',  "a\nb\nc\n", "a b\n", 0],
+
+# This padded with zeros before coreutils-8.21
+['padding1', '-t -n,15', "1\n", (" "x 14)."1,1\n", 0],
+# This crashed with divide by zero before coreutils-8.21
+['padding2', '-t -n,64', "1\n", (" "x 63)."1,1\n", 0],
+# Ensure we handle buffer truncation correctly
+['padding3', '-t -N1000000 -n,1', "1\n", "0,1\n", 0],
 );
 
 # Convert the above old-style test vectors to the newer
-- 
1.7.6.4


--------------040407030407060606050501--


From MAILER-DAEMON Wed Oct 24 18:23:14 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TR9M2-0000ic-LB
	for mharc-coreutils@gnu.org; Wed, 24 Oct 2012 18:23:14 -0400
Received: from eggs.gnu.org ([208.118.235.92]:44158)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TR9M0-0000hV-1n
	for coreutils@gnu.org; Wed, 24 Oct 2012 18:23:13 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TR9Ly-0007qS-HF
	for coreutils@gnu.org; Wed, 24 Oct 2012 18:23:11 -0400
Received: from mx1.redhat.com ([209.132.183.28]:18043)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TR9Ly-0007qD-7p
	for coreutils@gnu.org; Wed, 24 Oct 2012 18:23:10 -0400
Received: from int-mx01.intmail.prod.int.phx2.redhat.com
	(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9OMN78s001666
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Wed, 24 Oct 2012 18:23:07 -0400
Received: from pb-n5110.redhat.com (ovpn-116-60.ams2.redhat.com [10.36.116.60])
	by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9OMN6L9000919; Wed, 24 Oct 2012 18:23:06 -0400
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
To: coreutils@gnu.org
Subject: [PATCH] maint: refactor tests/misc/pr.pl into tests/pr/pr-tests.pl
Date: Wed, 24 Oct 2012 23:23:03 +0100
Message-Id: <1351117383-16113-1-git-send-email-P@draigBrady.com>
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Oct 2012 22:23:13 -0000

* tests/misc/pr.pl: Refactor this test into ...
* tests/pr/pr-tests.pl: ... here.
* tests/local.mk: Remove the reference to the removed test
* tests/pr/m-w-t-1: Input file for the refactored test.
* tests/pr/m-w-t-2: Likewise.
* tests/pr/m-w-t-3: Likewise.
---
 tests/local.mk       |    1 -
 tests/misc/pr.pl     |   43 -------------------------------------------
 tests/pr/m-w-t-1     |    1 +
 tests/pr/m-w-t-2     |    1 +
 tests/pr/m-w-t-3     |    1 +
 tests/pr/pr-tests.pl |    4 ++++
 6 files changed, 7 insertions(+), 44 deletions(-)
 delete mode 100755 tests/misc/pr.pl
 create mode 100644 tests/pr/m-w-t-1
 create mode 100644 tests/pr/m-w-t-2
 create mode 100644 tests/pr/m-w-t-3

diff --git a/tests/local.mk b/tests/local.mk
index 5a237fa..f31c8b0 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -240,7 +240,6 @@ all_tests =					\
   tests/misc/od-float.sh			\
   tests/misc/mktemp.pl				\
   tests/misc/arch.sh				\
-  tests/misc/pr.pl				\
   tests/misc/join.pl				\
   tests/pr/pr-tests.pl				\
   tests/misc/pwd-option.sh			\
diff --git a/tests/misc/pr.pl b/tests/misc/pr.pl
deleted file mode 100755
index 0f25e25..0000000
--- a/tests/misc/pr.pl
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/perl
-# Exercise a bug with pr -m -s
-
-# Copyright (C) 2007-2012 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 <http://www.gnu.org/licenses/>.
-
-use strict;
-
-(my $program_name = $0) =~ s|.*/||;
-
-$ENV{PROG} = 'pr';
-my $ME = $ENV{PROG};
-
-# Turn off localization of executable's output.
-@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
-
-my @Tests =
-  (
-   ['merge-w-tabs', '-m -s -t',
-    {IN=>{1=>"a\tb\tc\n"}},
-    {IN=>{2=>"m\tn\to\n"}},
-    {IN=>{3=>"x\ty\tz\n"}},
-     {OUT=>join("\t", qw(a b c m n o x y z)) . "\n"} ],
-  );
-
-my $save_temps = $ENV{DEBUG};
-my $verbose = $ENV{VERBOSE};
-
-my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
-my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
-exit $fail;
diff --git a/tests/pr/m-w-t-1 b/tests/pr/m-w-t-1
new file mode 100644
index 0000000..8e1a7a2
--- /dev/null
+++ b/tests/pr/m-w-t-1
@@ -0,0 +1 @@
+a	b	c
diff --git a/tests/pr/m-w-t-2 b/tests/pr/m-w-t-2
new file mode 100644
index 0000000..45ef271
--- /dev/null
+++ b/tests/pr/m-w-t-2
@@ -0,0 +1 @@
+m	n	o
diff --git a/tests/pr/m-w-t-3 b/tests/pr/m-w-t-3
new file mode 100644
index 0000000..e8aca8b
--- /dev/null
+++ b/tests/pr/m-w-t-3
@@ -0,0 +1 @@
+x	y	z
diff --git a/tests/pr/pr-tests.pl b/tests/pr/pr-tests.pl
index f202414..b786482 100755
--- a/tests/pr/pr-tests.pl
+++ b/tests/pr/pr-tests.pl
@@ -407,6 +407,10 @@ my @tv = (
 # Before coreutils-8.13 page numbers were not handled correctly when
 # headers were not printed (when -l <= 10 or -t or -T specified)
 ['page-range', '+1:1 -2 -l1 -s" "',  "a\nb\nc\n", "a b\n", 0],
+
+# Exercise a bug with pr -m -s (commit 553d347)
+['merge-w-tabs', '-m -s -t', [\'m-w-t-1', \'m-w-t-2', \'m-w-t-3'],
+ join("\t", qw(a b c m n o x y z)) . "\n", 0],
 );
 
 # Convert the above old-style test vectors to the newer
-- 
1.7.6.4



From MAILER-DAEMON Thu Oct 25 03:53:10 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRIFa-0008IK-F3
	for mharc-coreutils@gnu.org; Thu, 25 Oct 2012 03:53:10 -0400
Received: from eggs.gnu.org ([208.118.235.92]:32838)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TRIFT-0008I9-0t
	for coreutils@gnu.org; Thu, 25 Oct 2012 03:53:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TRIFR-00073n-SC
	for coreutils@gnu.org; Thu, 25 Oct 2012 03:53:02 -0400
Received: from mx1.redhat.com ([209.132.183.28]:43744)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <ooprala@redhat.com>) id 1TRIFR-00073g-K8
	for coreutils@gnu.org; Thu, 25 Oct 2012 03:53:01 -0400
Received: from int-mx01.intmail.prod.int.phx2.redhat.com
	(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9P7qxFL029371
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Thu, 25 Oct 2012 03:52:59 -0400
Received: from [10.34.4.104] (unused-4-104.brq.redhat.com [10.34.4.104])
	by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9P7qvq5004449
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Thu, 25 Oct 2012 03:52:58 -0400
Message-ID: <5088EFD7.1070609@redhat.com>
Date: Thu, 25 Oct 2012 09:52:55 +0200
From: Ondrej Oprala <ooprala@redhat.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121009 Thunderbird/16.0
MIME-Version: 1.0
To: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
Subject: Re: pr: floating-point error
References: <5087A0B8.9090906@redhat.com> <5087B435.2090803@draigBrady.com>
	<5088648D.1050400@draigBrady.com>
In-Reply-To: <5088648D.1050400@draigBrady.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9P7qxFL029371
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Oct 2012 07:53:09 -0000

On 10/24/2012 11:58 PM, P=E1draig Brady wrote:
> On 10/24/2012 10:26 AM, P=E1draig Brady wrote:
>> On 10/24/2012 09:03 AM, Ondrej Oprala wrote:
>>> Hello,
>>> one of our customers made a bug report, stating that pr -nNUM FILE
>>> causes a floating point exception if NUM >=3D 32
>>> and I would really like to hear your opinion on how to solve this.
>>> The easiest solution would be to document the <32 limit for the -n=20
>>> option.
>>> The more difficult one would be to support numbers of arbitrary lengt=
h.
>>> I was thinking about the second solution and  AFAIK the line number=20
>>> is not
>>> used in any arithmetic (apart from incrementation), so it could be=20
>>> represented as
>>> an array of digits, with a function incrementing the array from the=20
>>> rightmost element
>>> as needed. Then we would just print out the array one element at a=20
>>> time. It would
>>> probably cause a performance penalty though.
>>> Thanks in advance for any advice or suggestions.
>>
>> Ouch. Confirmed that this dumps core:
>>
>>    echo . | pr -T -n.32
>>
>> We can fix that up with something like the following.
>> I'll add a test and commit.
>
> Complete proposed patch is attached.
>
> thanks,
> P=E1draig.
Thanks, the patch looks great. You're also right about the leading zeros
patch, this one makes it redundant.
thanks,
Ondrej



From MAILER-DAEMON Thu Oct 25 05:48:46 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRK3S-000166-7c
	for mharc-coreutils@gnu.org; Thu, 25 Oct 2012 05:48:46 -0400
Received: from eggs.gnu.org ([208.118.235.92]:40248)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRK3Q-00014c-E7
	for coreutils@gnu.org; Thu, 25 Oct 2012 05:48:45 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRK3H-0006eu-EB
	for coreutils@gnu.org; Thu, 25 Oct 2012 05:48:44 -0400
Received: from mx.meyering.net ([88.168.87.75]:53639)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRK3H-0006eg-6i
	for coreutils@gnu.org; Thu, 25 Oct 2012 05:48:35 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 20D21600EE;
	Thu, 25 Oct 2012 11:48:34 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: [PATCH] maint: refactor tests/misc/pr.pl into tests/pr/pr-tests.pl
In-Reply-To: <1351117383-16113-1-git-send-email-P@draigBrady.com>
	(=?iso-8859-1?Q?=22P=E1draig?=
	Brady"'s message of "Wed, 24 Oct 2012 23:23:03 +0100")
References: <1351117383-16113-1-git-send-email-P@draigBrady.com>
Date: Thu, 25 Oct 2012 11:48:34 +0200
Message-ID: <87ehkmj30t.fsf@rho.meyering.net>
Lines: 59
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Oct 2012 09:48:45 -0000

P=E1draig Brady wrote:
> * tests/misc/pr.pl: Refactor this test into ...
> * tests/pr/pr-tests.pl: ... here.
> * tests/local.mk: Remove the reference to the removed test
> * tests/pr/m-w-t-1: Input file for the refactored test.
> * tests/pr/m-w-t-2: Likewise.
> * tests/pr/m-w-t-3: Likewise.
> ---
>  tests/local.mk       |    1 -
>  tests/misc/pr.pl     |   43 -------------------------------------------
>  tests/pr/m-w-t-1     |    1 +
>  tests/pr/m-w-t-2     |    1 +
>  tests/pr/m-w-t-3     |    1 +
>  tests/pr/pr-tests.pl |    4 ++++
>  6 files changed, 7 insertions(+), 44 deletions(-)
>  delete mode 100755 tests/misc/pr.pl
>  create mode 100644 tests/pr/m-w-t-1
>  create mode 100644 tests/pr/m-w-t-2
>  create mode 100644 tests/pr/m-w-t-3

Thanks.  You're right that those should be consolidated.
However, you can move the content of misc/pr.pl into pr-tests.pl
without adding those three tiny new files to version control.

To see why, some background helps.
In pr-tests.pl, you see tests (option,I/O,exit-status quadruples)
that are very concise, e.g.,

  ['1c', '+3', [\'0Ft'], [\'3-0F'], 0],

That is the old format.  Years ago, I converted nearly all of those
tests to the newer style, which is generally preferable, but in this
case, with many explicitly-named input and output files rather than
just i/o content, converting would have made the tests less readable.
Few would fit on one line.  So, instead, I wrote the loop at the end of
that file that automatically converts the old format to the new one.

However, in the case of this test, now that you know the
old-style tests have been converted to the new style, you
can simply append that lone entry to the @Tests list:

diff --git a/tests/pr/pr-tests.pl b/tests/pr/pr-tests.pl
index f202414..c21cca3 100755
--- a/tests/pr/pr-tests.pl
+++ b/tests/pr/pr-tests.pl
@@ -451,6 +451,13 @@ foreach my $t (@tv)
     push @Tests, $new_ent;
   }

+push @Tests,
+   ['merge-w-tabs', '-m -s -t',
+    {IN=3D>{1=3D>"a\tb\tc\n"}},
+    {IN=3D>{2=3D>"m\tn\to\n"}},
+    {IN=3D>{3=3D>"x\ty\tz\n"}},
+     {OUT=3D>join("\t", qw(a b c m n o x y z)) . "\n"} ];
+
 @Tests =3D triple_test \@Tests;

 my $save_temps =3D $ENV{DEBUG};


From MAILER-DAEMON Thu Oct 25 07:03:53 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRLE9-0004Ny-Fv
	for mharc-coreutils@gnu.org; Thu, 25 Oct 2012 07:03:53 -0400
Received: from eggs.gnu.org ([208.118.235.92]:34532)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <g.esp@free.fr>) id 1TRLE1-000428-JF
	for coreutils@gnu.org; Thu, 25 Oct 2012 07:03:51 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <g.esp@free.fr>) id 1TRLE0-0002cg-9y
	for coreutils@gnu.org; Thu, 25 Oct 2012 07:03:45 -0400
Received: from smtp3-g21.free.fr ([212.27.42.3]:42205)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <g.esp@free.fr>) id 1TRLDz-0002Xu-MH
	for coreutils@gnu.org; Thu, 25 Oct 2012 07:03:44 -0400
Received: from a7n8x-e.maison (unknown [82.236.101.3])
	by smtp3-g21.free.fr (Postfix) with ESMTP id 7B40EA622B;
	Thu, 25 Oct 2012 13:03:38 +0200 (CEST)
Received: from gesp by a7n8x-e.maison with local (Exim 4.72)
	(envelope-from <g.esp@free.fr>)
	id 1TRLDb-0003IC-NA; Thu, 25 Oct 2012 13:03:19 +0200
From: Gilles Espinasse <g.esp@free.fr>
To: coreutils@gnu.org
Subject: [PATCH] tests: fix du/bind-mount-dir-cycle.sh with regular mtab
Date: Thu, 25 Oct 2012 13:03:17 +0200
Message-Id: <1351162997-12627-1-git-send-email-g.esp@free.fr>
X-Mailer: git-send-email 1.7.2.5
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3)
X-Received-From: 212.27.42.3
Cc: Gilles Espinasse <g.esp@free.fr>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Oct 2012 11:03:51 -0000

Add the message when /etc/mtab is a regular file

Avoid to log the case that does not apply using test -h /etc/mtab
---
 tests/du/bind-mount-dir-cycle.sh |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/tests/du/bind-mount-dir-cycle.sh b/tests/du/bind-mount-dir-cycle.sh
index d8d381a..79fdf61 100755
--- a/tests/du/bind-mount-dir-cycle.sh
+++ b/tests/du/bind-mount-dir-cycle.sh
@@ -33,12 +33,21 @@ mount --bind a a/b \
   || skip_ "This test requires mount with a working --bind option."
 
 echo a > exp || framework_failure_
-echo "du: mount point 'a/b' already traversed" > exp-err || framework_failure_
+echo "du: mount point 'a/b' already traversed" > exp-err-mtab-symlink || framework_failure_
+cat <<EOF > exp-err-mtab-regular || framework_failure_
+du: WARNING: Circular directory structure.
+This almost certainly means that you have a corrupted file system.
+NOTIFY YOUR SYSTEM MANAGER.
+The following directory is part of the cycle:
+  'a/b'
+
+EOF
 
 du a > out 2> err && fail=1
 sed 's/^[0-9][0-9]*	//' out > k && mv k out
 
-compare exp-err err || fail=1
+env test -h /etc/mtab && (compare exp-err-mtab-symlink err || fail=1)
+env test -h /etc/mtab || compare exp-err-mtab-regular err || fail=1
 compare exp out || fail=1
 
 Exit $fail
-- 
1.7.2.5



From MAILER-DAEMON Thu Oct 25 07:54:42 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRM1K-0006cp-Ol
	for mharc-coreutils@gnu.org; Thu, 25 Oct 2012 07:54:42 -0400
Received: from eggs.gnu.org ([208.118.235.92]:42803)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TRM1H-0006cF-TD
	for coreutils@gnu.org; Thu, 25 Oct 2012 07:54:41 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TRM1B-0001Rd-RR
	for coreutils@gnu.org; Thu, 25 Oct 2012 07:54:39 -0400
Received: from mx1.redhat.com ([209.132.183.28]:63230)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TRM1B-0001RO-Jd
	for coreutils@gnu.org; Thu, 25 Oct 2012 07:54:33 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9PBsVi5009125
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Thu, 25 Oct 2012 07:54:32 -0400
Received: from [10.36.116.83] (ovpn-116-83.ams2.redhat.com [10.36.116.83])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9PB0Qkb023530
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Thu, 25 Oct 2012 07:00:28 -0400
Message-ID: <50891BCA.7010402@draigBrady.com>
Date: Thu, 25 Oct 2012 12:00:26 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: [PATCH] maint: refactor tests/misc/pr.pl into tests/pr/pr-tests.pl
References: <1351117383-16113-1-git-send-email-P@draigBrady.com>
	<87ehkmj30t.fsf@rho.meyering.net>
In-Reply-To: <87ehkmj30t.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9PBsVi5009125
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Oct 2012 11:54:41 -0000

On 10/25/2012 10:48 AM, Jim Meyering wrote:
> P=E1draig Brady wrote:
>> * tests/misc/pr.pl: Refactor this test into ...
>> * tests/pr/pr-tests.pl: ... here.
>> * tests/local.mk: Remove the reference to the removed test
>> * tests/pr/m-w-t-1: Input file for the refactored test.
>> * tests/pr/m-w-t-2: Likewise.
>> * tests/pr/m-w-t-3: Likewise.
>> ---
>>   tests/local.mk       |    1 -
>>   tests/misc/pr.pl     |   43 ----------------------------------------=
---
>>   tests/pr/m-w-t-1     |    1 +
>>   tests/pr/m-w-t-2     |    1 +
>>   tests/pr/m-w-t-3     |    1 +
>>   tests/pr/pr-tests.pl |    4 ++++
>>   6 files changed, 7 insertions(+), 44 deletions(-)
>>   delete mode 100755 tests/misc/pr.pl
>>   create mode 100644 tests/pr/m-w-t-1
>>   create mode 100644 tests/pr/m-w-t-2
>>   create mode 100644 tests/pr/m-w-t-3
>
> Thanks.  You're right that those should be consolidated.
> However, you can move the content of misc/pr.pl into pr-tests.pl
> without adding those three tiny new files to version control.
>
> To see why, some background helps.
> In pr-tests.pl, you see tests (option,I/O,exit-status quadruples)
> that are very concise, e.g.,
>
>    ['1c', '+3', [\'0Ft'], [\'3-0F'], 0],
>
> That is the old format.  Years ago, I converted nearly all of those
> tests to the newer style, which is generally preferable, but in this
> case, with many explicitly-named input and output files rather than
> just i/o content, converting would have made the tests less readable.
> Few would fit on one line.  So, instead, I wrote the loop at the end of
> that file that automatically converts the old format to the new one.
>
> However, in the case of this test, now that you know the
> old-style tests have been converted to the new style, you
> can simply append that lone entry to the @Tests list:
>
> diff --git a/tests/pr/pr-tests.pl b/tests/pr/pr-tests.pl
> index f202414..c21cca3 100755
> --- a/tests/pr/pr-tests.pl
> +++ b/tests/pr/pr-tests.pl
> @@ -451,6 +451,13 @@ foreach my $t (@tv)
>       push @Tests, $new_ent;
>     }
>
> +push @Tests,
> +   ['merge-w-tabs', '-m -s -t',
> +    {IN=3D>{1=3D>"a\tb\tc\n"}},
> +    {IN=3D>{2=3D>"m\tn\to\n"}},
> +    {IN=3D>{3=3D>"x\ty\tz\n"}},
> +     {OUT=3D>join("\t", qw(a b c m n o x y z)) . "\n"} ];
> +
>   @Tests =3D triple_test \@Tests;
>
>   my $save_temps =3D $ENV{DEBUG};

Much better.

Pushed with that adjustment.

thanks,
P=E1draig.


From MAILER-DAEMON Thu Oct 25 09:37:43 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRNd1-00059L-RI
	for mharc-coreutils@gnu.org; Thu, 25 Oct 2012 09:37:43 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49354)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRNcr-0004eM-Il
	for coreutils@gnu.org; Thu, 25 Oct 2012 09:37:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRNco-0003GD-Vq
	for coreutils@gnu.org; Thu, 25 Oct 2012 09:37:33 -0400
Received: from mx.meyering.net ([88.168.87.75]:54146)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRNco-0003FT-KI
	for coreutils@gnu.org; Thu, 25 Oct 2012 09:37:30 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 7DBF2600DF;
	Thu, 25 Oct 2012 15:37:28 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Stefano Lattarini <stefano.lattarini@gmail.com>
Subject: Re: [PATCH] build: do not require help2man at build-from-tarball time
In-Reply-To: <5087C706.3050205@gmail.com> (Stefano Lattarini's message of
	"Wed, 24 Oct 2012 12:46:30 +0200")
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com> <87txtkl07c.fsf@rho.meyering.net>
	<5087B58E.2040401@gmail.com> <5087C511.4050907@gmail.com>
	<5087C706.3050205@gmail.com>
Date: Thu, 25 Oct 2012 15:37:28 +0200
Message-ID: <87a9vahduv.fsf@rho.meyering.net>
Lines: 318
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: coreutils@gnu.org, 12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Oct 2012 13:37:41 -0000

Stefano Lattarini wrote:
...
> Here is the updated patch.  Sorry for the noise,
>   Stefano
>
> ----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----
>
>>From f61dcb763975c1aab299fa9678ea180d70db6acf Mon Sep 17 00:00:00 2001
> Message-Id: <f61dcb763975c1aab299fa9678ea180d70db6acf.1351075572.git.stefano.lattarini@gmail.com>
> From: Stefano Lattarini <stefano.lattarini@gmail.com>
> Date: Tue, 11 Sep 2012 20:54:30 +0200
> Subject: [PATCH] build: graceful degradation in man pages generation if perl

Thanks.  That looks good.
I've made some minor changes.  Here's an incremental:

diff --git a/man/dummy-man b/man/dummy-man
index 2e32320..633a5ba 100755
--- a/man/dummy-man
+++ b/man/dummy-man
@@ -1,7 +1,7 @@
 #!/bin/sh
-# Poor placeholder for help2man invocation on systems lacking perl;
-# it generates a dummy manpage stating that as proper manpage could
-# not be generated, and redirecting the user back to either the info
+# Poor man's placeholder for help2man invocation on systems lacking perl;
+# it generates a dummy man page stating that a proper one could not be
+# generated, and redirecting the user back to either the info
 # documentation or the '--help' output.

 set -e; set -u
@@ -42,8 +42,8 @@ test $# -le 1 || fatal_ "too many non-option arguments"

 baseout=`basename_ "$output"`
 sed 's/^/WARNING: /' >&2 <<END
-Cannot create proper man page '$baseout' since perl is missing or
-inadequate on this system.  Will create a stub man page instead.
+Cannot create proper '$baseout' man page, since perl is missing or
+inadequate on this system.  Creating a stub man page instead.
 END

 progname=`basename_ "$1"`
@@ -53,20 +53,20 @@ bs='\'
 cat >"$output" <<END
 .TH "$progname" 1 "$year" "$source" "User Commands"
 .SH NAME
-$progname $bs- a GNU coreutils program
+$progname $bs- a $source program
 .SH DESCRIPTION
 .B OOOPS!
-Due to lack of perl on your system, the GNU coreutils build system
-hasn't been able to create the manual page for
+Due to lack of perl on your system, the $source build system
+failed to create the manual page for
 .B $progname.
-For a quick help about that program, try running
+For concise option descriptions, run
 .IP
 .B env $progname --help
 .PP
 The full documentation for
 .B $progname
-is maintained as a Texinfo manual, which you might be accessible
-on your system with the command
+is maintained as a Texinfo manual, which should be accessible
+on your system via the command
 .IP
 .B info coreutils $bs(aq$progname invocation$bs(aq
 END

Here is the merged result, also with an adjusted log.  Ok?

----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----
>From 6f64d745fb2ce525a056b016ef4ada66416c9e8d Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <stefano.lattarini@gmail.com>
Date: Tue, 11 Sep 2012 20:54:30 +0200
Subject: [PATCH] build: graceful degradation in man pages generation if perl
 is lacking

Since commit v8.19-118-g57da212, our 'dist-hook' rule tweaks the
distributed Makefile.in so that each man page 'man/foo.1' depends
on the corresponding source 'src/foo.c' rather than the corresponding
program 'src/foo'.  That is done to accommodate inferior systems that,
lacking perl, cannot run help2man to regenerate the manpage after
its corresponding program has been built.

This seems a right and proper graceful degradation, in that the
man pages dependencies are still 100% correct in a git checkout,
while being laxer but "more portable" in a distribution tarball.

Alas, that is not the case in practice, as it turns out the tweaked
Makefile makes the building of man pages unreliable and potentially
incorrect!

In fact, assume that instead of the correct a dependency:

    man/ls.1: src/ls

we have the laxer one:

    man/ls.1: src/ls.c

and think of what happens if a user modifies, say, 'src/ls.c', and then
runs "make -j4" to rebuild everything.  The make process will see that
it has to rebuild the man page 'man/ls.1' (because its prerequisite
'src/ls.c' has changed), but won't see that it has to rebuild 'src/ls'
*before* re-running 'help2man' to generate that man page; so, if
'man/ls.1' is rebuilt before 'src/ls' (which can happen with concurrent
make), our user will get either a build error (if 'src/ls' did non
exist) or, worse, a man page with an up-to-date timestamp but an
out-of-date content.  And what's even worse in all of this is that
this problem will be present also for users who have perl installed:
this is not a "graceful degradation" at all!

In our situation, the best and simplest way to implement a graceful
degradation it to keep the correct dependencies for man pages (that
is, "man/ls.1: src/ls"), and if perl is not present, just generate
dummy man pages reporting that built-time issue and redirecting the
user back to either the info documentation or the '--help' output.

As a consequence of this change, we also stop distributing man pages,
since they will now be generated unconditionally.

* Makefile.am (do-not-require-help2man): Remove.
(dist-hook): Don't depend on it.
* man/local.mk: Remove an obsolete comment.
(EXTRA_DIST): Stop distributing generated man pages.
($(EXTRA_MANS)): This no longer needs to depend on $(all_programs).
(MAINTAINERCLEANFILES): $(ALL_MANS) Do not list it here, and ...
(CLEANFILES): ... list it here, instead.
(.x.1): Instead of warning if perl is missing, but then trying to run
'help2man' unconditionally, simply run ...
(run_help2man): ... the command referenced by this new variable, that
expands to a proper invocation of 'help2man' if perl is present, and
to an invocation of a shell script generating a dummy manpage if it
is not.
(EXTRA_DIST): Distribute that shell script.
* man/dummy-man: New shell script.
Fixes coreutils http://bugs.gnu.org/12715.
---
 Makefile.am   | 20 +----------------
 man/dummy-man | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/local.mk  | 25 +++++++++++----------
 3 files changed, 86 insertions(+), 31 deletions(-)
 create mode 100755 man/dummy-man

diff --git a/Makefile.am b/Makefile.am
index 0232090..5eaa45b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -93,29 +93,11 @@ BUILT_SOURCES = .version
 .version:
 	$(AM_V_GEN)echo $(VERSION) > $@-t && mv $@-t $@

-# In general, we run help2man to build a man page from the binary's --help
-# output, but when building from a just-unpacked distribution tarball, we
-# must not do that, since help2man uses perl.  We don't want to depend on
-# perl in that case.  In general, the .1 file does indeed depend on the
-# binary.  I.e., for cat, we have this Makefile dependency:
-#   man/cat.1: src/cat
-# That means that once we build src/cat, we would trigger the .x.1
-# rule which runs help2man.  The trick is simply to change the RHS to
-# "src/cat.c" in the $(distdir) that we're about to tar and compress.
-# Also handle the three exceptions corresponding to the three binaries
-# for which there is no like-named .c file: dir, vdir, ginstall.
-.PHONY: do-not-require-help2man
-do-not-require-help2man:
-	perl -pi -e 's,^(man/.+?\.1:\s*src/.+?)$$,$$1.c,;'		\
-	    -e  's,^(man/.+?\.1:\s*src)/ginstall\.c$$,$$1/install.c,;'	\
-	    -e  's,^(man/.+?\.1:\s*src)/v?dir\.c$$,$$1/ls.c,;'		\
-          $(distdir)/Makefile.in
-
 # Arrange so that .tarball-version appears only in the distribution
 # tarball, and never in a checked-out repository.
 # The perl substitution is to change some key uses of "rm" to "/bin/rm".
 # See the rm_subst comment for details.
-dist-hook: gen-ChangeLog do-not-require-help2man
+dist-hook: gen-ChangeLog
 	$(AM_V_GEN)echo $(VERSION) > $(distdir)/.tarball-version
 	$(AM_V_at)perl -pi -e '$(rm_subst)' $(distdir)/Makefile.in

diff --git a/man/dummy-man b/man/dummy-man
new file mode 100755
index 0000000..633a5ba
--- /dev/null
+++ b/man/dummy-man
@@ -0,0 +1,72 @@
+#!/bin/sh
+# Poor man's placeholder for help2man invocation on systems lacking perl;
+# it generates a dummy man page stating that a proper one could not be
+# generated, and redirecting the user back to either the info
+# documentation or the '--help' output.
+
+set -e; set -u
+
+fatal_ ()
+{
+  printf '%s: %s\n' "$0" "$*" >&2
+  exit 1
+}
+
+basename_ ()
+{
+  printf '%s\n' "$1" | sed 's,.*/,,'
+}
+
+output=
+source="GNU coreutils"
+while test $# -gt 0; do
+  case $1 in
+    # Help2man options we recognize and handle.
+    --output=*) output=`expr x"$1" : x'--output=\(.*\)'`;;
+    --output) shift; output=$1;;
+    --source=*) source=`expr x"$1" : x'--source=\(.*\)'`;;
+    --source) shift; source=$1;;
+    # Recognize (as no-op) other help2man options that might be used
+    # in the makefile.
+    --include=*);;
+    --include) shift;;
+    -*) fatal_ "invalid or unrecognized help2man option '$1'";;
+    --) shift; break;;
+     *) break;;
+  esac
+  shift
+done
+
+test $# -gt 0 || fatal_ "missing argument"
+test $# -le 1 || fatal_ "too many non-option arguments"
+
+baseout=`basename_ "$output"`
+sed 's/^/WARNING: /' >&2 <<END
+Cannot create proper '$baseout' man page, since perl is missing or
+inadequate on this system.  Creating a stub man page instead.
+END
+
+progname=`basename_ "$1"`
+year=`LC_ALL=C date +%Y`
+bs='\'
+
+cat >"$output" <<END
+.TH "$progname" 1 "$year" "$source" "User Commands"
+.SH NAME
+$progname $bs- a $source program
+.SH DESCRIPTION
+.B OOOPS!
+Due to lack of perl on your system, the $source build system
+failed to create the manual page for
+.B $progname.
+For concise option descriptions, run
+.IP
+.B env $progname --help
+.PP
+The full documentation for
+.B $progname
+is maintained as a Texinfo manual, which should be accessible
+on your system via the command
+.IP
+.B info coreutils $bs(aq$progname invocation$bs(aq
+END
diff --git a/man/local.mk b/man/local.mk
index ebc111d..2c05bb6 100644
--- a/man/local.mk
+++ b/man/local.mk
@@ -16,17 +16,24 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

-EXTRA_DIST += man/help2man
+EXTRA_DIST += man/help2man man/dummy-man
+
+## Graceful degradation for systems lacking perl.
+if HAVE_PERL
+run_help2man = $(PERL) -- $(srcdir)/man/help2man
+else
+run_help2man = $(SHELL) $(srcdir)/man/dummy-man
+endif

 man1_MANS = @man1_MANS@
-EXTRA_DIST += $(man1_MANS) $(man1_MANS:.1=.x)
+EXTRA_DIST += $(man1_MANS:.1=.x)

 EXTRA_MANS = @EXTRA_MANS@
-EXTRA_DIST += $(EXTRA_MANS) $(EXTRA_MANS:.1=.x)
+EXTRA_DIST += $(EXTRA_MANS:.1=.x)

 ALL_MANS = $(man1_MANS) $(EXTRA_MANS)

-MAINTAINERCLEANFILES += $(ALL_MANS)
+CLEANFILES += $(ALL_MANS)

 # This is required because we have subtle inter-directory dependencies:
 # in order to generate all man pages, even those for which we don't
@@ -161,13 +168,7 @@ man/whoami.1:    src/whoami
 man/yes.1:       src/yes

 .x.1:
-	$(AM_V_GEN)case '$(PERL)' in				\
-	  *"/missing "*)					\
-	    echo 'WARNING: cannot update man page $@ since perl is missing' \
-	      'or inadequate' 1>&2				\
-	    exit 0;;						\
-	esac; \
-	name=`echo $@ | sed -e 's|.*/||' -e 's|\.1$$||'` || exit 1;	\
+	$(AM_V_GEN)name=`echo $@ | sed 's|.*/||; s|\.1$$||'` || exit 1;	\
 ## Ensure that help2man runs the 'src/ginstall' binary as 'install' when
 ## creating 'install.1'.  Similarly, ensure that it uses the 'src/[' binary
 ## to create 'test.1'.
@@ -184,7 +185,7 @@ man/yes.1:       src/yes
 	  && rm -rf $$t							\
 	  && $(MKDIR_P) $$t						\
 	  && (cd $$t && $(LN_S) '$(abs_top_builddir)/src/'$$prog $$name) \
-	  && $(PERL) -- $(srcdir)/man/help2man				\
+	  && $(run_help2man)						\
 		     --source='$(PACKAGE_STRING)'			\
 		     --include=$(srcdir)/man/$$name.x			\
 		     --output=$$t/$$name.1 $$t/$$name			\
--
1.8.0


From MAILER-DAEMON Thu Oct 25 10:05:32 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRO3w-00018J-1M
	for mharc-coreutils@gnu.org; Thu, 25 Oct 2012 10:05:32 -0400
Received: from eggs.gnu.org ([208.118.235.92]:45128)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRO3n-0000n1-Ly
	for coreutils@gnu.org; Thu, 25 Oct 2012 10:05:30 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRO3W-0004zD-1p
	for coreutils@gnu.org; Thu, 25 Oct 2012 10:05:18 -0400
Received: from moutng.kundenserver.de ([212.227.17.10]:58691)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRO3V-0004qI-PV
	for coreutils@gnu.org; Thu, 25 Oct 2012 10:05:05 -0400
Received: from [192.168.2.108] (p4FF77F0F.dip.t-dialin.net [79.247.127.15])
	by mrelayeu.kundenserver.de (node=mreu4) with ESMTP (Nemesis)
	id 0LhpBu-1T67s01hGk-00nJnv; Thu, 25 Oct 2012 16:04:50 +0200
Message-ID: <50894701.2030700@bernhard-voelker.de>
Date: Thu, 25 Oct 2012 16:04:49 +0200
From: Bernhard Voelker <mail@bernhard-voelker.de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: bug#12715: [PATCH] build: do not require help2man at
	build-from-tarball time
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com>
	<87txtkl07c.fsf@rho.meyering.net> <5087B58E.2040401@gmail.com>
	<5087C511.4050907@gmail.com> <5087C706.3050205@gmail.com>
	<87a9vahduv.fsf@rho.meyering.net>
In-Reply-To: <87a9vahduv.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Provags-ID: V02:K0:/WLKDpiz0OsGHyp8msMQ3kAfRM3ofY/pafgNDlAmS8H
	gtQ1UMMNadA7ntUQb5JjIIas4X+wcseBjAwDbwINpvdZuTxgGk
	Zig0OkzWMVVeK2sfCOt6srsqpDkpHcZNAlWE/2TrRocoBcaKdU
	baZgpz6kieNAC9anZQ7LRIK80v91KB2sE6Bnpfm2AXJOD+qkku
	kcMUG+qJVjJZwamPwMvkET6LWvADSInosFMA+wZDUaxJVbUbFZ
	0Tj8hO4HKVoKnTBprcfc554Zk1RaxOaxK5JRc8eg6i7pV8QpNo
	+G6c7DD+CdY4Mw61xlPPSZ3/xahrvqq5HBJ+x2VnVcaiS8BTdI
	wbnDlCs6HxCPdf9LbIcDnjCaX1PMDTps8JpQ7IWOO
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 212.227.17.10
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>, coreutils@gnu.org,
	12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Oct 2012 14:05:30 -0000

On 10/25/2012 03:37 PM, Jim Meyering wrote:
> -Due to lack of perl on your system, the GNU coreutils build system
> -hasn't been able to create the manual page for
> +Due to lack of perl on your system, the $source build system
> +failed to create the manual page for

Isn't it "Due to lack on the build system, ..."?

I.e. coreutils could be built on system A lacking perl,
and then be installed on system B which has perl. The above
text would be misleading in this case.

Have a nice day,
Berny


From MAILER-DAEMON Thu Oct 25 10:08:45 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRO73-0003WM-CX
	for mharc-coreutils@gnu.org; Thu, 25 Oct 2012 10:08:45 -0400
Received: from eggs.gnu.org ([208.118.235.92]:46152)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRO70-0003Se-O7
	for coreutils@gnu.org; Thu, 25 Oct 2012 10:08:43 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRO6r-0005y6-7s
	for coreutils@gnu.org; Thu, 25 Oct 2012 10:08:42 -0400
Received: from mx.meyering.net ([88.168.87.75]:54221)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRO6r-0005y0-0X
	for coreutils@gnu.org; Thu, 25 Oct 2012 10:08:33 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id C36FA6024F;
	Thu, 25 Oct 2012 16:08:31 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: Re: bug#12715: [PATCH] build: do not require help2man at
	build-from-tarball time
In-Reply-To: <50894701.2030700@bernhard-voelker.de> (Bernhard Voelker's
	message of "Thu, 25 Oct 2012 16:04:49 +0200")
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com> <87txtkl07c.fsf@rho.meyering.net>
	<5087B58E.2040401@gmail.com> <5087C511.4050907@gmail.com>
	<5087C706.3050205@gmail.com> <87a9vahduv.fsf@rho.meyering.net>
	<50894701.2030700@bernhard-voelker.de>
Date: Thu, 25 Oct 2012 16:08:31 +0200
Message-ID: <874nlihcf4.fsf@rho.meyering.net>
Lines: 31
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>, coreutils@gnu.org,
	12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Oct 2012 14:08:43 -0000

Bernhard Voelker wrote:
> On 10/25/2012 03:37 PM, Jim Meyering wrote:
>> -Due to lack of perl on your system, the GNU coreutils build system
>> -hasn't been able to create the manual page for
>> +Due to lack of perl on your system, the $source build system
>> +failed to create the manual page for
>
> Isn't it "Due to lack on the build system, ..."?
>
> I.e. coreutils could be built on system A lacking perl,
> and then be installed on system B which has perl. The above
> text would be misleading in this case.

Good point.
I've merged this in:

diff --git a/man/dummy-man b/man/dummy-man
index 633a5ba..3069376 100755
--- a/man/dummy-man
+++ b/man/dummy-man
@@ -56,8 +56,8 @@ cat >"$output" <<END
 $progname $bs- a $source program
 .SH DESCRIPTION
 .B OOOPS!
-Due to lack of perl on your system, the $source build system
-failed to create the manual page for
+Due to the lack of perl on the build system, we were
+unable to create a proper manual page for
 .B $progname.
 For concise option descriptions, run
 .IP


From MAILER-DAEMON Thu Oct 25 10:26:19 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TROO3-0007d6-0i
	for mharc-coreutils@gnu.org; Thu, 25 Oct 2012 10:26:19 -0400
Received: from eggs.gnu.org ([208.118.235.92]:44673)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRONs-0007Qf-2S
	for coreutils@gnu.org; Thu, 25 Oct 2012 10:26:17 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRONh-0004S6-OY
	for coreutils@gnu.org; Thu, 25 Oct 2012 10:26:08 -0400
Received: from moutng.kundenserver.de ([212.227.126.186]:63580)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRONh-0004Rh-FK
	for coreutils@gnu.org; Thu, 25 Oct 2012 10:25:57 -0400
Received: from [192.168.2.108] (p4FF77F0F.dip.t-dialin.net [79.247.127.15])
	by mrelayeu.kundenserver.de (node=mreu3) with ESMTP (Nemesis)
	id 0Lq2aK-1SwkSc3j84-00dkHJ; Thu, 25 Oct 2012 16:25:43 +0200
Message-ID: <50894BE6.7070506@bernhard-voelker.de>
Date: Thu, 25 Oct 2012 16:25:42 +0200
From: Bernhard Voelker <mail@bernhard-voelker.de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: bug#12715: [PATCH] build: do not require help2man at
	build-from-tarball time
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com>
	<87txtkl07c.fsf@rho.meyering.net> <5087B58E.2040401@gmail.com>
	<5087C511.4050907@gmail.com> <5087C706.3050205@gmail.com>
	<87a9vahduv.fsf@rho.meyering.net>
	<50894701.2030700@bernhard-voelker.de>
	<874nlihcf4.fsf@rho.meyering.net>
In-Reply-To: <874nlihcf4.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Provags-ID: V02:K0:8ihw69p4kjBEhIlZVtx3R9XQZxz8iLDHgUKP6JELkV4
	jB8c3wsUJCvuh/ABjHj+Y8iDJyNQRSXuwMPhyz0U62VL/wIZ8n
	B16C2aEiFyu+Z/V7q3pYWdRbP+BJCMjOn07K8h01HFD1xm2nAC
	7UQj2ppASTjyF2iA7TPvTQgRHB8kCC9C4Ctjt7A24Wq/z7TCic
	BiUfNN3in3+J+WYnaKnH2oqnddWvSRggxjWi16Pp36A8+2fhCx
	oIGCWUdyzVf+jpJD9zrn80y6uadC5fCgOKu7cS0jncWLrDjqgK
	jxHFAbj6blWGq7jfN8broryh3kHh47PPPfaUnCGDK2tq2EQG/j
	oKXtTOMKjCtIjQ8xY2w9QGAGOzeSaQ1Cq8Kb7M73I
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 212.227.126.186
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>, coreutils@gnu.org,
	12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Oct 2012 14:26:17 -0000

On 10/25/2012 04:08 PM, Jim Meyering wrote:
> Bernhard Voelker wrote:
>> Isn't it "Due to lack on the build system, ..."?
>>
>> I.e. coreutils could be built on system A lacking perl,
>> and then be installed on system B which has perl. The above
>> text would be misleading in this case.
> 
> Good point.
> I've merged this in:
> 
> diff --git a/man/dummy-man b/man/dummy-man
> index 633a5ba..3069376 100755
> --- a/man/dummy-man
> +++ b/man/dummy-man
> @@ -56,8 +56,8 @@ cat >"$output" <<END
>  $progname $bs- a $source program
>  .SH DESCRIPTION
>  .B OOOPS!
> -Due to lack of perl on your system, the $source build system
> -failed to create the manual page for
> +Due to the lack of perl on the build system, we were
> +unable to create a proper manual page for
>  .B $progname.
>  For concise option descriptions, run
>  .IP

Looks good, thanks.

Berny


From MAILER-DAEMON Thu Oct 25 19:12:52 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRWbc-00058v-Fx
	for mharc-coreutils@gnu.org; Thu, 25 Oct 2012 19:12:52 -0400
Received: from eggs.gnu.org ([208.118.235.92]:44645)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRWbP-00057A-7t
	for coreutils@gnu.org; Thu, 25 Oct 2012 19:12:51 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRWbB-0004FY-2o
	for coreutils@gnu.org; Thu, 25 Oct 2012 19:12:39 -0400
Received: from moutng.kundenserver.de ([212.227.17.8]:54796)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRWbA-0004FG-PW
	for coreutils@gnu.org; Thu, 25 Oct 2012 19:12:25 -0400
Received: from [192.168.2.108] (p4FF77F0F.dip.t-dialin.net [79.247.127.15])
	by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis)
	id 0MQtv4-1TrLBp1NL4-00Trwf; Fri, 26 Oct 2012 01:12:23 +0200
Message-ID: <5089C756.7050205@bernhard-voelker.de>
Date: Fri, 26 Oct 2012 01:12:22 +0200
From: Bernhard Voelker <mail@bernhard-voelker.de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: Coreutils <coreutils@gnu.org>
Subject: factor tests: ugly long file names
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Provags-ID: V02:K0:MzN+ZWesATZL6H8l0Cl+Qjo4/7t+XvtEHApIu5M9bU8
	knfMPJR+xEHVWwxZ70jdDJjGiPvYuuQ31IqQB++m8kuoyJzo9d
	7V1TxR1MwYZ2ciV1PJgtkUNfZKpSWQw14QV9EA4vdd7MsjIWPv
	ZSin17zxHuRcMKKnf56XAgcSYLu/Z+4ymCpJwFjtlRwBhPl8PQ
	U4jucxv0UNSRqJcenvGFrEIF60o3Bd9yL8gERC/q1ERiRXH1yV
	UzfjkInAllShzHDH21HuMAfuhpdVBSbsbQOuDDQD5awzq05qLm
	VYQ+3yqofIR9HiRqrKHbNXSfNU+ZPeZfG6ozWDHC7qOL7J/G/r
	WyNGWbSoF5qsRExf943UkwEdwrTbfQk4c33kmWlKV
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 212.227.17.8
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Oct 2012 23:12:51 -0000

I was just wondering if we shouldn't refactor the new factor tests.

They have ugly and long file names (the test data), and have identical content
(which is redundancy which in turn should be avoided IMO):

$ md5sum *.sh
31c3a9e8b5dad969dafd07c348c48233  0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0.sh
31c3a9e8b5dad969dafd07c348c48233  10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016.sh
31c3a9e8b5dad969dafd07c348c48233
170141183460469225450570946617781744489-170141183460469225450570946617781744489-4622287c5f040cdb7b3bbe4d19d29a71ab277827.sh
31c3a9e8b5dad969dafd07c348c48233
170141183460469229545748130981302223887-170141183460469229545748130981302223887-dea308253708b57afad357e8c0d2a111460ef50e.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073708551616-18446744073708651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073708651616-18446744073708751615-729228e693b1a568ecc85b199927424c7d16d410.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073708751616-18446744073708851615-5a0c985017c2d285e4698f836f5a059e0b684563.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073708851616-18446744073708951615-0482295c514e371c98ce9fd335deed0c9c44a4f4.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073708951616-18446744073709051615-9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073709051616-18446744073709151615-604366d2b1d75371d0679e6a68962d66336cd383.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073709151616-18446744073709251615-9192d2bdee930135b28d7160e6d395a7027871da.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073709251616-18446744073709351615-bcf56ae55d20d700690cff4d3327b78f83fc01bf.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073709351616-18446744073709451615-16b106398749e5f24d278ba7c58229ae43f650ac.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073709451616-18446744073709551615-ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073709551616-18446744073709651615-2b6f9c11742d9de045515a6627c27a042c49f8ba.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073709651616-18446744073709751615-54851acd51c4819beb666e26bc0100dc9adbc310.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073709751616-18446744073709851615-6939c2a7afd2d81f45f818a159b7c5226f83a50b.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073709851616-18446744073709951615-0f2c8bc011d2a45e2afa01459391e68873363c6c.sh
31c3a9e8b5dad969dafd07c348c48233  18446744073709951616-18446744073710051615-630dc2ad72f4c222bad1405e6c5bea590f92a98c.sh
31c3a9e8b5dad969dafd07c348c48233  20000000-30000000-8115e8dff97d1674134ec054598d939a2a5f6113.sh
31c3a9e8b5dad969dafd07c348c48233  30000000-40000000-fe7b832c8e0ed55035152c0f9ebd59de73224a60.sh
31c3a9e8b5dad969dafd07c348c48233  40000000-50000000-b8786d66c432e48bc5b342ee3c6752b7f096f206.sh
31c3a9e8b5dad969dafd07c348c48233  50000000-60000000-a74fe518c5f79873c2b9016745b88b42c8fd3ede.sh
31c3a9e8b5dad969dafd07c348c48233  60000000-70000000-689bc70d681791e5d1b8ac1316a05d0c4473d6db.sh
31c3a9e8b5dad969dafd07c348c48233  70000000-80000000-d370808f2ab8c865f64c2ff909c5722db5b7d58d.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543940336-79228162514264337593543942335-63cbd6313d78247b04d63bbbac50cb8f8d33ff71.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543942336-79228162514264337593543944335-0d03d63653767173182491b86fa18f8f680bb036.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543944336-79228162514264337593543946335-ca43bd38cd9f97cc5bb63613cb19643578640f0b.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543946336-79228162514264337593543948335-86d59545a0c13567fa96811821ea5cde950611b1.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543948336-79228162514264337593543950335-c3740e702fa9c97e6cf00150860e0b936a141a6b.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543950336-79228162514264337593543952335-551c3c4c4640d86fda311b5c3006dac45505c0ce.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543952336-79228162514264337593543954335-b1b0b00463c2f853d70ef9c4f7a96de5cb614156.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543954336-79228162514264337593543956335-8938a484a9ef6bb16478091d294fcde9f8ecea69.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543956336-79228162514264337593543958335-d1ae6bc712d994f35edf55c785d71ddf31f16535.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543958336-79228162514264337593543960335-2374919a89196e1fce93adfe779cb4664556d4b6.sh
31c3a9e8b5dad969dafd07c348c48233
79228162514264337593543960336-79228162514264337593543962335-569e4363e8d9e8830a187d9ab27365eef08abde1.sh
31c3a9e8b5dad969dafd07c348c48233  80000000-90000000-7978aa66bf2bdb446398336ea6f02605e9a77581.sh
31c3a9e8b5dad969dafd07c348c48233  run.sh

Have a nice day,
Berny


From MAILER-DAEMON Thu Oct 25 19:28:13 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRWqT-0007Sn-P9
	for mharc-coreutils@gnu.org; Thu, 25 Oct 2012 19:28:13 -0400
Received: from eggs.gnu.org ([208.118.235.92]:57312)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRWqR-0007Sc-SF
	for coreutils@gnu.org; Thu, 25 Oct 2012 19:28:12 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRWqR-0007v9-37
	for coreutils@gnu.org; Thu, 25 Oct 2012 19:28:11 -0400
Received: from moutng.kundenserver.de ([212.227.17.9]:60936)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRWqQ-0007v2-PX
	for coreutils@gnu.org; Thu, 25 Oct 2012 19:28:10 -0400
Received: from [192.168.2.108] (p4FF77F0F.dip.t-dialin.net [79.247.127.15])
	by mrelayeu.kundenserver.de (node=mrbap3) with ESMTP (Nemesis)
	id 0Mdurl-1Tm60C3sRJ-00Pd1p; Fri, 26 Oct 2012 01:28:10 +0200
Message-ID: <5089CB09.4050705@bernhard-voelker.de>
Date: Fri, 26 Oct 2012 01:28:09 +0200
From: Bernhard Voelker <mail@bernhard-voelker.de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: Coreutils <coreutils@gnu.org>
Subject: Re: factor tests: ugly long file names
References: <5089C756.7050205@bernhard-voelker.de>
In-Reply-To: <5089C756.7050205@bernhard-voelker.de>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Provags-ID: V02:K0:6bc4a3mnFl37Ro4zOV9DGADxEguF1Qa1Vzp2+1O5Waf
	45znVZOVZnOnZ8S1XA9bxHLPVulV2hadQgvkbm2YtG0W6BHz+R
	DEWgd9je1Ut/+NPwajecq7k7DWo2MQpQ0U1Rye2L6kDKDjL2+9
	HU9iJ5acPEUpT6rhDqPkzENl/WM+XQGILRl+Hjurormd/p0Fdp
	8ThuVrPQzUZR09FeDz+t3YvFTpJVzUBRykf8SS7T6tRL45GY3d
	k4utzrWdc/uTH/aK18iDGoXOokqS7CNJYb/iTYieyQunxriZ1j
	mlzxNDE/YM8N1CA7nAJjksT0zFZhWqfe97TTDYFjQjSUlbM85g
	NOeSC/A5cgWbneVis65M9WIiUR+mmnYRvCFbHfb33
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 212.227.17.9
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Oct 2012 23:28:12 -0000

On 10/26/2012 01:12 AM, Bernhard Voelker wrote:
> I was just wondering if we shouldn't refactor the new factor tests.
> 
> They have ugly and long file names (the test data), and have identical content
> (which is redundancy which in turn should be avoided IMO):
> 
> $ md5sum *.sh
> 31c3a9e8b5dad969dafd07c348c48233  0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0.sh
> 31c3a9e8b5dad969dafd07c348c48233  10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016.sh
> [...]
> 31c3a9e8b5dad969dafd07c348c48233  run.sh

Opps, they are hard links ...
... but yet ugly in 'make check' output.

Have a nice day,
Berny


From MAILER-DAEMON Fri Oct 26 03:48:59 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRef5-0004Jb-Cs
	for mharc-coreutils@gnu.org; Fri, 26 Oct 2012 03:48:59 -0400
Received: from eggs.gnu.org ([208.118.235.92]:41700)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TRef3-0004Ie-Qt
	for coreutils@gnu.org; Fri, 26 Oct 2012 03:48:58 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TRef2-0004iQ-Qh
	for coreutils@gnu.org; Fri, 26 Oct 2012 03:48:57 -0400
Received: from mail-bk0-f41.google.com ([209.85.214.41]:63008)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TRef2-0004iI-Jy
	for coreutils@gnu.org; Fri, 26 Oct 2012 03:48:56 -0400
Received: by mail-bk0-f41.google.com with SMTP id jm1so1101130bkc.0
	for <coreutils@gnu.org>; Fri, 26 Oct 2012 00:48:55 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=message-id:date:from:mime-version:to:cc:subject:references
	:in-reply-to:content-type:content-transfer-encoding;
	bh=7y3jW06zWxJV3h27HRjl+7Bm4ftnFLhoaXXnbWJhc/k=;
	b=bmiXL7kITExxFWd2Mw20AG2CJrDXbJJ+OyoZY0jZl10NTZe1xDxsb32/7EDLfbo+3j
	SqbvgmXY42wkzDd35IJtYM7SoI5weLFH7L7PWHfTjEJxuEladU5wWFh+K2VsYywtv2SA
	vdNbSxCZaY5SkZvowR8YtKScavUri21bow4KApfv6zzwnzUExYGO5VvdJhLHxDCeym8x
	GJk445THWLwZVCqBTT6qorFjIrCdwxMRLIKRK2vU79sMYnn3MOSHGDWNocUt9lepIFSo
	1yo4sNNjH7Xqvy1Q9F27/ys+aOHOyN79Kz6YZLSq00f6JgVQboT6BJZt1kZKkXB5ow2p
	iYAA==
Received: by 10.204.8.208 with SMTP id i16mr6690044bki.116.1351237735489;
	Fri, 26 Oct 2012 00:48:55 -0700 (PDT)
Received: from [192.168.178.21]
	(host247-100-dynamic.8-87-r.retail.telecomitalia.it. [87.8.100.247])
	by mx.google.com with ESMTPS id j24sm213527bkv.0.2012.10.26.00.48.53
	(version=SSLv3 cipher=OTHER); Fri, 26 Oct 2012 00:48:54 -0700 (PDT)
Message-ID: <508A4057.2030800@gmail.com>
Date: Fri, 26 Oct 2012 09:48:39 +0200
From: Stefano Lattarini <stefano.lattarini@gmail.com>
MIME-Version: 1.0
To: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: Re: bug#12715: [PATCH] build: do not require help2man at
	build-from-tarball time
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com>
	<87txtkl07c.fsf@rho.meyering.net> <5087B58E.2040401@gmail.com>
	<5087C511.4050907@gmail.com> <5087C706.3050205@gmail.com>
	<87a9vahduv.fsf@rho.meyering.net>
	<50894701.2030700@bernhard-voelker.de>
	<874nlihcf4.fsf@rho.meyering.net>
	<50894BE6.7070506@bernhard-voelker.de>
In-Reply-To: <50894BE6.7070506@bernhard-voelker.de>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.85.214.41
Cc: 12715@debbugs.gnu.org, coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Oct 2012 07:48:58 -0000

On 10/25/2012 04:25 PM, Bernhard Voelker wrote:
> On 10/25/2012 04:08 PM, Jim Meyering wrote:
>> Bernhard Voelker wrote:
>>> Isn't it "Due to lack on the build system, ..."?
>>>
>>> I.e. coreutils could be built on system A lacking perl,
>>> and then be installed on system B which has perl. The above
>>> text would be misleading in this case.
>>
>> Good point.
>> I've merged this in:
>>
>> diff --git a/man/dummy-man b/man/dummy-man
>> index 633a5ba..3069376 100755
>> --- a/man/dummy-man
>> +++ b/man/dummy-man
>> @@ -56,8 +56,8 @@ cat >"$output" <<END
>>  $progname $bs- a $source program
>>  .SH DESCRIPTION
>>  .B OOOPS!
>> -Due to lack of perl on your system, the $source build system
>> -failed to create the manual page for
>> +Due to the lack of perl on the build system, we were
>> +unable to create a proper manual page for
>>  .B $progname.
>>  For concise option descriptions, run
>>  .IP
> 
> Looks good, thanks.
> 
Fine by me as well.

Thanks,
  Stefano



From MAILER-DAEMON Fri Oct 26 04:34:38 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRfNG-0006KS-QQ
	for mharc-coreutils@gnu.org; Fri, 26 Oct 2012 04:34:38 -0400
Received: from eggs.gnu.org ([208.118.235.92]:42619)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRfNE-0006Jv-PF
	for coreutils@gnu.org; Fri, 26 Oct 2012 04:34:37 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRfNA-0007zR-Lb
	for coreutils@gnu.org; Fri, 26 Oct 2012 04:34:36 -0400
Received: from mx.meyering.net ([88.168.87.75]:33078)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRfNA-0007zK-Di
	for coreutils@gnu.org; Fri, 26 Oct 2012 04:34:32 -0400
Received: from rho (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 51B5D601AC;
	Fri, 26 Oct 2012 10:34:31 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: Re: factor tests: ugly long file names
In-Reply-To: <5089C756.7050205@bernhard-voelker.de> (Bernhard Voelker's
	message of "Fri, 26 Oct 2012 01:12:22 +0200")
References: <5089C756.7050205@bernhard-voelker.de>
Date: Fri, 26 Oct 2012 10:34:31 +0200
Message-ID: <87mwz94oo8.fsf@meyering.net>
Lines: 69
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Oct 2012 08:34:38 -0000

Bernhard Voelker wrote:
> I was just wondering if we shouldn't refactor the new factor tests.
>
> They have ugly and long file names (the test data), and have identical content
> (which is redundancy which in turn should be avoided IMO):
>
> $ md5sum *.sh
> 31c3a9e8b5dad969dafd07c348c48233
> 0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0.sh

As you've seen, the factorization, ahem, is already done, in a sense.
Those test cases are recorded in factored form in tests/local.mk.
No line there is longer than 80.

While there are many of these long-named factor tests, the only file
saved in version control is run.sh, and those long-named files are
merely temporaries that are hard-linked to run.sh.

However, as you've seen, the resulting (expanded) file names
are very long.  We could easily shave off a few bytes by
recording "START-N" rather than "START-END" pairs.

-  $(tf)/$(p)08551616-$(p)08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh \
+  $(tf)/$(p)08551616-99999-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh \

-  $(tf)/$(t1)-$(t1)-4622287c5f040cdb7b3bbe4d19d29a71ab277827.sh \
+  $(tf)/$(t1)-0-e5826a8ddfe2c1281e5dadd90a874eda.sh \


With this matching change:

diff --git a/tests/factor/run.sh b/tests/factor/run.sh
index 6ff24c3..d63f733 100755
--- a/tests/factor/run.sh
+++ b/tests/factor/run.sh
@@ -3,8 +3,8 @@
 # Expect to be invoked via a file whose basename matches
 # /^(\d+)\-(\d+)\-([\da-f]{40})\.sh$/
 # The test is to run this command
-# seq $1 $2 | factor | shasum -c --status <(echo $3  -)
-# I.e., to ensure that the factorizations of integers $1..$2
+# seq $1 $(expr $1 + $2) | factor | shasum -c --status <(echo $3  -)
+# I.e., to ensure that the factorizations of integers $1..$1+$2
 # match what we expect.

 # Copyright (C) 2012 Free Software Foundation, Inc.
@@ -25,6 +25,7 @@ set $t
 echo "$3  -" > exp

 f=1
-seq $1 $2 | factor | shasum -c --status exp && f=0
+end=$(expr $1 + $2)
+seq $1 $end | factor | shasum -c --status exp && f=0

 Exit $f

If "make check" output line length were really important
--------------------------------

A simple additional change would be to use md5sum in place of sha1sum.
We don't need the added strength/length of sha1sum for this.

You could save more by encoding the checksum in base64 rather than hex,
but with that, the mechanics may get involved, so I wouldn't bother.

Another simple change: use only 8 or 10 hex digits instead
of the full checksum.

You're welcome to pursue it.


From MAILER-DAEMON Fri Oct 26 05:43:11 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRgRb-0005gv-1j
	for mharc-coreutils@gnu.org; Fri, 26 Oct 2012 05:43:11 -0400
Received: from eggs.gnu.org ([208.118.235.92]:54303)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TRgRT-0005fR-LH
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:43:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TRgRN-0003U6-TZ
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:43:03 -0400
Received: from mx1.redhat.com ([209.132.183.28]:50921)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TRgRN-0003Ty-LQ
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:42:57 -0400
Received: from int-mx01.intmail.prod.int.phx2.redhat.com
	(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9Q9gmPH009172
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Fri, 26 Oct 2012 05:42:49 -0400
Received: from [10.36.116.73] (ovpn-116-73.ams2.redhat.com [10.36.116.73])
	by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9Q9giCf006743
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Fri, 26 Oct 2012 05:42:46 -0400
Message-ID: <508A5B13.2090909@draigBrady.com>
Date: Fri, 26 Oct 2012 10:42:43 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: bug#12715: [PATCH] build: do not require help2man at
	build-from-tarball time
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com>
	<87txtkl07c.fsf@rho.meyering.net> <5087B58E.2040401@gmail.com>
	<5087C511.4050907@gmail.com> <5087C706.3050205@gmail.com>
	<87a9vahduv.fsf@rho.meyering.net>
	<50894701.2030700@bernhard-voelker.de>
	<874nlihcf4.fsf@rho.meyering.net>
	<50894BE6.7070506@bernhard-voelker.de>
	<508A4057.2030800@gmail.com> <87haph4lw4.fsf@meyering.net>
In-Reply-To: <87haph4lw4.fsf@meyering.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9Q9gmPH009172
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: Bernhard Voelker <mail@bernhard-voelker.de>,
	Stefano Lattarini <stefano.lattarini@gmail.com>,
	coreutils@gnu.org, 12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Oct 2012 09:43:09 -0000

On 10/26/2012 10:34 AM, Jim Meyering wrote:
> +** Build-related
> +
> +  The generated man/*.1 man pages are no longer distributed.  Building
> +  without perl, you would create stub man pages, and besides would be
> +  unable to run a significant percentage of the tests (so don't do tha=
t!).
> +  Thus, while perl is not an official prerequisite (build and "make ch=
eck"
> +  will still succeed), any resulting man pages would be inferior.

We should probably mention that this fixes a parallel build failure
when building modified sources, like a patched distro package for example.

thanks,
P=E1draig.


From MAILER-DAEMON Fri Oct 26 05:50:39 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRgYp-0007nY-NA
	for mharc-coreutils@gnu.org; Fri, 26 Oct 2012 05:50:39 -0400
Received: from eggs.gnu.org ([208.118.235.92]:53192)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRgYn-0007mv-Kq
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:50:38 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRgYm-0007vy-K4
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:50:37 -0400
Received: from mx.meyering.net ([88.168.87.75]:33181)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRgYm-0007vt-Cv
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:50:36 -0400
Received: from rho (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 767A16012B;
	Fri, 26 Oct 2012 11:50:35 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: =?iso-8859-1?Q?P=E1draig?= Brady <P@draigBrady.com>
Subject: Re: bug#12715: [PATCH] build: do not require help2man at
	build-from-tarball time
In-Reply-To: <508A5B13.2090909@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?=
	=?iso-8859-1?Q?g?= Brady"'s message of
	"Fri, 26 Oct 2012 10:42:43 +0100")
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com> <87txtkl07c.fsf@rho.meyering.net>
	<5087B58E.2040401@gmail.com> <5087C511.4050907@gmail.com>
	<5087C706.3050205@gmail.com> <87a9vahduv.fsf@rho.meyering.net>
	<50894701.2030700@bernhard-voelker.de>
	<874nlihcf4.fsf@rho.meyering.net>
	<50894BE6.7070506@bernhard-voelker.de> <508A4057.2030800@gmail.com>
	<87haph4lw4.fsf@meyering.net> <508A5B13.2090909@draigBrady.com>
Date: Fri, 26 Oct 2012 11:50:35 +0200
Message-ID: <87625x4l5g.fsf@meyering.net>
Lines: 32
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Bernhard Voelker <mail@bernhard-voelker.de>,
	Stefano Lattarini <stefano.lattarini@gmail.com>,
	coreutils@gnu.org, 12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Oct 2012 09:50:38 -0000

P=E1draig Brady wrote:

> On 10/26/2012 10:34 AM, Jim Meyering wrote:
>> +** Build-related
>> +
>> +  The generated man/*.1 man pages are no longer distributed.  Building
>> +  without perl, you would create stub man pages, and besides would be
>> +  unable to run a significant percentage of the tests (so don't do that=
!).
>> +  Thus, while perl is not an official prerequisite (build and "make che=
ck"
>> +  will still succeed), any resulting man pages would be inferior.
>
> We should probably mention that this fixes a parallel build failure
> when building modified sources, like a patched distro package for example.

Yes.  Good point.
How about this?

I was tempted to note it in the "Bug fixes" section,
but figures this would be enough.

** Build-related

  Perl is now more of a prerequisite.  It has long been required in order
  to run (not skip) a significant percentage of the tests.  Now, it is
  also required in order to generate proper man pages, via help2man. The
  generated man/*.1 man pages are no longer distributed.  Building without
  perl, you would create stub man pages.  Thus, while perl is not an
  official prerequisite (build and "make check" will still succeed), any
  resulting man pages would be inferior.  In addition, this fixes a bug
  in distributed (not from clone) Makefile.in that could cause parallel
  build failure when building from modified sources, as is common practice
  for a patched distribution package.


From MAILER-DAEMON Fri Oct 26 05:56:56 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRgeu-0001lG-9x
	for mharc-coreutils@gnu.org; Fri, 26 Oct 2012 05:56:56 -0400
Received: from eggs.gnu.org ([208.118.235.92]:48445)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TRgem-0001ki-Up
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:56:54 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TRgel-0001TU-Tf
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:56:48 -0400
Received: from mx1.redhat.com ([209.132.183.28]:45150)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TRgel-0001TB-Ke
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:56:47 -0400
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9Q9ukCY013840
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Fri, 26 Oct 2012 05:56:46 -0400
Received: from [10.36.116.73] (ovpn-116-73.ams2.redhat.com [10.36.116.73])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id q9Q9uicN010649
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Fri, 26 Oct 2012 05:56:45 -0400
Message-ID: <508A5E5C.8060705@draigBrady.com>
Date: Fri, 26 Oct 2012 10:56:44 +0100
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: bug#12715: [PATCH] build: do not require help2man at
	build-from-tarball time
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com>
	<87txtkl07c.fsf@rho.meyering.net> <5087B58E.2040401@gmail.com>
	<5087C511.4050907@gmail.com> <5087C706.3050205@gmail.com>
	<87a9vahduv.fsf@rho.meyering.net>
	<50894701.2030700@bernhard-voelker.de>
	<874nlihcf4.fsf@rho.meyering.net>
	<50894BE6.7070506@bernhard-voelker.de>
	<508A4057.2030800@gmail.com> <87haph4lw4.fsf@meyering.net>
	<508A5B13.2090909@draigBrady.com> <87625x4l5g.fsf@meyering.net>
In-Reply-To: <87625x4l5g.fsf@meyering.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	q9Q9ukCY013840
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Oct 2012 09:56:54 -0000

On 10/26/2012 10:50 AM, Jim Meyering wrote:
> P=E1draig Brady wrote:
>
>> On 10/26/2012 10:34 AM, Jim Meyering wrote:
>>> +** Build-related
>>> +
>>> +  The generated man/*.1 man pages are no longer distributed.  Buildi=
ng
>>> +  without perl, you would create stub man pages, and besides would b=
e
>>> +  unable to run a significant percentage of the tests (so don't do t=
hat!).
>>> +  Thus, while perl is not an official prerequisite (build and "make =
check"
>>> +  will still succeed), any resulting man pages would be inferior.
>>
>> We should probably mention that this fixes a parallel build failure
>> when building modified sources, like a patched distro package for exam=
ple.
>
> Yes.  Good point.
> How about this?
>
> I was tempted to note it in the "Bug fixes" section,
> but figures this would be enough.
>
> ** Build-related
>
>    Perl is now more of a prerequisite.  It has long been required in or=
der
>    to run (not skip) a significant percentage of the tests.  Now, it is
>    also required in order to generate proper man pages, via help2man. T=
he
>    generated man/*.1 man pages are no longer distributed.  Building wit=
hout
>    perl, you would create stub man pages.  Thus, while perl is not an
>    official prerequisite (build and "make check" will still succeed), a=
ny
>    resulting man pages would be inferior.  In addition, this fixes a bu=
g
>    in distributed (not from clone) Makefile.in that could cause paralle=
l
>    build failure when building from modified sources, as is common prac=
tice
>    for a patched distribution package.

+1


From MAILER-DAEMON Fri Oct 26 05:58:16 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRgJO-0003dO-Nf
	for mharc-coreutils@gnu.org; Fri, 26 Oct 2012 05:34:42 -0400
Received: from eggs.gnu.org ([208.118.235.92]:53072)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRgJK-0003Sb-HM
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:34:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRgJI-0000ur-Nm
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:34:38 -0400
Received: from mx.meyering.net ([88.168.87.75]:33152)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TRgJI-0000un-C8
	for coreutils@gnu.org; Fri, 26 Oct 2012 05:34:36 -0400
Received: from rho (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 9196E60096;
	Fri, 26 Oct 2012 11:34:35 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Stefano Lattarini <stefano.lattarini@gmail.com>
Subject: Re: bug#12715: [PATCH] build: do not require help2man at
	build-from-tarball time
In-Reply-To: <508A4057.2030800@gmail.com> (Stefano Lattarini's message of
	"Fri, 26 Oct 2012 09:48:39 +0200")
References: <87ipbmnx4f.fsf@rho.meyering.net> <504DC2D4.7080509@gmail.com>
	<87vcfmm9z4.fsf@rho.meyering.net>
	<201209151946.42381.vapier@gentoo.org>
	<874nmytix4.fsf@rho.meyering.net> <87zk3cl2vu.fsf@rho.meyering.net>
	<5087A7BA.4070405@draigBrady.com> <87txtkl07c.fsf@rho.meyering.net>
	<5087B58E.2040401@gmail.com> <5087C511.4050907@gmail.com>
	<5087C706.3050205@gmail.com> <87a9vahduv.fsf@rho.meyering.net>
	<50894701.2030700@bernhard-voelker.de>
	<874nlihcf4.fsf@rho.meyering.net>
	<50894BE6.7070506@bernhard-voelker.de> <508A4057.2030800@gmail.com>
Date: Fri, 26 Oct 2012 11:34:35 +0200
Message-ID: <87haph4lw4.fsf@meyering.net>
Lines: 121
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Bernhard Voelker <mail@bernhard-voelker.de>, coreutils@gnu.org,
	12715@debbugs.gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Oct 2012 09:34:40 -0000

Stefano Lattarini wrote:
> On 10/25/2012 04:25 PM, Bernhard Voelker wrote:
>> On 10/25/2012 04:08 PM, Jim Meyering wrote:
>>> Bernhard Voelker wrote:
>>>> Isn't it "Due to lack on the build system, ..."?
>>>>
>>>> I.e. coreutils could be built on system A lacking perl,
>>>> and then be installed on system B which has perl. The above
>>>> text would be misleading in this case.
>>>
>>> Good point.
>>> I've merged this in:
>>>
>>> diff --git a/man/dummy-man b/man/dummy-man
>>> index 633a5ba..3069376 100755
>>> --- a/man/dummy-man
>>> +++ b/man/dummy-man
>>> @@ -56,8 +56,8 @@ cat >"$output" <<END
>>>  $progname $bs- a $source program
>>>  .SH DESCRIPTION
>>>  .B OOOPS!
>>> -Due to lack of perl on your system, the $source build system
>>> -failed to create the manual page for
>>> +Due to the lack of perl on the build system, we were
>>> +unable to create a proper manual page for
>>>  .B $progname.
>>>  For concise option descriptions, run
>>>  .IP
>>
>> Looks good, thanks.
>>
> Fine by me as well.

This is definitely NEWS-worthy and I nearly forgot to add a NEWS entry.
Here's the adjusted log and NEWS diffs:

commit 2eeec4ebbdda9ed89263c815a4087675043b556a
Author: Stefano Lattarini <stefano.lattarini@gmail.com>
Date:   Tue Sep 11 20:54:30 2012 +0200

    build: man page generation: degrade gracefully when perl is lacking

    Since commit v8.19-118-g57da212, our 'dist-hook' rule tweaked the
    distributed Makefile.in to make each man page 'man/foo.1' depend
    on the corresponding source 'src/foo.c' rather than the corresponding
    program 'src/foo'.  That was done to accommodate systems without
    perl, which cannot run help2man to regenerate the manpage after
    its corresponding program has been built.

    This seems a right and proper graceful degradation, in that the
    man pages dependencies are still 100% correct in a git checkout,
    while being more lax but "more portable" in a distribution tarball.
    Alas, that is not the case in practice, as it turns out the tweaked
    Makefile makes the building of man pages unreliable and potentially
    incorrect!

    In fact, assume that instead of the correct a dependency:

        man/ls.1: src/ls

    we have the laxer one:

        man/ls.1: src/ls.c

    and think of what happens if a user modifies, say, 'src/ls.c', and then
    runs "make -j4" to rebuild everything.  The make process will see that
    it has to rebuild the man page 'man/ls.1' (because its prerequisite
    'src/ls.c' has changed), but won't see that it has to rebuild 'src/ls'
    *before* re-running 'help2man' to generate that man page; so, if
    'man/ls.1' is rebuilt before 'src/ls' (which can happen with concurrent
    make), our user will get either a build error (if 'src/ls' did non
    exist) or, worse, a man page with an up-to-date timestamp but an
    out-of-date content.  And what's even worse in all of this is that
    this problem will be present also for users who have perl installed:
    this is not a "graceful degradation" at all!

    In our situation, the best and simplest way to implement a graceful
    degradation it to keep the correct dependencies for man pages (that
    is, "man/ls.1: src/ls"), and if perl is not present, just generate
    dummy man pages reporting that built-time issue and redirecting the
    user back to either the info documentation or the '--help' output.

    As a consequence of this change, we also stop distributing man pages,
    since they will now be generated unconditionally.

    * Makefile.am (do-not-require-help2man): Remove.
    (dist-hook): Don't depend on it.
    * man/local.mk: Remove an obsolete comment.
    (EXTRA_DIST): Stop distributing generated man pages.
    ($(EXTRA_MANS)): This no longer needs to depend on $(all_programs).
    (MAINTAINERCLEANFILES): $(ALL_MANS) Do not list it here, and ...
    (CLEANFILES): ... list it here, instead.
    (.x.1): Instead of warning if perl is missing, but then trying to run
    'help2man' unconditionally, simply run ...
    (run_help2man): ... the command referenced by this new variable, that
    expands to a proper invocation of 'help2man' if perl is present, and
    to an invocation of a shell script generating a dummy manpage if it
    is not.
    (EXTRA_DIST): Distribute that shell script.
    * man/dummy-man: New shell script.
    * NEWS (Build-related): Mention this.
    Fixes coreutils http://bugs.gnu.org/12715.

diff --git a/NEWS b/NEWS
index e13ba22..2d32ca5 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,14 @@ GNU coreutils NEWS                                    -*- outline -*-
   consistently padded with spaces, rather than with zeros for certain widths.
   [bug introduced in TEXTUTILS-1_22i]

+** Build-related
+
+  The generated man/*.1 man pages are no longer distributed.  Building
+  without perl, you would create stub man pages, and besides would be
+  unable to run a significant percentage of the tests (so don't do that!).
+  Thus, while perl is not an official prerequisite (build and "make check"
+  will still succeed), any resulting man pages would be inferior.
+

 * Noteworthy changes in release 8.20 (2012-10-23) [stable]


From MAILER-DAEMON Fri Oct 26 12:45:34 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRn2M-0006kw-PB
	for mharc-coreutils@gnu.org; Fri, 26 Oct 2012 12:45:34 -0400
Received: from eggs.gnu.org ([208.118.235.92]:34575)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRn2J-0006id-6a
	for coreutils@gnu.org; Fri, 26 Oct 2012 12:45:33 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRn2G-0003of-Va
	for coreutils@gnu.org; Fri, 26 Oct 2012 12:45:31 -0400
Received: from moutng.kundenserver.de ([212.227.17.9]:51013)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRn2G-0003n6-Id
	for coreutils@gnu.org; Fri, 26 Oct 2012 12:45:28 -0400
Received: from [192.168.2.108] (p4FF7651F.dip.t-dialin.net [79.247.101.31])
	by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis)
	id 0LyQ8Q-1TNoXk3t94-015KWb; Fri, 26 Oct 2012 18:45:15 +0200
Message-ID: <508ABE1A.8070107@bernhard-voelker.de>
Date: Fri, 26 Oct 2012 18:45:14 +0200
From: Bernhard Voelker <mail@bernhard-voelker.de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: factor tests: ugly long file names
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net>
In-Reply-To: <87mwz94oo8.fsf@meyering.net>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Provags-ID: V02:K0:fEh2n3AzEHSgXTOMjdgIVvyH+pHa748/wQhkqoOw86f
	oOOm30Xg6Ip39+1IBiSWxpoRkja/3ZvC1z67nmCUnizgiYSc3M
	iqU8SxxoctGUCqUCCIcZX+X/NbIj3aK7zNJ8SBfeOYtITDu4LK
	3iDsOWkge52tv7X5sRND+mEF9MWnvW2i82Ck4SyT/JJ3ZtloAD
	fLasEm5RL7lPVuloD8nAkdnIEOBkOdAMdUPmE+iw7cEUmMDCA8
	TtXRGgx9CfrRNj74NJ9UB5t6u6CnQxMl3kC1F0dSqXrpeY+YwW
	3jSn4arlfK70YXD7XS0RVB+TvY74qJSP6GQATd2+4l+K/WD2zf
	S5CTaNCZR1R/NDPlqD2Qc//EhKPT06oWGucte442s
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 212.227.17.9
Cc: Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Oct 2012 16:45:33 -0000

On 10/26/2012 10:34 AM, Jim Meyering wrote:
> Bernhard Voelker wrote:
>> I was just wondering if we shouldn't refactor the new factor tests.
>>
>> They have ugly and long file names (the test data), and have identical content
>> (which is redundancy which in turn should be avoided IMO):
>>
>> $ md5sum *.sh
>> 31c3a9e8b5dad969dafd07c348c48233
>> 0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0.sh
> 
> As you've seen, the factorization, ahem, is already done, in a sense.
> Those test cases are recorded in factored form in tests/local.mk.
> No line there is longer than 80.
> 
> While there are many of these long-named factor tests, the only file
> saved in version control is run.sh, and those long-named files are
> merely temporaries that are hard-linked to run.sh.

yes, I've seen that (on the second glance).

> However, as you've seen, the resulting (expanded) file names
> are very long.  We could easily shave off a few bytes by
> recording "START-N" rather than "START-END" pairs.
> 
> -  $(tf)/$(p)08551616-$(p)08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh \
> +  $(tf)/$(p)08551616-99999-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh \
> 
> -  $(tf)/$(t1)-$(t1)-4622287c5f040cdb7b3bbe4d19d29a71ab277827.sh \
> +  $(tf)/$(t1)-0-e5826a8ddfe2c1281e5dadd90a874eda.sh \
> 
> 
> With this matching change:
> 
> diff --git a/tests/factor/run.sh b/tests/factor/run.sh
> index 6ff24c3..d63f733 100755
> --- a/tests/factor/run.sh
> +++ b/tests/factor/run.sh
> @@ -3,8 +3,8 @@
>  # Expect to be invoked via a file whose basename matches
>  # /^(\d+)\-(\d+)\-([\da-f]{40})\.sh$/
>  # The test is to run this command
> -# seq $1 $2 | factor | shasum -c --status <(echo $3  -)
> -# I.e., to ensure that the factorizations of integers $1..$2
> +# seq $1 $(expr $1 + $2) | factor | shasum -c --status <(echo $3  -)
> +# I.e., to ensure that the factorizations of integers $1..$1+$2
>  # match what we expect.
> 
>  # Copyright (C) 2012 Free Software Foundation, Inc.
> @@ -25,6 +25,7 @@ set $t
>  echo "$3  -" > exp
> 
>  f=1
> -seq $1 $2 | factor | shasum -c --status exp && f=0
> +end=$(expr $1 + $2)
> +seq $1 $end | factor | shasum -c --status exp && f=0
> 
>  Exit $f
> 
> If "make check" output line length were really important
> --------------------------------
> 
> A simple additional change would be to use md5sum in place of sha1sum.
> We don't need the added strength/length of sha1sum for this.
> 
> You could save more by encoding the checksum in base64 rather than hex,
> but with that, the mechanics may get involved, so I wouldn't bother.
> 
> Another simple change: use only 8 or 10 hex digits instead
> of the full checksum.
> 
> You're welcome to pursue it.

As the tests are created by tests/local.mk, I rather thought of going
away from hardlinks, and, instead, use run.sh as a template by exchanging
START, END, and CKSUM variables into factor-{01,02,03,04,...}.sh.
Something like the following.
WDYT?

Not tested very thoroughly, but it seems to work.

Have a nice day,
Berny

>From d85f748f4cad3fadcc699c575891259f5122fddb Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <mail@bernhard-voelker.de>
Date: Fri, 26 Oct 2012 18:40:25 +0200
Subject: [PATCH] maint: refactor new tests for refactored factor

* tests/local.mk (EXTRA_DIST): Add new tests/factor/setup.sh.
(factor_tests): Rename the test names to t{00..36}.sh. Factor out
the test data triples out.
(p,q,t1,t2) Factor out the related magic numbers.
$(factor_tests): Add dependency to new tests/factor/setup.sh.
Call that script to generate the test scripts.
* tests/factor/setup.sh: Add new script to create the test script
from the template tests/factor/run.sh.
Use test data and magic number factored out from above.
* tests/factor/run.sh: Change this script into a real template.
Add template variables START, END and CKSUM, replacing the code
to split the test data from the test script's file name.
Use the new template variables in the call to seq and for
creating the exp file.
---
 tests/factor/run.sh   |   17 ++++-----
 tests/factor/setup.sh |   89 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/local.mk        |   67 +++++++------------------------------
 3 files changed, 108 insertions(+), 65 deletions(-)
 create mode 100755 tests/factor/setup.sh

diff --git a/tests/factor/run.sh b/tests/factor/run.sh
index 6ff24c3..ed865ff 100755
--- a/tests/factor/run.sh
+++ b/tests/factor/run.sh
@@ -1,9 +1,7 @@
 #!/bin/sh
 # Test the factor rewrite.
-# Expect to be invoked via a file whose basename matches
-# /^(\d+)\-(\d+)\-([\da-f]{40})\.sh$/
 # The test is to run this command
-# seq $1 $2 | factor | shasum -c --status <(echo $3  -)
+# seq $START $END | factor | shasum -c --status <(echo $CKSUM  -)
 # I.e., to ensure that the factorizations of integers $1..$2
 # match what we expect.

@@ -16,15 +14,14 @@ very_expensive_

 print_ver_ factor seq

-# Remove the ".sh" suffix:
-t=${ME_%.sh}
+# Template - __{START,END,CKSUM}__ is replaced by local.mk.
+START=__START__
+  END=__END__
+CKSUM=__CKSUM__

-# Make IFS include "-", so that a simple "set" will separate the args:
-IFS=-$IFS
-set $t
-echo "$3  -" > exp
+echo "$CKSUM  -" > exp

 f=1
-seq $1 $2 | factor | shasum -c --status exp && f=0
+seq $START $END | factor | shasum -c --status exp && f=0

 Exit $f
diff --git a/tests/factor/setup.sh b/tests/factor/setup.sh
new file mode 100755
index 0000000..2acb5d3
--- /dev/null
+++ b/tests/factor/setup.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+# Create the factor test scripts
+
+# Extract the test name from $1.
+testname="$1"
+t=$( basename "$testname" )
+t=$( echo "${t%.sh}" )
+
+ftdir=$( dirname "$testname" )
+
+# prefix of 2^64
+p=184467440737
+
+# prefix of 2^96
+q=79228162514264337593543
+
+# Each of these numbers has a Pollard rho factor larger than 2^64,
+# and thus exercises some hard-to-reach code in factor.c.
+t1=170141183460469225450570946617781744489
+t2=170141183460469229545748130981302223887
+
+# Factors of the above:
+# t1: 9223372036854775421 18446744073709551709
+# t2: 9223372036854775643 18446744073709551709
+
+# Each test is a triple: lo, hi, sha1 of result.
+# The test script, run.sh, runs seq lo hi|factor|sha1sum
+# and verifies that the actual and expected checksums are the same.
+# New tests must be added to tests/local.mk (factor_tests), too.
+case ".$t" in
+  .t00) d=0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;
+  .t01) d=10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016 ;;
+  .t02) d=20000000-30000000-8115e8dff97d1674134ec054598d939a2a5f6113 ;;
+  .t03) d=30000000-40000000-fe7b832c8e0ed55035152c0f9ebd59de73224a60 ;;
+  .t04) d=40000000-50000000-b8786d66c432e48bc5b342ee3c6752b7f096f206 ;;
+  .t05) d=50000000-60000000-a74fe518c5f79873c2b9016745b88b42c8fd3ede ;;
+  .t06) d=60000000-70000000-689bc70d681791e5d1b8ac1316a05d0c4473d6db ;;
+  .t07) d=70000000-80000000-d370808f2ab8c865f64c2ff909c5722db5b7d58d ;;
+  .t08) d=80000000-90000000-7978aa66bf2bdb446398336ea6f02605e9a77581 ;;
+  .t09) d=${t1}-${t1}-4622287c5f040cdb7b3bbe4d19d29a71ab277827 ;;
+  .t10) d=${t2}-${t2}-dea308253708b57afad357e8c0d2a111460ef50e ;;
+  .t11) d=${p}08551616-${p}08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1 ;;
+  .t12) d=${p}08651616-${p}08751615-729228e693b1a568ecc85b199927424c7d16d410 ;;
+  .t13) d=${p}08751616-${p}08851615-5a0c985017c2d285e4698f836f5a059e0b684563 ;;
+  .t14) d=${p}08851616-${p}08951615-0482295c514e371c98ce9fd335deed0c9c44a4f4 ;;
+  .t15) d=${p}08951616-${p}09051615-9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71 ;;
+  .t16) d=${p}09051616-${p}09151615-604366d2b1d75371d0679e6a68962d66336cd383 ;;
+  .t17) d=${p}09151616-${p}09251615-9192d2bdee930135b28d7160e6d395a7027871da ;;
+  .t18) d=${p}09251616-${p}09351615-bcf56ae55d20d700690cff4d3327b78f83fc01bf ;;
+  .t19) d=${p}09351616-${p}09451615-16b106398749e5f24d278ba7c58229ae43f650ac ;;
+  .t20) d=${p}09451616-${p}09551615-ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c ;;
+  .t21) d=${p}09551616-${p}09651615-2b6f9c11742d9de045515a6627c27a042c49f8ba ;;
+  .t22) d=${p}09651616-${p}09751615-54851acd51c4819beb666e26bc0100dc9adbc310 ;;
+  .t23) d=${p}09751616-${p}09851615-6939c2a7afd2d81f45f818a159b7c5226f83a50b ;;
+  .t24) d=${p}09851616-${p}09951615-0f2c8bc011d2a45e2afa01459391e68873363c6c ;;
+  .t25) d=${p}09951616-${p}10051615-630dc2ad72f4c222bad1405e6c5bea590f92a98c ;;
+  .t26) d=${q}940336-${q}942335-63cbd6313d78247b04d63bbbac50cb8f8d33ff71 ;;
+  .t27) d=${q}942336-${q}944335-0d03d63653767173182491b86fa18f8f680bb036 ;;
+  .t28) d=${q}944336-${q}946335-ca43bd38cd9f97cc5bb63613cb19643578640f0b ;;
+  .t29) d=${q}946336-${q}948335-86d59545a0c13567fa96811821ea5cde950611b1 ;;
+  .t30) d=${q}948336-${q}950335-c3740e702fa9c97e6cf00150860e0b936a141a6b ;;
+  .t31) d=${q}950336-${q}952335-551c3c4c4640d86fda311b5c3006dac45505c0ce ;;
+  .t32) d=${q}952336-${q}954335-b1b0b00463c2f853d70ef9c4f7a96de5cb614156 ;;
+  .t33) d=${q}954336-${q}956335-8938a484a9ef6bb16478091d294fcde9f8ecea69 ;;
+  .t34) d=${q}956336-${q}958335-d1ae6bc712d994f35edf55c785d71ddf31f16535 ;;
+  .t35) d=${q}958336-${q}960335-2374919a89196e1fce93adfe779cb4664556d4b6 ;;
+  .t36) d=${q}960336-${q}962335-569e4363e8d9e8830a187d9ab27365eef08abde1 ;;
+  *)
+    echo "$0: error: unknown test: $t" >&2
+    exit 1
+    ;;
+esac
+
+# Make IFS include "-", so that a simple "set" will separate the args:
+IFS=-$IFS
+set $d
+
+# Create the test script from the template for this test
+# by substituting the START, the END and the CKSUM.
+sed \
+  -e "s/__START__/$1/" \
+  -e "s/__END__/$2/" \
+  -e "s/__CKSUM__/$3/" \
+  < "${ftdir}/run.sh" > "$testname" \
+  && chmod a+x "$testname" \
+  || exit 1
+
+test -x "$testname"
+exit $?
\ No newline at end of file
diff --git a/tests/local.mk b/tests/local.mk
index f31c8b0..7ca95c1 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -96,6 +96,7 @@ EXTRA_DIST +=			\
   tests/d_type-check		\
   tests/envvar-check		\
   tests/factor/run.sh		\
+  tests/factor/setup.sh		\
   tests/filefrag-extent-compare \
   tests/fiemap-capable		\
   tests/init.sh			\
@@ -625,65 +626,21 @@ all_tests =					\
   tests/touch/trailing-slash.sh			\
   $(all_root_tests)

-# prefix of 2^64
-p = 184467440737
-# prefix of 2^96
-q = 79228162514264337593543
-
-# Each of these numbers has a Pollard rho factor larger than 2^64,
-# and thus exercises some hard-to-reach code in factor.c.
-t1 = 170141183460469225450570946617781744489
-t2 = 170141183460469229545748130981302223887
-# Factors of the above:
-# t1: 9223372036854775421 18446744073709551709
-# t2: 9223372036854775643 18446744073709551709
-
-# Each tests is a triple: lo, hi, sha1 of result.
-# The test script, run.sh, runs seq lo hi|factor|sha1sum
-# and verifies that the actual and expected checksums are the same.
+# See tests/factor/setup.sh.
 tf = tests/factor
 factor_tests = \
-  $(tf)/0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0.sh \
-  $(tf)/10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016.sh \
-  $(tf)/20000000-30000000-8115e8dff97d1674134ec054598d939a2a5f6113.sh \
-  $(tf)/30000000-40000000-fe7b832c8e0ed55035152c0f9ebd59de73224a60.sh \
-  $(tf)/40000000-50000000-b8786d66c432e48bc5b342ee3c6752b7f096f206.sh \
-  $(tf)/50000000-60000000-a74fe518c5f79873c2b9016745b88b42c8fd3ede.sh \
-  $(tf)/60000000-70000000-689bc70d681791e5d1b8ac1316a05d0c4473d6db.sh \
-  $(tf)/70000000-80000000-d370808f2ab8c865f64c2ff909c5722db5b7d58d.sh \
-  $(tf)/80000000-90000000-7978aa66bf2bdb446398336ea6f02605e9a77581.sh \
-  $(tf)/$(t1)-$(t1)-4622287c5f040cdb7b3bbe4d19d29a71ab277827.sh \
-  $(tf)/$(t2)-$(t2)-dea308253708b57afad357e8c0d2a111460ef50e.sh \
-  $(tf)/$(p)08551616-$(p)08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh \
-  $(tf)/$(p)08651616-$(p)08751615-729228e693b1a568ecc85b199927424c7d16d410.sh \
-  $(tf)/$(p)08751616-$(p)08851615-5a0c985017c2d285e4698f836f5a059e0b684563.sh \
-  $(tf)/$(p)08851616-$(p)08951615-0482295c514e371c98ce9fd335deed0c9c44a4f4.sh \
-  $(tf)/$(p)08951616-$(p)09051615-9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71.sh \
-  $(tf)/$(p)09051616-$(p)09151615-604366d2b1d75371d0679e6a68962d66336cd383.sh \
-  $(tf)/$(p)09151616-$(p)09251615-9192d2bdee930135b28d7160e6d395a7027871da.sh \
-  $(tf)/$(p)09251616-$(p)09351615-bcf56ae55d20d700690cff4d3327b78f83fc01bf.sh \
-  $(tf)/$(p)09351616-$(p)09451615-16b106398749e5f24d278ba7c58229ae43f650ac.sh \
-  $(tf)/$(p)09451616-$(p)09551615-ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c.sh \
-  $(tf)/$(p)09551616-$(p)09651615-2b6f9c11742d9de045515a6627c27a042c49f8ba.sh \
-  $(tf)/$(p)09651616-$(p)09751615-54851acd51c4819beb666e26bc0100dc9adbc310.sh \
-  $(tf)/$(p)09751616-$(p)09851615-6939c2a7afd2d81f45f818a159b7c5226f83a50b.sh \
-  $(tf)/$(p)09851616-$(p)09951615-0f2c8bc011d2a45e2afa01459391e68873363c6c.sh \
-  $(tf)/$(p)09951616-$(p)10051615-630dc2ad72f4c222bad1405e6c5bea590f92a98c.sh \
-  $(tf)/$(q)940336-$(q)942335-63cbd6313d78247b04d63bbbac50cb8f8d33ff71.sh \
-  $(tf)/$(q)942336-$(q)944335-0d03d63653767173182491b86fa18f8f680bb036.sh \
-  $(tf)/$(q)944336-$(q)946335-ca43bd38cd9f97cc5bb63613cb19643578640f0b.sh \
-  $(tf)/$(q)946336-$(q)948335-86d59545a0c13567fa96811821ea5cde950611b1.sh \
-  $(tf)/$(q)948336-$(q)950335-c3740e702fa9c97e6cf00150860e0b936a141a6b.sh \
-  $(tf)/$(q)950336-$(q)952335-551c3c4c4640d86fda311b5c3006dac45505c0ce.sh \
-  $(tf)/$(q)952336-$(q)954335-b1b0b00463c2f853d70ef9c4f7a96de5cb614156.sh \
-  $(tf)/$(q)954336-$(q)956335-8938a484a9ef6bb16478091d294fcde9f8ecea69.sh \
-  $(tf)/$(q)956336-$(q)958335-d1ae6bc712d994f35edf55c785d71ddf31f16535.sh \
-  $(tf)/$(q)958336-$(q)960335-2374919a89196e1fce93adfe779cb4664556d4b6.sh \
-  $(tf)/$(q)960336-$(q)962335-569e4363e8d9e8830a187d9ab27365eef08abde1.sh
+  $(tf)/t00.sh $(tf)/t01.sh $(tf)/t02.sh $(tf)/t03.sh $(tf)/t04.sh \
+  $(tf)/t05.sh $(tf)/t06.sh $(tf)/t07.sh $(tf)/t08.sh $(tf)/t09.sh \
+  $(tf)/t10.sh $(tf)/t11.sh $(tf)/t12.sh $(tf)/t13.sh $(tf)/t14.sh \
+  $(tf)/t15.sh $(tf)/t16.sh $(tf)/t17.sh $(tf)/t18.sh $(tf)/t19.sh \
+  $(tf)/t20.sh $(tf)/t21.sh $(tf)/t22.sh $(tf)/t23.sh $(tf)/t24.sh \
+  $(tf)/t25.sh $(tf)/t26.sh $(tf)/t27.sh $(tf)/t28.sh $(tf)/t29.sh \
+  $(tf)/t30.sh $(tf)/t31.sh $(tf)/t32.sh $(tf)/t33.sh $(tf)/t34.sh \
+  $(tf)/t35.sh $(tf)/t36.sh

-$(factor_tests): tests/factor/run.sh
+$(factor_tests): tests/factor/run.sh tests/factor/setup.sh
 	$(AM_V_GEN)$(MKDIR_P) $(tf)
-	$(AM_V_at)ln -f $(srcdir)/tests/factor/run.sh $@
+	$(AM_V_at)$(srcdir)/tests/factor/setup.sh $@

 CLEANFILES += $(factor_tests)

-- 
1.7.7






From MAILER-DAEMON Fri Oct 26 13:55:24 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRo7w-0003yj-A5
	for mharc-coreutils@gnu.org; Fri, 26 Oct 2012 13:55:24 -0400
Received: from eggs.gnu.org ([208.118.235.92]:33018)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TRo7s-0003xI-7q
	for coreutils@gnu.org; Fri, 26 Oct 2012 13:55:22 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TRo7p-00070Y-IE
	for coreutils@gnu.org; Fri, 26 Oct 2012 13:55:20 -0400
Received: from mail-ea0-f169.google.com ([209.85.215.169]:49352)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TRo7p-0006y7-5T
	for coreutils@gnu.org; Fri, 26 Oct 2012 13:55:17 -0400
Received: by mail-ea0-f169.google.com with SMTP id k11so1112065eaa.0
	for <coreutils@gnu.org>; Fri, 26 Oct 2012 10:55:16 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=message-id:date:from:mime-version:to:cc:subject:references
	:in-reply-to:content-type:content-transfer-encoding;
	bh=I/WvWhB/FRB5Stz6P58Xkmai639+YsvK5kiQoSsKUxE=;
	b=WbOs/4noX4S+9Z2fave9Gol7lyrdIlhgesizoJcqP6DkRUfm/cf0RWfpKVHADv7W4R
	p3dBmfQcnqp9JBlv3J7he4zbR0bdZMYv1WtFlZHsHczz6g2grtbz3emcwVgoSPCpSSn/
	rBOLgiQxTWcP+miFbNKePmXF1GAeGa40ClS0RCm+buUqDKBP/jbqxY1xKI2Vu67uC/ey
	bEyrA33YosKQEYMxe0bqzAVrRlkiL598Ok94fmD+jKYwwoJENtl55lPNw9wiGceFWHuH
	0Xs3y4FxoC7QQ+dZisWByUWKiGP2PwbW+czyjxYjBCuybdyNl6U4vuT7gvshn5mP8F5k
	/QBQ==
Received: by 10.14.207.68 with SMTP id m44mr18259743eeo.40.1351274115968;
	Fri, 26 Oct 2012 10:55:15 -0700 (PDT)
Received: from [192.168.178.21]
	(host247-100-dynamic.8-87-r.retail.telecomitalia.it. [87.8.100.247])
	by mx.google.com with ESMTPS id o49sm4052733eep.5.2012.10.26.10.55.14
	(version=SSLv3 cipher=OTHER); Fri, 26 Oct 2012 10:55:15 -0700 (PDT)
Message-ID: <508ACE7E.4080204@gmail.com>
Date: Fri, 26 Oct 2012 19:55:10 +0200
From: Stefano Lattarini <stefano.lattarini@gmail.com>
MIME-Version: 1.0
To: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: Re: factor tests: ugly long file names
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net>
	<508ABE1A.8070107@bernhard-voelker.de>
In-Reply-To: <508ABE1A.8070107@bernhard-voelker.de>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.85.215.169
Cc: Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Oct 2012 17:55:22 -0000

On 10/26/2012 06:45 PM, Bernhard Voelker wrote:
> On 10/26/2012 10:34 AM, Jim Meyering wrote:
>> Bernhard Voelker wrote:
>>> I was just wondering if we shouldn't refactor the new factor tests.
>>>
>>> They have ugly and long file names (the test data), and have identical content
>>> (which is redundancy which in turn should be avoided IMO):
>>>
>>> $ md5sum *.sh
>>> 31c3a9e8b5dad969dafd07c348c48233
>>> 0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0.sh
>>
>> As you've seen, the factorization, ahem, is already done, in a sense.
>> Those test cases are recorded in factored form in tests/local.mk.
>> No line there is longer than 80.
>>
>> While there are many of these long-named factor tests, the only file
>> saved in version control is run.sh, and those long-named files are
>> merely temporaries that are hard-linked to run.sh.
> 
> yes, I've seen that (on the second glance).
> 
>> However, as you've seen, the resulting (expanded) file names
>> are very long.  We could easily shave off a few bytes by
>> recording "START-N" rather than "START-END" pairs.
>>
>> -  $(tf)/$(p)08551616-$(p)08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh \
>> +  $(tf)/$(p)08551616-99999-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh \
>>
>> -  $(tf)/$(t1)-$(t1)-4622287c5f040cdb7b3bbe4d19d29a71ab277827.sh \
>> +  $(tf)/$(t1)-0-e5826a8ddfe2c1281e5dadd90a874eda.sh \
>>
>>
>> With this matching change:
>>
>> diff --git a/tests/factor/run.sh b/tests/factor/run.sh
>> index 6ff24c3..d63f733 100755
>> --- a/tests/factor/run.sh
>> +++ b/tests/factor/run.sh
>> @@ -3,8 +3,8 @@
>>  # Expect to be invoked via a file whose basename matches
>>  # /^(\d+)\-(\d+)\-([\da-f]{40})\.sh$/
>>  # The test is to run this command
>> -# seq $1 $2 | factor | shasum -c --status <(echo $3  -)
>> -# I.e., to ensure that the factorizations of integers $1..$2
>> +# seq $1 $(expr $1 + $2) | factor | shasum -c --status <(echo $3  -)
>> +# I.e., to ensure that the factorizations of integers $1..$1+$2
>>  # match what we expect.
>>
>>  # Copyright (C) 2012 Free Software Foundation, Inc.
>> @@ -25,6 +25,7 @@ set $t
>>  echo "$3  -" > exp
>>
>>  f=1
>> -seq $1 $2 | factor | shasum -c --status exp && f=0
>> +end=$(expr $1 + $2)
>> +seq $1 $end | factor | shasum -c --status exp && f=0
>>
>>  Exit $f
>>
>> If "make check" output line length were really important
>> --------------------------------
>>
>> A simple additional change would be to use md5sum in place of sha1sum.
>> We don't need the added strength/length of sha1sum for this.
>>
>> You could save more by encoding the checksum in base64 rather than hex,
>> but with that, the mechanics may get involved, so I wouldn't bother.
>>
>> Another simple change: use only 8 or 10 hex digits instead
>> of the full checksum.
>>
>> You're welcome to pursue it.
> 
> As the tests are created by tests/local.mk, I rather thought of going
> away from hardlinks, and, instead, use run.sh as a template by exchanging
> START, END, and CKSUM variables into factor-{01,02,03,04,...}.sh.
> Something like the following.
> WDYT?
> 
> Not tested very thoroughly, but it seems to work.
> 
> Have a nice day,
> Berny
> 
> From d85f748f4cad3fadcc699c575891259f5122fddb Mon Sep 17 00:00:00 2001
> From: Bernhard Voelker <mail@bernhard-voelker.de>
> Date: Fri, 26 Oct 2012 18:40:25 +0200
> Subject: [PATCH] maint: refactor new tests for refactored factor
>
Wow, a tongue-twister summary line :-)

On the serious side, I've some nits below.

> * tests/local.mk (EXTRA_DIST): Add new tests/factor/setup.sh.
> (factor_tests): Rename the test names to t{00..36}.sh. Factor out
> the test data triples out.
> (p,q,t1,t2) Factor out the related magic numbers.
> $(factor_tests): Add dependency to new tests/factor/setup.sh.
> Call that script to generate the test scripts.
> * tests/factor/setup.sh: Add new script to create the test script
> from the template tests/factor/run.sh.
> Use test data and magic number factored out from above.
> * tests/factor/run.sh: Change this script into a real template.
> Add template variables START, END and CKSUM, replacing the code
> to split the test data from the test script's file name.
> Use the new template variables in the call to seq and for
> creating the exp file.
> ---
>  tests/factor/run.sh   |   17 ++++-----
>  tests/factor/setup.sh |   89 +++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/local.mk        |   67 +++++++------------------------------
>  3 files changed, 108 insertions(+), 65 deletions(-)
>  create mode 100755 tests/factor/setup.sh
> 
> diff --git a/tests/factor/run.sh b/tests/factor/run.sh
> index 6ff24c3..ed865ff 100755
> --- a/tests/factor/run.sh
> +++ b/tests/factor/run.sh
> @@ -1,9 +1,7 @@
>  #!/bin/sh
>  # Test the factor rewrite.
> -# Expect to be invoked via a file whose basename matches
> -# /^(\d+)\-(\d+)\-([\da-f]{40})\.sh$/
>  # The test is to run this command
> -# seq $1 $2 | factor | shasum -c --status <(echo $3  -)
> +# seq $START $END | factor | shasum -c --status <(echo $CKSUM  -)
>  # I.e., to ensure that the factorizations of integers $1..$2
>  # match what we expect.
> 
> @@ -16,15 +14,14 @@ very_expensive_
> 
>  print_ver_ factor seq
> 
> -# Remove the ".sh" suffix:
> -t=${ME_%.sh}
> +# Template - __{START,END,CKSUM}__ is replaced by local.mk.
> +START=__START__
> +  END=__END__
> +CKSUM=__CKSUM__
> 
> -# Make IFS include "-", so that a simple "set" will separate the args:
> -IFS=-$IFS
> -set $t
> -echo "$3  -" > exp
> +echo "$CKSUM  -" > exp
> 
>  f=1
> -seq $1 $2 | factor | shasum -c --status exp && f=0
> +seq $START $END | factor | shasum -c --status exp && f=0
> 
>  Exit $f
> diff --git a/tests/factor/setup.sh b/tests/factor/setup.sh
> new file mode 100755
> index 0000000..2acb5d3
> --- /dev/null
> +++ b/tests/factor/setup.sh
>
A better name would be something like factor/create-test.sh IMHO.

> @@ -0,0 +1,89 @@
> +#!/bin/sh
>
Missing copyright notice (not that I'd care, but the FSF seems to
care deeply).

> +# Create the factor test scripts
> +
Missing trailing full-stop.

> +# Extract the test name from $1.
> +testname="$1"
>
Useless quoting, the following is clearer and perfectly portable:

    testname=$1

> +t=$( basename "$testname" )
>
You can save a fork by avoiding a call to basename:

    t=${testname##*/}

> +t=$( echo "${t%.sh}" )
> +
Useless use of echo, just use:

   t=${t%.sh}

> +ftdir=$( dirname "$testname" )
> +
You can similarly save a fork as follows:

    case $testname in
      */*) ftdir=${testname%/*}
        *) ftdir=.;;
    esac

Albeit this slightly complicates the code, so it might not be
worthwhile in the end...

> +# prefix of 2^64
> +p=184467440737
> +
> +# prefix of 2^96
> +q=79228162514264337593543
> +
> +# Each of these numbers has a Pollard rho factor larger than 2^64,
> +# and thus exercises some hard-to-reach code in factor.c.
> +t1=170141183460469225450570946617781744489
> +t2=170141183460469229545748130981302223887
> +
> +# Factors of the above:
> +# t1: 9223372036854775421 18446744073709551709
> +# t2: 9223372036854775643 18446744073709551709
> +
> +# Each test is a triple: lo, hi, sha1 of result.
> +# The test script, run.sh, runs seq lo hi|factor|sha1sum
> +# and verifies that the actual and expected checksums are the same.
> +# New tests must be added to tests/local.mk (factor_tests), too.
> +case ".$t" in
>
Useless quoting, simply using

    case .$t in

would be fine as well.

Also, may I ask why you're using that leading dot?

> +  .t00) d=0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;
> +  .t01) d=10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016 ;;
> +  .t02) d=20000000-30000000-8115e8dff97d1674134ec054598d939a2a5f6113 ;;
> +  .t03) d=30000000-40000000-fe7b832c8e0ed55035152c0f9ebd59de73224a60 ;;
> +  .t04) d=40000000-50000000-b8786d66c432e48bc5b342ee3c6752b7f096f206 ;;
> +  .t05) d=50000000-60000000-a74fe518c5f79873c2b9016745b88b42c8fd3ede ;;
> +  .t06) d=60000000-70000000-689bc70d681791e5d1b8ac1316a05d0c4473d6db ;;
> +  .t07) d=70000000-80000000-d370808f2ab8c865f64c2ff909c5722db5b7d58d ;;
> +  .t08) d=80000000-90000000-7978aa66bf2bdb446398336ea6f02605e9a77581 ;;
> +  .t09) d=${t1}-${t1}-4622287c5f040cdb7b3bbe4d19d29a71ab277827 ;;
> +  .t10) d=${t2}-${t2}-dea308253708b57afad357e8c0d2a111460ef50e ;;
> +  .t11) d=${p}08551616-${p}08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1 ;;
> +  .t12) d=${p}08651616-${p}08751615-729228e693b1a568ecc85b199927424c7d16d410 ;;
> +  .t13) d=${p}08751616-${p}08851615-5a0c985017c2d285e4698f836f5a059e0b684563 ;;
> +  .t14) d=${p}08851616-${p}08951615-0482295c514e371c98ce9fd335deed0c9c44a4f4 ;;
> +  .t15) d=${p}08951616-${p}09051615-9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71 ;;
> +  .t16) d=${p}09051616-${p}09151615-604366d2b1d75371d0679e6a68962d66336cd383 ;;
> +  .t17) d=${p}09151616-${p}09251615-9192d2bdee930135b28d7160e6d395a7027871da ;;
> +  .t18) d=${p}09251616-${p}09351615-bcf56ae55d20d700690cff4d3327b78f83fc01bf ;;
> +  .t19) d=${p}09351616-${p}09451615-16b106398749e5f24d278ba7c58229ae43f650ac ;;
> +  .t20) d=${p}09451616-${p}09551615-ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c ;;
> +  .t21) d=${p}09551616-${p}09651615-2b6f9c11742d9de045515a6627c27a042c49f8ba ;;
> +  .t22) d=${p}09651616-${p}09751615-54851acd51c4819beb666e26bc0100dc9adbc310 ;;
> +  .t23) d=${p}09751616-${p}09851615-6939c2a7afd2d81f45f818a159b7c5226f83a50b ;;
> +  .t24) d=${p}09851616-${p}09951615-0f2c8bc011d2a45e2afa01459391e68873363c6c ;;
> +  .t25) d=${p}09951616-${p}10051615-630dc2ad72f4c222bad1405e6c5bea590f92a98c ;;
> +  .t26) d=${q}940336-${q}942335-63cbd6313d78247b04d63bbbac50cb8f8d33ff71 ;;
> +  .t27) d=${q}942336-${q}944335-0d03d63653767173182491b86fa18f8f680bb036 ;;
> +  .t28) d=${q}944336-${q}946335-ca43bd38cd9f97cc5bb63613cb19643578640f0b ;;
> +  .t29) d=${q}946336-${q}948335-86d59545a0c13567fa96811821ea5cde950611b1 ;;
> +  .t30) d=${q}948336-${q}950335-c3740e702fa9c97e6cf00150860e0b936a141a6b ;;
> +  .t31) d=${q}950336-${q}952335-551c3c4c4640d86fda311b5c3006dac45505c0ce ;;
> +  .t32) d=${q}952336-${q}954335-b1b0b00463c2f853d70ef9c4f7a96de5cb614156 ;;
> +  .t33) d=${q}954336-${q}956335-8938a484a9ef6bb16478091d294fcde9f8ecea69 ;;
> +  .t34) d=${q}956336-${q}958335-d1ae6bc712d994f35edf55c785d71ddf31f16535 ;;
> +  .t35) d=${q}958336-${q}960335-2374919a89196e1fce93adfe779cb4664556d4b6 ;;
> +  .t36) d=${q}960336-${q}962335-569e4363e8d9e8830a187d9ab27365eef08abde1 ;;
> +  *)
> +    echo "$0: error: unknown test: $t" >&2
> +    exit 1
> +    ;;
> +esac
> +
> +# Make IFS include "-", so that a simple "set" will separate the args:
> +IFS=-$IFS
> +set $d
> +
Wouldn't it be better & safer to save and restore the original value of $IFS?
It's not really required for now, granted, but that might change in case the
script is modified in the future ...

Or: why not use 'set' directly in the 'case' construct above?  That is,
instead of

    .t00) d=0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;

you could do:

    .t00) set 0 10000000 a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;

> +# Create the test script from the template for this test
> +# by substituting the START, the END and the CKSUM.
> +sed \
> +  -e "s/__START__/$1/" \
> +  -e "s/__END__/$2/" \
> +  -e "s/__CKSUM__/$3/" \
> +  < "${ftdir}/run.sh" > "$testname" \
>
I'm not sure this would work in a VPATH setup sadly ...  You'd need
to reference $(srcdir) somewhere, but that is available only in the
Makefile.  Maybe you could simply make this script read from stdin
and write to stdout, and make the redirections in the Makefile recipe
itself?

> +  && chmod a+x "$testname" \
> +  || exit 1
> +
Maybe you could also make the generated test read-only, so that it will
be more difficult for some "casual contributor" to try to modify it by
mistake:

   && chmod a+x,a-w "$testname" \
   || exit 1

> +test -x "$testname"
>
A little too paranoid maybe?

> +exit $?

> \ No newline at end of file
>
Huh?

> diff --git a/tests/local.mk b/tests/local.mk
> index f31c8b0..7ca95c1 100644
> --- a/tests/local.mk
> +++ b/tests/local.mk
> @@ -96,6 +96,7 @@ EXTRA_DIST +=			\
>    tests/d_type-check		\
>    tests/envvar-check		\
>    tests/factor/run.sh		\
> +  tests/factor/setup.sh		\
>    tests/filefrag-extent-compare \
>    tests/fiemap-capable		\
>    tests/init.sh			\
> @@ -625,65 +626,21 @@ all_tests =					\
>    tests/touch/trailing-slash.sh			\
>    $(all_root_tests)
> 
> -# prefix of 2^64
> -p = 184467440737
> -# prefix of 2^96
> -q = 79228162514264337593543
> -
> -# Each of these numbers has a Pollard rho factor larger than 2^64,
> -# and thus exercises some hard-to-reach code in factor.c.
> -t1 = 170141183460469225450570946617781744489
> -t2 = 170141183460469229545748130981302223887
> -# Factors of the above:
> -# t1: 9223372036854775421 18446744073709551709
> -# t2: 9223372036854775643 18446744073709551709
> -
> -# Each tests is a triple: lo, hi, sha1 of result.
> -# The test script, run.sh, runs seq lo hi|factor|sha1sum
> -# and verifies that the actual and expected checksums are the same.
> +# See tests/factor/setup.sh.
>  tf = tests/factor
>  factor_tests = \
> -  $(tf)/0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0.sh \
> -  $(tf)/10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016.sh \
> -  $(tf)/20000000-30000000-8115e8dff97d1674134ec054598d939a2a5f6113.sh \
> -  $(tf)/30000000-40000000-fe7b832c8e0ed55035152c0f9ebd59de73224a60.sh \
> -  $(tf)/40000000-50000000-b8786d66c432e48bc5b342ee3c6752b7f096f206.sh \
> -  $(tf)/50000000-60000000-a74fe518c5f79873c2b9016745b88b42c8fd3ede.sh \
> -  $(tf)/60000000-70000000-689bc70d681791e5d1b8ac1316a05d0c4473d6db.sh \
> -  $(tf)/70000000-80000000-d370808f2ab8c865f64c2ff909c5722db5b7d58d.sh \
> -  $(tf)/80000000-90000000-7978aa66bf2bdb446398336ea6f02605e9a77581.sh \
> -  $(tf)/$(t1)-$(t1)-4622287c5f040cdb7b3bbe4d19d29a71ab277827.sh \
> -  $(tf)/$(t2)-$(t2)-dea308253708b57afad357e8c0d2a111460ef50e.sh \
> -  $(tf)/$(p)08551616-$(p)08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh \
> -  $(tf)/$(p)08651616-$(p)08751615-729228e693b1a568ecc85b199927424c7d16d410.sh \
> -  $(tf)/$(p)08751616-$(p)08851615-5a0c985017c2d285e4698f836f5a059e0b684563.sh \
> -  $(tf)/$(p)08851616-$(p)08951615-0482295c514e371c98ce9fd335deed0c9c44a4f4.sh \
> -  $(tf)/$(p)08951616-$(p)09051615-9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71.sh \
> -  $(tf)/$(p)09051616-$(p)09151615-604366d2b1d75371d0679e6a68962d66336cd383.sh \
> -  $(tf)/$(p)09151616-$(p)09251615-9192d2bdee930135b28d7160e6d395a7027871da.sh \
> -  $(tf)/$(p)09251616-$(p)09351615-bcf56ae55d20d700690cff4d3327b78f83fc01bf.sh \
> -  $(tf)/$(p)09351616-$(p)09451615-16b106398749e5f24d278ba7c58229ae43f650ac.sh \
> -  $(tf)/$(p)09451616-$(p)09551615-ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c.sh \
> -  $(tf)/$(p)09551616-$(p)09651615-2b6f9c11742d9de045515a6627c27a042c49f8ba.sh \
> -  $(tf)/$(p)09651616-$(p)09751615-54851acd51c4819beb666e26bc0100dc9adbc310.sh \
> -  $(tf)/$(p)09751616-$(p)09851615-6939c2a7afd2d81f45f818a159b7c5226f83a50b.sh \
> -  $(tf)/$(p)09851616-$(p)09951615-0f2c8bc011d2a45e2afa01459391e68873363c6c.sh \
> -  $(tf)/$(p)09951616-$(p)10051615-630dc2ad72f4c222bad1405e6c5bea590f92a98c.sh \
> -  $(tf)/$(q)940336-$(q)942335-63cbd6313d78247b04d63bbbac50cb8f8d33ff71.sh \
> -  $(tf)/$(q)942336-$(q)944335-0d03d63653767173182491b86fa18f8f680bb036.sh \
> -  $(tf)/$(q)944336-$(q)946335-ca43bd38cd9f97cc5bb63613cb19643578640f0b.sh \
> -  $(tf)/$(q)946336-$(q)948335-86d59545a0c13567fa96811821ea5cde950611b1.sh \
> -  $(tf)/$(q)948336-$(q)950335-c3740e702fa9c97e6cf00150860e0b936a141a6b.sh \
> -  $(tf)/$(q)950336-$(q)952335-551c3c4c4640d86fda311b5c3006dac45505c0ce.sh \
> -  $(tf)/$(q)952336-$(q)954335-b1b0b00463c2f853d70ef9c4f7a96de5cb614156.sh \
> -  $(tf)/$(q)954336-$(q)956335-8938a484a9ef6bb16478091d294fcde9f8ecea69.sh \
> -  $(tf)/$(q)956336-$(q)958335-d1ae6bc712d994f35edf55c785d71ddf31f16535.sh \
> -  $(tf)/$(q)958336-$(q)960335-2374919a89196e1fce93adfe779cb4664556d4b6.sh \
> -  $(tf)/$(q)960336-$(q)962335-569e4363e8d9e8830a187d9ab27365eef08abde1.sh
> +  $(tf)/t00.sh $(tf)/t01.sh $(tf)/t02.sh $(tf)/t03.sh $(tf)/t04.sh \
> +  $(tf)/t05.sh $(tf)/t06.sh $(tf)/t07.sh $(tf)/t08.sh $(tf)/t09.sh \
> +  $(tf)/t10.sh $(tf)/t11.sh $(tf)/t12.sh $(tf)/t13.sh $(tf)/t14.sh \
> +  $(tf)/t15.sh $(tf)/t16.sh $(tf)/t17.sh $(tf)/t18.sh $(tf)/t19.sh \
> +  $(tf)/t20.sh $(tf)/t21.sh $(tf)/t22.sh $(tf)/t23.sh $(tf)/t24.sh \
> +  $(tf)/t25.sh $(tf)/t26.sh $(tf)/t27.sh $(tf)/t28.sh $(tf)/t29.sh \
> +  $(tf)/t30.sh $(tf)/t31.sh $(tf)/t32.sh $(tf)/t33.sh $(tf)/t34.sh \
> +  $(tf)/t35.sh $(tf)/t36.sh
> 
> -$(factor_tests): tests/factor/run.sh
> +$(factor_tests): tests/factor/run.sh tests/factor/setup.sh
>  	$(AM_V_GEN)$(MKDIR_P) $(tf)
> -	$(AM_V_at)ln -f $(srcdir)/tests/factor/run.sh $@
> +	$(AM_V_at)$(srcdir)/tests/factor/setup.sh $@
> 
>  CLEANFILES += $(factor_tests)
> 

Regards,
  Stefano


From MAILER-DAEMON Fri Oct 26 20:05:29 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TRtu5-0005Jt-7n
	for mharc-coreutils@gnu.org; Fri, 26 Oct 2012 20:05:29 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49865)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRtu0-0005Jg-H6
	for coreutils@gnu.org; Fri, 26 Oct 2012 20:05:27 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRttx-0000UO-Qo
	for coreutils@gnu.org; Fri, 26 Oct 2012 20:05:24 -0400
Received: from moutng.kundenserver.de ([212.227.17.10]:57897)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TRttx-0000TC-C1
	for coreutils@gnu.org; Fri, 26 Oct 2012 20:05:21 -0400
Received: from [192.168.2.108] (p4FF7651F.dip.t-dialin.net [79.247.101.31])
	by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis)
	id 0LcCMD-1T2QR939dd-00jBXA; Sat, 27 Oct 2012 02:05:19 +0200
Message-ID: <508B253D.3000107@bernhard-voelker.de>
Date: Sat, 27 Oct 2012 02:05:17 +0200
From: Bernhard Voelker <mail@bernhard-voelker.de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: Stefano Lattarini <stefano.lattarini@gmail.com>
Subject: Re: factor tests: ugly long file names
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net>
	<508ABE1A.8070107@bernhard-voelker.de> <508ACE7E.4080204@gmail.com>
In-Reply-To: <508ACE7E.4080204@gmail.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Provags-ID: V02:K0:YSP6SpR0XoZkWeQCVSO5R3NSOpODkTJ/UPb3pV11SnN
	+fb6K58Opu2BuZX9+bgy7aCTeQwcifemer7viVX6txS2BaYCIZ
	PR12pv254F4Erism+ho1XHTyoz05D94G1yRG864o7A+uj99WoE
	2Ht1ZPraBJQcKGpLEB4X6PUlMHDRXMuCiFZQt4UGTFwzw9fyZ+
	ch/QnjPWzSb9D8gKAMFuQVWEOT4icBYMb8Iz5tSdVZP3mrQy6K
	S70bikNMAJEm3ivQOj8v27T9GaqSFHrQ+apODjzIoZIjiSLPys
	U02UunK6UU6dPa2IwhipnU2OU0FZMcKIsEVdcWwJw724pZ4rcG
	dxlffmyqAU5YnkAqC5fYeXv4kcAkvhccjFus3Lchr
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 212.227.17.10
Cc: Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Oct 2012 00:05:27 -0000

On 10/26/2012 07:55 PM, Stefano Lattarini wrote:
> On 10/26/2012 06:45 PM, Bernhard Voelker wrote:
>> WDYT?
>>
>> Not tested very thoroughly, but it seems to work.
>>
>> Have a nice day,
>> Berny
>>
>> From d85f748f4cad3fadcc699c575891259f5122fddb Mon Sep 17 00:00:00 2001
>> From: Bernhard Voelker <mail@bernhard-voelker.de>
>> Date: Fri, 26 Oct 2012 18:40:25 +0200
>> Subject: [PATCH] maint: refactor new tests for refactored factor
>>
> Wow, a tongue-twister summary line :-)

Thanks for the feedback.

> On the serious side, I've some nits below.

The patch wasn't meant to be ready to be pushed yet - just a working
outline of the idea to move the factor-related test data into the
tests/factor/ directory where it belongs.
Ok, lets see ...

>> * tests/local.mk (EXTRA_DIST): Add new tests/factor/setup.sh.
>> (factor_tests): Rename the test names to t{00..36}.sh. Factor out
>> the test data triples out.
>> (p,q,t1,t2) Factor out the related magic numbers.
>> $(factor_tests): Add dependency to new tests/factor/setup.sh.
>> Call that script to generate the test scripts.
>> * tests/factor/setup.sh: Add new script to create the test script
>> from the template tests/factor/run.sh.
>> Use test data and magic number factored out from above.
>> * tests/factor/run.sh: Change this script into a real template.
>> Add template variables START, END and CKSUM, replacing the code
>> to split the test data from the test script's file name.
>> Use the new template variables in the call to seq and for
>> creating the exp file.
>> ---
>>  tests/factor/run.sh   |   17 ++++-----
>>  tests/factor/setup.sh |   89 +++++++++++++++++++++++++++++++++++++++++++++++++
>>  tests/local.mk        |   67 +++++++------------------------------
>>  3 files changed, 108 insertions(+), 65 deletions(-)
>>  create mode 100755 tests/factor/setup.sh
>>
>> diff --git a/tests/factor/run.sh b/tests/factor/run.sh
>> index 6ff24c3..ed865ff 100755
>> --- a/tests/factor/run.sh
>> +++ b/tests/factor/run.sh
>> @@ -1,9 +1,7 @@
>>  #!/bin/sh
>>  # Test the factor rewrite.
>> -# Expect to be invoked via a file whose basename matches
>> -# /^(\d+)\-(\d+)\-([\da-f]{40})\.sh$/
>>  # The test is to run this command
>> -# seq $1 $2 | factor | shasum -c --status <(echo $3  -)
>> +# seq $START $END | factor | shasum -c --status <(echo $CKSUM  -)
>>  # I.e., to ensure that the factorizations of integers $1..$2
>>  # match what we expect.
>>
>> @@ -16,15 +14,14 @@ very_expensive_
>>
>>  print_ver_ factor seq
>>
>> -# Remove the ".sh" suffix:
>> -t=${ME_%.sh}
>> +# Template - __{START,END,CKSUM}__ is replaced by local.mk.
>> +START=__START__
>> +  END=__END__
>> +CKSUM=__CKSUM__
>>
>> -# Make IFS include "-", so that a simple "set" will separate the args:
>> -IFS=-$IFS
>> -set $t
>> -echo "$3  -" > exp
>> +echo "$CKSUM  -" > exp
>>
>>  f=1
>> -seq $1 $2 | factor | shasum -c --status exp && f=0
>> +seq $START $END | factor | shasum -c --status exp && f=0
>>
>>  Exit $f
>> diff --git a/tests/factor/setup.sh b/tests/factor/setup.sh
>> new file mode 100755
>> index 0000000..2acb5d3
>> --- /dev/null
>> +++ b/tests/factor/setup.sh
>>
> A better name would be something like factor/create-test.sh IMHO.

Renamed.

>> @@ -0,0 +1,89 @@
>> +#!/bin/sh
>>
> Missing copyright notice (not that I'd care, but the FSF seems to
> care deeply).

Good point. Copied from run.sh.

>> +# Create the factor test scripts
>> +
> Missing trailing full-stop.

Added.

>> +# Extract the test name from $1.
>> +testname="$1"
>>
> Useless quoting, the following is clearer and perfectly portable:
> 
>     testname=$1

Personal paranoia - if something goes wrong, quoting saves
the day. ;-)

>> +t=$( basename "$testname" )
>>
> You can save a fork by avoiding a call to basename:
> 
>     t=${testname##*/}

Good point. I wasn't sure if that syntax is portable.
I know it from old dtksh days.

>> +t=$( echo "${t%.sh}" )
>> +
> Useless use of echo, just use:
> 
>    t=${t%.sh}

Fixed.

>> +ftdir=$( dirname "$testname" )
>> +
> You can similarly save a fork as follows:
> 
>     case $testname in
>       */*) ftdir=${testname%/*}
>         *) ftdir=.;;
>     esac
> 
> Albeit this slightly complicates the code, so it might not be
> worthwhile in the end...

I fixed that by your suggestion below (redirect stdin/stdout from
the Makefile).

>> +# prefix of 2^64
>> +p=184467440737
>> +
>> +# prefix of 2^96
>> +q=79228162514264337593543
>> +
>> +# Each of these numbers has a Pollard rho factor larger than 2^64,
>> +# and thus exercises some hard-to-reach code in factor.c.
>> +t1=170141183460469225450570946617781744489
>> +t2=170141183460469229545748130981302223887
>> +
>> +# Factors of the above:
>> +# t1: 9223372036854775421 18446744073709551709
>> +# t2: 9223372036854775643 18446744073709551709
>> +
>> +# Each test is a triple: lo, hi, sha1 of result.
>> +# The test script, run.sh, runs seq lo hi|factor|sha1sum
>> +# and verifies that the actual and expected checksums are the same.
>> +# New tests must be added to tests/local.mk (factor_tests), too.
>> +case ".$t" in
>>
> Useless quoting, simply using
> 
>     case .$t in
> 
> would be fine as well.
> 
> Also, may I ask why you're using that leading dot?

Again paranoia. Changed.

>> +  .t00) d=0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;
>> +  .t01) d=10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016 ;;
>> +  .t02) d=20000000-30000000-8115e8dff97d1674134ec054598d939a2a5f6113 ;;
>> +  .t03) d=30000000-40000000-fe7b832c8e0ed55035152c0f9ebd59de73224a60 ;;
>> +  .t04) d=40000000-50000000-b8786d66c432e48bc5b342ee3c6752b7f096f206 ;;
>> +  .t05) d=50000000-60000000-a74fe518c5f79873c2b9016745b88b42c8fd3ede ;;
>> +  .t06) d=60000000-70000000-689bc70d681791e5d1b8ac1316a05d0c4473d6db ;;
>> +  .t07) d=70000000-80000000-d370808f2ab8c865f64c2ff909c5722db5b7d58d ;;
>> +  .t08) d=80000000-90000000-7978aa66bf2bdb446398336ea6f02605e9a77581 ;;
>> +  .t09) d=${t1}-${t1}-4622287c5f040cdb7b3bbe4d19d29a71ab277827 ;;
>> +  .t10) d=${t2}-${t2}-dea308253708b57afad357e8c0d2a111460ef50e ;;
>> +  .t11) d=${p}08551616-${p}08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1 ;;
>> +  .t12) d=${p}08651616-${p}08751615-729228e693b1a568ecc85b199927424c7d16d410 ;;
>> +  .t13) d=${p}08751616-${p}08851615-5a0c985017c2d285e4698f836f5a059e0b684563 ;;
>> +  .t14) d=${p}08851616-${p}08951615-0482295c514e371c98ce9fd335deed0c9c44a4f4 ;;
>> +  .t15) d=${p}08951616-${p}09051615-9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71 ;;
>> +  .t16) d=${p}09051616-${p}09151615-604366d2b1d75371d0679e6a68962d66336cd383 ;;
>> +  .t17) d=${p}09151616-${p}09251615-9192d2bdee930135b28d7160e6d395a7027871da ;;
>> +  .t18) d=${p}09251616-${p}09351615-bcf56ae55d20d700690cff4d3327b78f83fc01bf ;;
>> +  .t19) d=${p}09351616-${p}09451615-16b106398749e5f24d278ba7c58229ae43f650ac ;;
>> +  .t20) d=${p}09451616-${p}09551615-ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c ;;
>> +  .t21) d=${p}09551616-${p}09651615-2b6f9c11742d9de045515a6627c27a042c49f8ba ;;
>> +  .t22) d=${p}09651616-${p}09751615-54851acd51c4819beb666e26bc0100dc9adbc310 ;;
>> +  .t23) d=${p}09751616-${p}09851615-6939c2a7afd2d81f45f818a159b7c5226f83a50b ;;
>> +  .t24) d=${p}09851616-${p}09951615-0f2c8bc011d2a45e2afa01459391e68873363c6c ;;
>> +  .t25) d=${p}09951616-${p}10051615-630dc2ad72f4c222bad1405e6c5bea590f92a98c ;;
>> +  .t26) d=${q}940336-${q}942335-63cbd6313d78247b04d63bbbac50cb8f8d33ff71 ;;
>> +  .t27) d=${q}942336-${q}944335-0d03d63653767173182491b86fa18f8f680bb036 ;;
>> +  .t28) d=${q}944336-${q}946335-ca43bd38cd9f97cc5bb63613cb19643578640f0b ;;
>> +  .t29) d=${q}946336-${q}948335-86d59545a0c13567fa96811821ea5cde950611b1 ;;
>> +  .t30) d=${q}948336-${q}950335-c3740e702fa9c97e6cf00150860e0b936a141a6b ;;
>> +  .t31) d=${q}950336-${q}952335-551c3c4c4640d86fda311b5c3006dac45505c0ce ;;
>> +  .t32) d=${q}952336-${q}954335-b1b0b00463c2f853d70ef9c4f7a96de5cb614156 ;;
>> +  .t33) d=${q}954336-${q}956335-8938a484a9ef6bb16478091d294fcde9f8ecea69 ;;
>> +  .t34) d=${q}956336-${q}958335-d1ae6bc712d994f35edf55c785d71ddf31f16535 ;;
>> +  .t35) d=${q}958336-${q}960335-2374919a89196e1fce93adfe779cb4664556d4b6 ;;
>> +  .t36) d=${q}960336-${q}962335-569e4363e8d9e8830a187d9ab27365eef08abde1 ;;
>> +  *)
>> +    echo "$0: error: unknown test: $t" >&2
>> +    exit 1
>> +    ;;
>> +esac
>> +
>> +# Make IFS include "-", so that a simple "set" will separate the args:
>> +IFS=-$IFS
>> +set $d
>> +
> Wouldn't it be better & safer to save and restore the original value of $IFS?
> It's not really required for now, granted, but that might change in case the
> script is modified in the future ...

I copied that part from run.sh and didn't think much about it. However, ...

> Or: why not use 'set' directly in the 'case' construct above?  That is,
> instead of
> 
>     .t00) d=0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;
> 
> you could do:
> 
>     .t00) set 0 10000000 a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;

... that's a great idea: I also changed the indentation.
Now, that part looks nicer - see below.

>> +# Create the test script from the template for this test
>> +# by substituting the START, the END and the CKSUM.
>> +sed \
>> +  -e "s/__START__/$1/" \
>> +  -e "s/__END__/$2/" \
>> +  -e "s/__CKSUM__/$3/" \
>> +  < "${ftdir}/run.sh" > "$testname" \
>>
> I'm not sure this would work in a VPATH setup sadly ...  You'd need
> to reference $(srcdir) somewhere, but that is available only in the
> Makefile.  Maybe you could simply make this script read from stdin
> and write to stdout, and make the redirections in the Makefile recipe
> itself?

Done.

>> +  && chmod a+x "$testname" \
>> +  || exit 1
>> +
> Maybe you could also make the generated test read-only, so that it will
> be more difficult for some "casual contributor" to try to modify it by
> mistake:
> 
>    && chmod a+x,a-w "$testname" \
>    || exit 1

I'm not sure about that. If the user changes run.sh or create-test.sh,
and the tests have to be rebuilt, then that would fail with "permission
denied".
Instead, I added a line into the template that this file is generated.


>> +test -x "$testname"
>>
> A little too paranoid maybe?

Admitted ;-)

>> +exit $?
> 
>> \ No newline at end of file
>>
> Huh?

Sorry, I was using geany, and `make syntax-check` didn't complain
(although I'm not sure whether it inspected the new file).

Here's the new approach:

>From 5503728eaa0ce1c9eea6003a3a3c62bab1c97996 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <mail@bernhard-voelker.de>
Date: Sat, 27 Oct 2012 01:56:36 +0200
Subject: [PATCH] maint: refactor new tests for refactored factor

* tests/local.mk (EXTRA_DIST): Add new tests/factor/create-test.sh.
(p,q,t1,t2) Factor out the factor-related magic numbers.
(factor_tests): Rename the test names to t{00..36}.sh. Factor out
the triples of test data.
($(factor_tests)): Add dependency to new
tests/factor/create-factor.sh.
Call that script to generate the test scripts.
* tests/factor/run.sh: Turn this script into a template.
Add template variables START, END and CKSUM, replacing the code
to split the test data from the test script's file name.
Use the new template variables in the call to seq and for
creating the exp file.
* tests/factor/create-test.sh: Add new script to create the
test scripts from the template tests/factor/run.sh.
Use test data and magic numbers factored out from the above
files. Let the script also change the __TEMPLATE__ line in
run.sh to make clear that the test scripts are generated.
* cfg.mk (sc_tests_list_consistency): Exempt the new test.
---
 cfg.mk                      |    2 +-
 tests/factor/create-test.sh |   86 +++++++++++++++++++++++++++++++++++++++++++
 tests/factor/run.sh         |   22 ++++++-----
 tests/local.mk              |   70 +++++++---------------------------
 4 files changed, 114 insertions(+), 66 deletions(-)
 create mode 100755 tests/factor/create-test.sh

diff --git a/cfg.mk b/cfg.mk
index 08f6c3d..6155ec2 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -111,7 +111,7 @@ sc_tests_list_consistency:
 	  for t in $(all_tests); do echo $$t; done;			\
 	  cd $(top_srcdir);						\
 	  $(SHELL) build-aux/vc-list-files tests			\
-	    | grep -Ev '^tests/(factor/run|init)\.sh$$'			\
+	    | grep -Ev '^tests/(factor/run|factor/create-test|init)\.sh$$' \
 	    | $(EGREP) "$$test_extensions_rx\$$";			\
 	} | sort | uniq -u | grep . && exit 1; :

diff --git a/tests/factor/create-test.sh b/tests/factor/create-test.sh
new file mode 100755
index 0000000..907396f
--- /dev/null
+++ b/tests/factor/create-test.sh
@@ -0,0 +1,86 @@
+#!/bin/sh
+# Create the factor test scripts.
+# Used template: tests/factor/run.sh.
+
+# Copyright (C) 2012 Free Software Foundation, Inc.
+
+# Extract the test name from $1.
+testname="$1"
+t="${testname##*/}"
+t="${t%.sh}"
+
+# prefix of 2^64
+p=184467440737
+
+# prefix of 2^96
+q=79228162514264337593543
+
+# Each of these numbers has a Pollard rho factor larger than 2^64,
+# and thus exercises some hard-to-reach code in factor.c.
+t1=170141183460469225450570946617781744489
+t2=170141183460469229545748130981302223887
+
+# Factors of the above:
+# t1: 9223372036854775421 18446744073709551709
+# t2: 9223372036854775643 18446744073709551709
+
+# Each test is a triple: lo, hi, sha1 of result.
+# The test script, run.sh, runs seq lo hi|factor|sha1sum
+# and verifies that the actual and expected checksums are the same.
+# New tests must be added to tests/local.mk (factor_tests), too.
+case $t in
+  t00) set            0     10000000 a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;
+  t01) set     10000000     20000000 c792a2e02f1c8536b5121f624b04039d20187016 ;;
+  t02) set     20000000     30000000 8115e8dff97d1674134ec054598d939a2a5f6113 ;;
+  t03) set     30000000     40000000 fe7b832c8e0ed55035152c0f9ebd59de73224a60 ;;
+  t04) set     40000000     50000000 b8786d66c432e48bc5b342ee3c6752b7f096f206 ;;
+  t05) set     50000000     60000000 a74fe518c5f79873c2b9016745b88b42c8fd3ede ;;
+  t06) set     60000000     70000000 689bc70d681791e5d1b8ac1316a05d0c4473d6db ;;
+  t07) set     70000000     80000000 d370808f2ab8c865f64c2ff909c5722db5b7d58d ;;
+  t08) set     80000000     90000000 7978aa66bf2bdb446398336ea6f02605e9a77581 ;;
+  t09) set        ${t1}        ${t1} 4622287c5f040cdb7b3bbe4d19d29a71ab277827 ;;
+  t10) set        ${t2}        ${t2} dea308253708b57afad357e8c0d2a111460ef50e ;;
+  t11) set ${p}08551616 ${p}08651615 66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1 ;;
+  t12) set ${p}08651616 ${p}08751615 729228e693b1a568ecc85b199927424c7d16d410 ;;
+  t13) set ${p}08751616 ${p}08851615 5a0c985017c2d285e4698f836f5a059e0b684563 ;;
+  t14) set ${p}08851616 ${p}08951615 0482295c514e371c98ce9fd335deed0c9c44a4f4 ;;
+  t15) set ${p}08951616 ${p}09051615 9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71 ;;
+  t16) set ${p}09051616 ${p}09151615 604366d2b1d75371d0679e6a68962d66336cd383 ;;
+  t17) set ${p}09151616 ${p}09251615 9192d2bdee930135b28d7160e6d395a7027871da ;;
+  t18) set ${p}09251616 ${p}09351615 bcf56ae55d20d700690cff4d3327b78f83fc01bf ;;
+  t19) set ${p}09351616 ${p}09451615 16b106398749e5f24d278ba7c58229ae43f650ac ;;
+  t20) set ${p}09451616 ${p}09551615 ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c ;;
+  t21) set ${p}09551616 ${p}09651615 2b6f9c11742d9de045515a6627c27a042c49f8ba ;;
+  t22) set ${p}09651616 ${p}09751615 54851acd51c4819beb666e26bc0100dc9adbc310 ;;
+  t23) set ${p}09751616 ${p}09851615 6939c2a7afd2d81f45f818a159b7c5226f83a50b ;;
+  t24) set ${p}09851616 ${p}09951615 0f2c8bc011d2a45e2afa01459391e68873363c6c ;;
+  t25) set ${p}09951616 ${p}10051615 630dc2ad72f4c222bad1405e6c5bea590f92a98c ;;
+  t26) set   ${q}940336   ${q}942335 63cbd6313d78247b04d63bbbac50cb8f8d33ff71 ;;
+  t27) set   ${q}942336   ${q}944335 0d03d63653767173182491b86fa18f8f680bb036 ;;
+  t28) set   ${q}944336   ${q}946335 ca43bd38cd9f97cc5bb63613cb19643578640f0b ;;
+  t29) set   ${q}946336   ${q}948335 86d59545a0c13567fa96811821ea5cde950611b1 ;;
+  t30) set   ${q}948336   ${q}950335 c3740e702fa9c97e6cf00150860e0b936a141a6b ;;
+  t31) set   ${q}950336   ${q}952335 551c3c4c4640d86fda311b5c3006dac45505c0ce ;;
+  t32) set   ${q}952336   ${q}954335 b1b0b00463c2f853d70ef9c4f7a96de5cb614156 ;;
+  t33) set   ${q}954336   ${q}956335 8938a484a9ef6bb16478091d294fcde9f8ecea69 ;;
+  t34) set   ${q}956336   ${q}958335 d1ae6bc712d994f35edf55c785d71ddf31f16535 ;;
+  t35) set   ${q}958336   ${q}960335 2374919a89196e1fce93adfe779cb4664556d4b6 ;;
+  t36) set   ${q}960336   ${q}962335 569e4363e8d9e8830a187d9ab27365eef08abde1 ;;
+  *)
+    echo "$0: error: unknown test: '$testname' -> '$t'" >&2
+    exit 1
+    ;;
+esac
+
+TEMPLATE="TEST SCRIPT DERIVED FROM THE TEMPLATE tests\/factor\/run.sh"
+
+# Create the test script from the template for this test
+# by substituting the START, the END and the CKSUM.
+sed \
+  -e "s/__START__/$1/" \
+  -e "s/__END__/$2/" \
+  -e "s/__CKSUM__/$3/" \
+  -e "s/__TEMPLATE__/$TEMPLATE/" \
+  || exit 1
+
+exit 0
diff --git a/tests/factor/run.sh b/tests/factor/run.sh
index 6ff24c3..33ec8cd 100755
--- a/tests/factor/run.sh
+++ b/tests/factor/run.sh
@@ -1,11 +1,14 @@
 #!/bin/sh
+
+# === THIS IS A __TEMPLATE__ ===
+
 # Test the factor rewrite.
-# Expect to be invoked via a file whose basename matches
-# /^(\d+)\-(\d+)\-([\da-f]{40})\.sh$/
 # The test is to run this command
-# seq $1 $2 | factor | shasum -c --status <(echo $3  -)
+# seq $START $END | factor | shasum -c --status <(echo $CKSUM  -)
 # I.e., to ensure that the factorizations of integers $1..$2
 # match what we expect.
+#
+# See: tests/factor/create-test.sh

 # Copyright (C) 2012 Free Software Foundation, Inc.

@@ -16,15 +19,14 @@ very_expensive_

 print_ver_ factor seq

-# Remove the ".sh" suffix:
-t=${ME_%.sh}
+# Template variables.
+START=__START__
+  END=__END__
+CKSUM=__CKSUM__

-# Make IFS include "-", so that a simple "set" will separate the args:
-IFS=-$IFS
-set $t
-echo "$3  -" > exp
+echo "$CKSUM  -" > exp

 f=1
-seq $1 $2 | factor | shasum -c --status exp && f=0
+seq $START $END | factor | shasum -c --status exp && f=0

 Exit $f
diff --git a/tests/local.mk b/tests/local.mk
index f31c8b0..9ee696a 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -96,6 +96,7 @@ EXTRA_DIST +=			\
   tests/d_type-check		\
   tests/envvar-check		\
   tests/factor/run.sh		\
+  tests/factor/create-test.sh	\
   tests/filefrag-extent-compare \
   tests/fiemap-capable		\
   tests/init.sh			\
@@ -625,65 +626,24 @@ all_tests =					\
   tests/touch/trailing-slash.sh			\
   $(all_root_tests)

-# prefix of 2^64
-p = 184467440737
-# prefix of 2^96
-q = 79228162514264337593543
-
-# Each of these numbers has a Pollard rho factor larger than 2^64,
-# and thus exercises some hard-to-reach code in factor.c.
-t1 = 170141183460469225450570946617781744489
-t2 = 170141183460469229545748130981302223887
-# Factors of the above:
-# t1: 9223372036854775421 18446744073709551709
-# t2: 9223372036854775643 18446744073709551709
-
-# Each tests is a triple: lo, hi, sha1 of result.
-# The test script, run.sh, runs seq lo hi|factor|sha1sum
-# and verifies that the actual and expected checksums are the same.
+# See tests/factor/create-test.sh.
 tf = tests/factor
 factor_tests = \
-  $(tf)/0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0.sh \
-  $(tf)/10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016.sh \
-  $(tf)/20000000-30000000-8115e8dff97d1674134ec054598d939a2a5f6113.sh \
-  $(tf)/30000000-40000000-fe7b832c8e0ed55035152c0f9ebd59de73224a60.sh \
-  $(tf)/40000000-50000000-b8786d66c432e48bc5b342ee3c6752b7f096f206.sh \
-  $(tf)/50000000-60000000-a74fe518c5f79873c2b9016745b88b42c8fd3ede.sh \
-  $(tf)/60000000-70000000-689bc70d681791e5d1b8ac1316a05d0c4473d6db.sh \
-  $(tf)/70000000-80000000-d370808f2ab8c865f64c2ff909c5722db5b7d58d.sh \
-  $(tf)/80000000-90000000-7978aa66bf2bdb446398336ea6f02605e9a77581.sh \
-  $(tf)/$(t1)-$(t1)-4622287c5f040cdb7b3bbe4d19d29a71ab277827.sh \
-  $(tf)/$(t2)-$(t2)-dea308253708b57afad357e8c0d2a111460ef50e.sh \
-  $(tf)/$(p)08551616-$(p)08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh \
-  $(tf)/$(p)08651616-$(p)08751615-729228e693b1a568ecc85b199927424c7d16d410.sh \
-  $(tf)/$(p)08751616-$(p)08851615-5a0c985017c2d285e4698f836f5a059e0b684563.sh \
-  $(tf)/$(p)08851616-$(p)08951615-0482295c514e371c98ce9fd335deed0c9c44a4f4.sh \
-  $(tf)/$(p)08951616-$(p)09051615-9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71.sh \
-  $(tf)/$(p)09051616-$(p)09151615-604366d2b1d75371d0679e6a68962d66336cd383.sh \
-  $(tf)/$(p)09151616-$(p)09251615-9192d2bdee930135b28d7160e6d395a7027871da.sh \
-  $(tf)/$(p)09251616-$(p)09351615-bcf56ae55d20d700690cff4d3327b78f83fc01bf.sh \
-  $(tf)/$(p)09351616-$(p)09451615-16b106398749e5f24d278ba7c58229ae43f650ac.sh \
-  $(tf)/$(p)09451616-$(p)09551615-ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c.sh \
-  $(tf)/$(p)09551616-$(p)09651615-2b6f9c11742d9de045515a6627c27a042c49f8ba.sh \
-  $(tf)/$(p)09651616-$(p)09751615-54851acd51c4819beb666e26bc0100dc9adbc310.sh \
-  $(tf)/$(p)09751616-$(p)09851615-6939c2a7afd2d81f45f818a159b7c5226f83a50b.sh \
-  $(tf)/$(p)09851616-$(p)09951615-0f2c8bc011d2a45e2afa01459391e68873363c6c.sh \
-  $(tf)/$(p)09951616-$(p)10051615-630dc2ad72f4c222bad1405e6c5bea590f92a98c.sh \
-  $(tf)/$(q)940336-$(q)942335-63cbd6313d78247b04d63bbbac50cb8f8d33ff71.sh \
-  $(tf)/$(q)942336-$(q)944335-0d03d63653767173182491b86fa18f8f680bb036.sh \
-  $(tf)/$(q)944336-$(q)946335-ca43bd38cd9f97cc5bb63613cb19643578640f0b.sh \
-  $(tf)/$(q)946336-$(q)948335-86d59545a0c13567fa96811821ea5cde950611b1.sh \
-  $(tf)/$(q)948336-$(q)950335-c3740e702fa9c97e6cf00150860e0b936a141a6b.sh \
-  $(tf)/$(q)950336-$(q)952335-551c3c4c4640d86fda311b5c3006dac45505c0ce.sh \
-  $(tf)/$(q)952336-$(q)954335-b1b0b00463c2f853d70ef9c4f7a96de5cb614156.sh \
-  $(tf)/$(q)954336-$(q)956335-8938a484a9ef6bb16478091d294fcde9f8ecea69.sh \
-  $(tf)/$(q)956336-$(q)958335-d1ae6bc712d994f35edf55c785d71ddf31f16535.sh \
-  $(tf)/$(q)958336-$(q)960335-2374919a89196e1fce93adfe779cb4664556d4b6.sh \
-  $(tf)/$(q)960336-$(q)962335-569e4363e8d9e8830a187d9ab27365eef08abde1.sh
+  $(tf)/t00.sh $(tf)/t01.sh $(tf)/t02.sh $(tf)/t03.sh $(tf)/t04.sh \
+  $(tf)/t05.sh $(tf)/t06.sh $(tf)/t07.sh $(tf)/t08.sh $(tf)/t09.sh \
+  $(tf)/t10.sh $(tf)/t11.sh $(tf)/t12.sh $(tf)/t13.sh $(tf)/t14.sh \
+  $(tf)/t15.sh $(tf)/t16.sh $(tf)/t17.sh $(tf)/t18.sh $(tf)/t19.sh \
+  $(tf)/t20.sh $(tf)/t21.sh $(tf)/t22.sh $(tf)/t23.sh $(tf)/t24.sh \
+  $(tf)/t25.sh $(tf)/t26.sh $(tf)/t27.sh $(tf)/t28.sh $(tf)/t29.sh \
+  $(tf)/t30.sh $(tf)/t31.sh $(tf)/t32.sh $(tf)/t33.sh $(tf)/t34.sh \
+  $(tf)/t35.sh $(tf)/t36.sh

-$(factor_tests): tests/factor/run.sh
+$(factor_tests): $(tf)/run.sh $(tf)/create-test.sh
 	$(AM_V_GEN)$(MKDIR_P) $(tf)
-	$(AM_V_at)ln -f $(srcdir)/tests/factor/run.sh $@
+	$(AM_V_at)$(srcdir)/$(tf)/create-test.sh $@ \
+	  < $(srcdir)/$(tf)/run.sh \
+	  > $@
+	@chmod a+x $@

 CLEANFILES += $(factor_tests)

-- 
1.7.7



From MAILER-DAEMON Sat Oct 27 03:40:14 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TS109-0006DH-V4
	for mharc-coreutils@gnu.org; Sat, 27 Oct 2012 03:40:13 -0400
Received: from eggs.gnu.org ([208.118.235.92]:35265)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TS105-0006Bj-T9
	for coreutils@gnu.org; Sat, 27 Oct 2012 03:40:12 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TS103-0005DF-EO
	for coreutils@gnu.org; Sat, 27 Oct 2012 03:40:09 -0400
Received: from mail-ea0-f169.google.com ([209.85.215.169]:49753)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TS103-0005C0-43
	for coreutils@gnu.org; Sat, 27 Oct 2012 03:40:07 -0400
Received: by mail-ea0-f169.google.com with SMTP id k11so1284164eaa.0
	for <coreutils@gnu.org>; Sat, 27 Oct 2012 00:40:06 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=message-id:date:from:mime-version:to:cc:subject:references
	:in-reply-to:content-type:content-transfer-encoding;
	bh=fegHYiYAFv2+zV8ULsrHs8+nDAHFNCFNfXzzx21UNIs=;
	b=h+s6e0ZCrE4n8rXhrxuINsfgf8id7HrPRsWmR4dBpYe3On6uKuB7H2AXfbEQ6TO30u
	oajxEu/hgpC3fiUt/6zWiIKLMUPk0zYnoBnMo80E10vJvWm/43cFvyt6pwU76+KcskdB
	SPm1HVo/pHf3jB7XJSb+l5hMASu4pXRwbKfPxlV4lks4vO0qc5Q724toGb2c2p/RzVgp
	VibZZpP6XFn5kBwQhiXGOjlcFHCnViOLekYutUe2HJU/EPk+9FjpgcRInQDaBazHZfDn
	zc76sMA3kTrQuEmqb/2+hWVfQXEI7gi+2lv79lyD0fZypuQQymV6Y/krSVang5es0UFo
	VG6g==
Received: by 10.14.184.2 with SMTP id r2mr40083120eem.43.1351323606082;
	Sat, 27 Oct 2012 00:40:06 -0700 (PDT)
Received: from [192.168.178.21]
	(host247-100-dynamic.8-87-r.retail.telecomitalia.it. [87.8.100.247])
	by mx.google.com with ESMTPS id o49sm7536685eep.5.2012.10.27.00.40.04
	(version=SSLv3 cipher=OTHER); Sat, 27 Oct 2012 00:40:05 -0700 (PDT)
Message-ID: <508B8FD3.6030100@gmail.com>
Date: Sat, 27 Oct 2012 09:40:03 +0200
From: Stefano Lattarini <stefano.lattarini@gmail.com>
MIME-Version: 1.0
To: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: Re: factor tests: ugly long file names
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net>
	<508ABE1A.8070107@bernhard-voelker.de> <508ACE7E.4080204@gmail.com>
	<508B253D.3000107@bernhard-voelker.de>
In-Reply-To: <508B253D.3000107@bernhard-voelker.de>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.85.215.169
Cc: Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Oct 2012 07:40:12 -0000

Hi Bernhard.

On 10/27/2012 02:05 AM, Bernhard Voelker wrote:
> On 10/26/2012 07:55 PM, Stefano Lattarini wrote:
>> On 10/26/2012 06:45 PM, Bernhard Voelker wrote:
>>> WDYT?
>>>
>>> Not tested very thoroughly, but it seems to work.
>>>
>>> Have a nice day,
>>> Berny
>>>
>>> From d85f748f4cad3fadcc699c575891259f5122fddb Mon Sep 17 00:00:00 2001
>>> From: Bernhard Voelker <mail@bernhard-voelker.de>
>>> Date: Fri, 26 Oct 2012 18:40:25 +0200
>>> Subject: [PATCH] maint: refactor new tests for refactored factor
>>>
>> Wow, a tongue-twister summary line :-)
> 
> Thanks for the feedback.
> 
>> On the serious side, I've some nits below.
> 
> The patch wasn't meant to be ready to be pushed yet - just a working
> outline of the idea to move the factor-related test data into the
> tests/factor/ directory where it belongs.
>
Ah, OK.  I hadn't got that actually; so thanks for the clarification.

> Ok, lets see ...
> 
>>> * tests/local.mk (EXTRA_DIST): Add new tests/factor/setup.sh.
>>> (factor_tests): Rename the test names to t{00..36}.sh. Factor out
>>> the test data triples out.
>>> (p,q,t1,t2) Factor out the related magic numbers.
>>> $(factor_tests): Add dependency to new tests/factor/setup.sh.
>>> Call that script to generate the test scripts.
>>> * tests/factor/setup.sh: Add new script to create the test script
>>> from the template tests/factor/run.sh.
>>> Use test data and magic number factored out from above.
>>> * tests/factor/run.sh: Change this script into a real template.
>>> Add template variables START, END and CKSUM, replacing the code
>>> to split the test data from the test script's file name.
>>> Use the new template variables in the call to seq and for
>>> creating the exp file.
>>> ---
>>>  tests/factor/run.sh   |   17 ++++-----
>>>  tests/factor/setup.sh |   89 +++++++++++++++++++++++++++++++++++++++++++++++++
>>>  tests/local.mk        |   67 +++++++------------------------------
>>>  3 files changed, 108 insertions(+), 65 deletions(-)
>>>  create mode 100755 tests/factor/setup.sh
>>>
>>> diff --git a/tests/factor/run.sh b/tests/factor/run.sh
>>> index 6ff24c3..ed865ff 100755
>>> --- a/tests/factor/run.sh
>>> +++ b/tests/factor/run.sh
>>> @@ -1,9 +1,7 @@
>>>  #!/bin/sh
>>>  # Test the factor rewrite.
>>> -# Expect to be invoked via a file whose basename matches
>>> -# /^(\d+)\-(\d+)\-([\da-f]{40})\.sh$/
>>>  # The test is to run this command
>>> -# seq $1 $2 | factor | shasum -c --status <(echo $3  -)
>>> +# seq $START $END | factor | shasum -c --status <(echo $CKSUM  -)
>>>  # I.e., to ensure that the factorizations of integers $1..$2
>>>  # match what we expect.
>>>
>>> @@ -16,15 +14,14 @@ very_expensive_
>>>
>>>  print_ver_ factor seq
>>>
>>> -# Remove the ".sh" suffix:
>>> -t=${ME_%.sh}
>>> +# Template - __{START,END,CKSUM}__ is replaced by local.mk.
>>> +START=__START__
>>> +  END=__END__
>>> +CKSUM=__CKSUM__
>>>
>>> -# Make IFS include "-", so that a simple "set" will separate the args:
>>> -IFS=-$IFS
>>> -set $t
>>> -echo "$3  -" > exp
>>> +echo "$CKSUM  -" > exp
>>>
>>>  f=1
>>> -seq $1 $2 | factor | shasum -c --status exp && f=0
>>> +seq $START $END | factor | shasum -c --status exp && f=0
>>>
>>>  Exit $f
>>> diff --git a/tests/factor/setup.sh b/tests/factor/setup.sh
>>> new file mode 100755
>>> index 0000000..2acb5d3
>>> --- /dev/null
>>> +++ b/tests/factor/setup.sh
>>>
>> A better name would be something like factor/create-test.sh IMHO.
> 
> Renamed.
> 
>>> @@ -0,0 +1,89 @@
>>> +#!/bin/sh
>>>
>> Missing copyright notice (not that I'd care, but the FSF seems to
>> care deeply).
> 
> Good point. Copied from run.sh.
> 
>>> +# Create the factor test scripts
>>> +
>> Missing trailing full-stop.
> 
> Added.
> 
>>> +# Extract the test name from $1.
>>> +testname="$1"
>>>
>> Useless quoting, the following is clearer and perfectly portable:
>>
>>     testname=$1
> 
> Personal paranoia - if something goes wrong, quoting saves
> the day. ;-)
>
Alas, not always!

    $ ksh -c 'x="`echo "a b"`"; echo "$x"'
    ksh: : cannot execute [Is a directory]
    ksh: b: not found [No such file or directory]
    $ ksh -c 'x=`echo "a b"`; echo "$x"'
    a b

I think the Autoconf manual has other lovely examples ...

>>> +t=$( basename "$testname" )
>>>
>> You can save a fork by avoiding a call to basename:
>>
>>     t=${testname##*/}
> 
> Good point. I wasn't sure if that syntax is portable.
> I know it from old dtksh days.
>
It is portable to any decent POSIX shell.  And I think Coreutils assumes
that one is available on the build system.  But then, to ensure such a
shell is actually used, you'll have to invoke your script explicitly with
the configure-determined $(SHELL) from the make recipe below (thank you
Solaris for keeping an old non-POSIX shell as /bin/sh, sigh).

Jim, can you confirm it's OK to assume that $(SHELL) points to a POSIX
shell in the coreutils build system?

>>> +t=$( echo "${t%.sh}" )
>>> +
>> Useless use of echo, just use:
>>
>>    t=${t%.sh}
> 
> Fixed.
> 
>>> +ftdir=$( dirname "$testname" )
>>> +
>> You can similarly save a fork as follows:
>>
>>     case $testname in
>>       */*) ftdir=${testname%/*}
>>         *) ftdir=.;;
>>     esac
>>
>> Albeit this slightly complicates the code, so it might not be
>> worthwhile in the end...
> 
> I fixed that by your suggestion below (redirect stdin/stdout from
> the Makefile).
> 
>>> +# prefix of 2^64
>>> +p=184467440737
>>> +
>>> +# prefix of 2^96
>>> +q=79228162514264337593543
>>> +
>>> +# Each of these numbers has a Pollard rho factor larger than 2^64,
>>> +# and thus exercises some hard-to-reach code in factor.c.
>>> +t1=170141183460469225450570946617781744489
>>> +t2=170141183460469229545748130981302223887
>>> +
>>> +# Factors of the above:
>>> +# t1: 9223372036854775421 18446744073709551709
>>> +# t2: 9223372036854775643 18446744073709551709
>>> +
>>> +# Each test is a triple: lo, hi, sha1 of result.
>>> +# The test script, run.sh, runs seq lo hi|factor|sha1sum
>>> +# and verifies that the actual and expected checksums are the same.
>>> +# New tests must be added to tests/local.mk (factor_tests), too.
>>> +case ".$t" in
>>>
>> Useless quoting, simply using
>>
>>     case .$t in
>>
>> would be fine as well.
>>
>> Also, may I ask why you're using that leading dot?
> 
> Again paranoia. Changed.
> 
>>> +  .t00) d=0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;
>>> +  .t01) d=10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016 ;;
>>> +  .t02) d=20000000-30000000-8115e8dff97d1674134ec054598d939a2a5f6113 ;;
>>> +  .t03) d=30000000-40000000-fe7b832c8e0ed55035152c0f9ebd59de73224a60 ;;
>>> +  .t04) d=40000000-50000000-b8786d66c432e48bc5b342ee3c6752b7f096f206 ;;
>>> +  .t05) d=50000000-60000000-a74fe518c5f79873c2b9016745b88b42c8fd3ede ;;
>>> +  .t06) d=60000000-70000000-689bc70d681791e5d1b8ac1316a05d0c4473d6db ;;
>>> +  .t07) d=70000000-80000000-d370808f2ab8c865f64c2ff909c5722db5b7d58d ;;
>>> +  .t08) d=80000000-90000000-7978aa66bf2bdb446398336ea6f02605e9a77581 ;;
>>> +  .t09) d=${t1}-${t1}-4622287c5f040cdb7b3bbe4d19d29a71ab277827 ;;
>>> +  .t10) d=${t2}-${t2}-dea308253708b57afad357e8c0d2a111460ef50e ;;
>>> +  .t11) d=${p}08551616-${p}08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1 ;;
>>> +  .t12) d=${p}08651616-${p}08751615-729228e693b1a568ecc85b199927424c7d16d410 ;;
>>> +  .t13) d=${p}08751616-${p}08851615-5a0c985017c2d285e4698f836f5a059e0b684563 ;;
>>> +  .t14) d=${p}08851616-${p}08951615-0482295c514e371c98ce9fd335deed0c9c44a4f4 ;;
>>> +  .t15) d=${p}08951616-${p}09051615-9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71 ;;
>>> +  .t16) d=${p}09051616-${p}09151615-604366d2b1d75371d0679e6a68962d66336cd383 ;;
>>> +  .t17) d=${p}09151616-${p}09251615-9192d2bdee930135b28d7160e6d395a7027871da ;;
>>> +  .t18) d=${p}09251616-${p}09351615-bcf56ae55d20d700690cff4d3327b78f83fc01bf ;;
>>> +  .t19) d=${p}09351616-${p}09451615-16b106398749e5f24d278ba7c58229ae43f650ac ;;
>>> +  .t20) d=${p}09451616-${p}09551615-ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c ;;
>>> +  .t21) d=${p}09551616-${p}09651615-2b6f9c11742d9de045515a6627c27a042c49f8ba ;;
>>> +  .t22) d=${p}09651616-${p}09751615-54851acd51c4819beb666e26bc0100dc9adbc310 ;;
>>> +  .t23) d=${p}09751616-${p}09851615-6939c2a7afd2d81f45f818a159b7c5226f83a50b ;;
>>> +  .t24) d=${p}09851616-${p}09951615-0f2c8bc011d2a45e2afa01459391e68873363c6c ;;
>>> +  .t25) d=${p}09951616-${p}10051615-630dc2ad72f4c222bad1405e6c5bea590f92a98c ;;
>>> +  .t26) d=${q}940336-${q}942335-63cbd6313d78247b04d63bbbac50cb8f8d33ff71 ;;
>>> +  .t27) d=${q}942336-${q}944335-0d03d63653767173182491b86fa18f8f680bb036 ;;
>>> +  .t28) d=${q}944336-${q}946335-ca43bd38cd9f97cc5bb63613cb19643578640f0b ;;
>>> +  .t29) d=${q}946336-${q}948335-86d59545a0c13567fa96811821ea5cde950611b1 ;;
>>> +  .t30) d=${q}948336-${q}950335-c3740e702fa9c97e6cf00150860e0b936a141a6b ;;
>>> +  .t31) d=${q}950336-${q}952335-551c3c4c4640d86fda311b5c3006dac45505c0ce ;;
>>> +  .t32) d=${q}952336-${q}954335-b1b0b00463c2f853d70ef9c4f7a96de5cb614156 ;;
>>> +  .t33) d=${q}954336-${q}956335-8938a484a9ef6bb16478091d294fcde9f8ecea69 ;;
>>> +  .t34) d=${q}956336-${q}958335-d1ae6bc712d994f35edf55c785d71ddf31f16535 ;;
>>> +  .t35) d=${q}958336-${q}960335-2374919a89196e1fce93adfe779cb4664556d4b6 ;;
>>> +  .t36) d=${q}960336-${q}962335-569e4363e8d9e8830a187d9ab27365eef08abde1 ;;
>>> +  *)
>>> +    echo "$0: error: unknown test: $t" >&2
>>> +    exit 1
>>> +    ;;
>>> +esac
>>> +
>>> +# Make IFS include "-", so that a simple "set" will separate the args:
>>> +IFS=-$IFS
>>> +set $d
>>> +
>> Wouldn't it be better & safer to save and restore the original value of $IFS?
>> It's not really required for now, granted, but that might change in case the
>> script is modified in the future ...
> 
> I copied that part from run.sh and didn't think much about it. However, ...
> 
>> Or: why not use 'set' directly in the 'case' construct above?  That is,
>> instead of
>>
>>     .t00) d=0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;
>>
>> you could do:
>>
>>     .t00) set 0 10000000 a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;
> 
> ... that's a great idea: I also changed the indentation.
> Now, that part looks nicer - see below.
> 
>>> +# Create the test script from the template for this test
>>> +# by substituting the START, the END and the CKSUM.
>>> +sed \
>>> +  -e "s/__START__/$1/" \
>>> +  -e "s/__END__/$2/" \
>>> +  -e "s/__CKSUM__/$3/" \
>>> +  < "${ftdir}/run.sh" > "$testname" \
>>>
>> I'm not sure this would work in a VPATH setup sadly ...  You'd need
>> to reference $(srcdir) somewhere, but that is available only in the
>> Makefile.  Maybe you could simply make this script read from stdin
>> and write to stdout, and make the redirections in the Makefile recipe
>> itself?
> 
> Done.
> 
>>> +  && chmod a+x "$testname" \
>>> +  || exit 1
>>> +
>> Maybe you could also make the generated test read-only, so that it will
>> be more difficult for some "casual contributor" to try to modify it by
>> mistake:
>>
>>    && chmod a+x,a-w "$testname" \
>>    || exit 1
> 
> I'm not sure about that. If the user changes run.sh or create-test.sh,
> and the tests have to be rebuilt, then that would fail with "permission
> denied".
>
That is easily fixed: you should remove '$@' from the makefile recipe
(simply a "rm -f $@") before rebuilding it.  This read-only issue is
not a big deal though, so I'll stop pushing about it.

> Instead, I added a line into the template that this file is generated.
> 
> 
>>> +test -x "$testname"
>>>
>> A little too paranoid maybe?
> 
> Admitted ;-)
> 
>>> +exit $?
>>
>>> \ No newline at end of file
>>>
>> Huh?
> 
> Sorry, I was using geany, and `make syntax-check` didn't complain
> (although I'm not sure whether it inspected the new file).
> 
> Here's the new approach:
>
I've just tow more nits that is worth reporting ...

> [MEGA-SNIP]

> -$(factor_tests): tests/factor/run.sh
> +$(factor_tests): $(tf)/run.sh $(tf)/create-test.sh
>  	$(AM_V_GEN)$(MKDIR_P) $(tf)
> -	$(AM_V_at)ln -f $(srcdir)/tests/factor/run.sh $@
> +	$(AM_V_at)$(srcdir)/$(tf)/create-test.sh $@ \
>
... you should invoke the new script with $(SHELL):

    $(AM_V_at)$(SHELL) $(srcdir)/$(tf)/create-test.sh $@ \

and ...

> +	  < $(srcdir)/$(tf)/run.sh \
> +	  > $@
> +	@chmod a+x $@
>
... this should be "$(AM_V_at)chmod a+x $@" rather than "@chmod a+x $@"

Regards,
  Stefano


From MAILER-DAEMON Sat Oct 27 05:14:36 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TS2TU-0000Mz-Ml
	for mharc-coreutils@gnu.org; Sat, 27 Oct 2012 05:14:36 -0400
Received: from eggs.gnu.org ([208.118.235.92]:47950)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS2TR-0000KN-RP
	for coreutils@gnu.org; Sat, 27 Oct 2012 05:14:34 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS2TQ-00022U-RI
	for coreutils@gnu.org; Sat, 27 Oct 2012 05:14:33 -0400
Received: from mx.meyering.net ([88.168.87.75]:34788)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS2TQ-00022H-Kq
	for coreutils@gnu.org; Sat, 27 Oct 2012 05:14:32 -0400
Received: from rho (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id CC915601F4;
	Sat, 27 Oct 2012 11:14:31 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Stefano Lattarini <stefano.lattarini@gmail.com>
Subject: Re: factor tests: ugly long file names
In-Reply-To: <508B8FD3.6030100@gmail.com> (Stefano Lattarini's message of
	"Sat, 27 Oct 2012 09:40:03 +0200")
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net> <508ABE1A.8070107@bernhard-voelker.de>
	<508ACE7E.4080204@gmail.com> <508B253D.3000107@bernhard-voelker.de>
	<508B8FD3.6030100@gmail.com>
Date: Sat, 27 Oct 2012 11:14:31 +0200
Message-ID: <87txtgz37s.fsf@meyering.net>
Lines: 35
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Bernhard Voelker <mail@bernhard-voelker.de>, Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Oct 2012 09:14:34 -0000

Stefano Lattarini wrote:
>>> You can save a fork by avoiding a call to basename:
>>>
>>>     t=${testname##*/}
>>
>> Good point. I wasn't sure if that syntax is portable.
>> I know it from old dtksh days.
>>
> It is portable to any decent POSIX shell.  And I think Coreutils assumes
> that one is available on the build system.  But then, to ensure such a
> shell is actually used, you'll have to invoke your script explicitly with
> the configure-determined $(SHELL) from the make recipe below (thank you
> Solaris for keeping an old non-POSIX shell as /bin/sh, sigh).
>
> Jim, can you confirm it's OK to assume that $(SHELL) points to a POSIX
> shell in the coreutils build system?

It's even better than that.
coreutils (via init.sh) guarantees that the shell
used to invoke tests accepts $(...) syntax, so we don't
have to use the anachronistic `...`.

It appears that every shell meeting the above criteria also
supports ${var##X}, ${var#X}, ${var%%X}, etc. substitution,
since this use has been in a test since 2007:

    symlink_loop_msg=${readlink_msg#'readlink: p/1: '}

init.sh explicitly requires ${var#X} support and a couple
other shell features when $(EXEEXT) is nonempty, but I doubt
you're building on mingw.

So, yes, it is safe to use that syntax in coreutils tests/ scripts.

Thanks for reviewing.


From MAILER-DAEMON Sat Oct 27 05:25:49 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TS2eL-0001qS-UQ
	for mharc-coreutils@gnu.org; Sat, 27 Oct 2012 05:25:49 -0400
Received: from eggs.gnu.org ([208.118.235.92]:40136)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TS2eJ-0001pO-N7
	for coreutils@gnu.org; Sat, 27 Oct 2012 05:25:48 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TS2eH-0004wG-QY
	for coreutils@gnu.org; Sat, 27 Oct 2012 05:25:47 -0400
Received: from mail-ea0-f169.google.com ([209.85.215.169]:53965)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <stefano.lattarini@gmail.com>) id 1TS2eH-0004vW-I1
	for coreutils@gnu.org; Sat, 27 Oct 2012 05:25:45 -0400
Received: by mail-ea0-f169.google.com with SMTP id k11so1309637eaa.0
	for <coreutils@gnu.org>; Sat, 27 Oct 2012 02:25:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=message-id:date:from:mime-version:to:cc:subject:references
	:in-reply-to:content-type:content-transfer-encoding;
	bh=ZR/7t/M1Q11Fo3+vGcAiFa3j+HMRbRqTeBgaBgIf8Ao=;
	b=whV8MsRDAKIRjZo7IHfN8L9/E+WYf4S0Q7yGR1yPz4mJob82zc/pJzUSelPO+2uBrA
	wnLu+n9jba3mMhDzMnpHagUB7LtYy4GAwMmbo5rLvtIeNpGT49HVrsoSTJO0mGAfXeI7
	BiB2jhNIxf7W0bTWgItmcOGrwmUSq7TGsSBK1hKBPngDj2Xk9N7tebazxYjMpx04SrJ/
	OLw6H79uACaVmmIWvPQLes4llvhJY5KLwBKOI4XFfQXDZsC7JAUhn/rDWDR61H7pxvWs
	xSfR2YN/chwXkEZC5d7ciB5CucvxHoKGZLc3qOsrvB/zFLS/Esndh5xcbcj4/h2BOy5J
	TyfA==
Received: by 10.14.203.132 with SMTP id f4mr41232029eeo.11.1351329944831;
	Sat, 27 Oct 2012 02:25:44 -0700 (PDT)
Received: from [192.168.178.21]
	(host247-100-dynamic.8-87-r.retail.telecomitalia.it. [87.8.100.247])
	by mx.google.com with ESMTPS id c6sm8061990eep.17.2012.10.27.02.25.43
	(version=SSLv3 cipher=OTHER); Sat, 27 Oct 2012 02:25:44 -0700 (PDT)
Message-ID: <508BA895.90401@gmail.com>
Date: Sat, 27 Oct 2012 11:25:41 +0200
From: Stefano Lattarini <stefano.lattarini@gmail.com>
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: factor tests: ugly long file names
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net>
	<508ABE1A.8070107@bernhard-voelker.de> <508ACE7E.4080204@gmail.com>
	<508B253D.3000107@bernhard-voelker.de>
	<508B8FD3.6030100@gmail.com> <87txtgz37s.fsf@meyering.net>
In-Reply-To: <87txtgz37s.fsf@meyering.net>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.85.215.169
Cc: Bernhard Voelker <mail@bernhard-voelker.de>, Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Oct 2012 09:25:48 -0000

Hi Jim.

On 10/27/2012 11:14 AM, Jim Meyering wrote:
> Stefano Lattarini wrote:
>>>> You can save a fork by avoiding a call to basename:
>>>>
>>>>     t=${testname##*/}
>>>
>>> Good point. I wasn't sure if that syntax is portable.
>>> I know it from old dtksh days.
>>>
>> It is portable to any decent POSIX shell.  And I think Coreutils assumes
>> that one is available on the build system.  But then, to ensure such a
>> shell is actually used, you'll have to invoke your script explicitly with
>> the configure-determined $(SHELL) from the make recipe below (thank you
>> Solaris for keeping an old non-POSIX shell as /bin/sh, sigh).
>>
>> Jim, can you confirm it's OK to assume that $(SHELL) points to a POSIX
>> shell in the coreutils build system?
> 
> It's even better than that.
> coreutils (via init.sh) guarantees that the shell
> used to invoke tests accepts $(...) syntax, so we don't
> have to use the anachronistic `...`.
>
Ah, but it seems to me that 'tests/factor/create-test.sh' doesn't
use 'tests/init.sh' -- nor I'm sure it can, being 'tests/init.sh'
designed to be sourced only by test scripts :-(

It would be really nice if Autoconf 2.70 would finally ensure that
the $SHELL it sets is a true POSIX shell ...  See also:
<http://lists.gnu.org/archive/html/bug-autoconf/2012-06/msg00009.html>

> It appears that every shell meeting the above criteria also
> supports ${var##X}, ${var#X}, ${var%%X}, etc. substitution,
> since this use has been in a test since 2007:
> 
>     symlink_loop_msg=${readlink_msg#'readlink: p/1: '}
> 
> init.sh explicitly requires ${var#X} support and a couple
> other shell features when $(EXEEXT) is nonempty, but I doubt
> you're building on mingw.
> 
> So, yes, it is safe to use that syntax in coreutils tests/ scripts.
>
Is this true even in light of my observation above?

Thanks,
  Stefano


From MAILER-DAEMON Sat Oct 27 06:02:22 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TS3Di-0002fl-0M
	for mharc-coreutils@gnu.org; Sat, 27 Oct 2012 06:02:22 -0400
Received: from eggs.gnu.org ([208.118.235.92]:50300)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS3De-0002d1-Im
	for coreutils@gnu.org; Sat, 27 Oct 2012 06:02:19 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS3Dc-0005Ee-UA
	for coreutils@gnu.org; Sat, 27 Oct 2012 06:02:18 -0400
Received: from mx.meyering.net ([88.168.87.75]:34839)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS3Dc-0005Ea-JR
	for coreutils@gnu.org; Sat, 27 Oct 2012 06:02:16 -0400
Received: from rho (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id A141364118;
	Sat, 27 Oct 2012 12:02:15 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Stefano Lattarini <stefano.lattarini@gmail.com>
Subject: Re: factor tests: ugly long file names
In-Reply-To: <508BA895.90401@gmail.com> (Stefano Lattarini's message of "Sat, 
	27 Oct 2012 11:25:41 +0200")
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net> <508ABE1A.8070107@bernhard-voelker.de>
	<508ACE7E.4080204@gmail.com> <508B253D.3000107@bernhard-voelker.de>
	<508B8FD3.6030100@gmail.com> <87txtgz37s.fsf@meyering.net>
	<508BA895.90401@gmail.com>
Date: Sat, 27 Oct 2012 12:02:15 +0200
Message-ID: <87objoz108.fsf@meyering.net>
Lines: 169
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Bernhard Voelker <mail@bernhard-voelker.de>, Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Oct 2012 10:02:20 -0000

Stefano Lattarini wrote:

> Hi Jim.
>
> On 10/27/2012 11:14 AM, Jim Meyering wrote:
>> Stefano Lattarini wrote:
>>>>> You can save a fork by avoiding a call to basename:
>>>>>
>>>>>     t=${testname##*/}
>>>>
>>>> Good point. I wasn't sure if that syntax is portable.
>>>> I know it from old dtksh days.
>>>>
>>> It is portable to any decent POSIX shell.  And I think Coreutils assumes
>>> that one is available on the build system.  But then, to ensure such a
>>> shell is actually used, you'll have to invoke your script explicitly with
>>> the configure-determined $(SHELL) from the make recipe below (thank you
>>> Solaris for keeping an old non-POSIX shell as /bin/sh, sigh).
>>>
>>> Jim, can you confirm it's OK to assume that $(SHELL) points to a POSIX
>>> shell in the coreutils build system?
>>
>> It's even better than that.
>> coreutils (via init.sh) guarantees that the shell
>> used to invoke tests accepts $(...) syntax, so we don't
>> have to use the anachronistic `...`.
>>
> Ah, but it seems to me that 'tests/factor/create-test.sh' doesn't
> use 'tests/init.sh' -- nor I'm sure it can, being 'tests/init.sh'
> designed to be sourced only by test scripts :-(

Hi Stefano,

You're right.
create-test.sh is different from the others.
It is subject to the regular (strict) portability rules.
So we can *not* use that syntax there.

> It would be really nice if Autoconf 2.70 would finally ensure that
> the $SHELL it sets is a true POSIX shell ...  See also:
> <http://lists.gnu.org/archive/html/bug-autoconf/2012-06/msg00009.html>

I think that is the way to go.
Trying to identify and remember so many vagaries of shell portability
is a losing battle.

>> It appears that every shell meeting the above criteria also
>> supports ${var##X}, ${var#X}, ${var%%X}, etc. substitution,
>> since this use has been in a test since 2007:
>>
>>     symlink_loop_msg=${readlink_msg#'readlink: p/1: '}
>>
>> init.sh explicitly requires ${var#X} support and a couple
>> other shell features when $(EXEEXT) is nonempty, but I doubt
>> you're building on mingw.
>>
>> So, yes, it is safe to use that syntax in coreutils tests/ scripts.
>>
> Is this true even in light of my observation above?

It is true for all tests/ scripts except create-test.sh.

Berny,

Here are some changes I'd appreciate:
  - shorten a regexp
  - remove two mentions of tests/factor/run.sh in create-test.sh
  - change create-test.sh to take 2 arguments
  - change $testname to $test_name; more readable
  - remove useless curly braces around ${t1} ${t2}.
      The other uses are required, but not those.
  - avoid the need for backslash-escaped slashes in TEMPLATE
  - simply exec "sed"
  - remove the execute bit on run.sh
  - "never redirect directly to $@" (repeat this mantra ;-)

diff --git a/cfg.mk b/cfg.mk
index 6155ec2..54ffde1 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -111,7 +111,7 @@ sc_tests_list_consistency:
 	  for t in $(all_tests); do echo $$t; done;			\
 	  cd $(top_srcdir);						\
 	  $(SHELL) build-aux/vc-list-files tests			\
-	    | grep -Ev '^tests/(factor/run|factor/create-test|init)\.sh$$' \
+	    | grep -Ev '^tests/(factor/(run|create-test)|init)\.sh$$'	\
 	    | $(EGREP) "$$test_extensions_rx\$$";			\
 	} | sort | uniq -u | grep . && exit 1; :

diff --git a/tests/factor/create-test.sh b/tests/factor/create-test.sh
index 907396f..180e89a 100755
--- a/tests/factor/create-test.sh
+++ b/tests/factor/create-test.sh
@@ -1,13 +1,13 @@
 #!/bin/sh
 # Create the factor test scripts.
-# Used template: tests/factor/run.sh.

 # Copyright (C) 2012 Free Software Foundation, Inc.

-# Extract the test name from $1.
-testname="$1"
-t="${testname##*/}"
-t="${t%.sh}"
+test_name=$1
+template=$2
+
+# Extract the test name: remove .sh suffix from the basename.
+t=`echo "$test_name"|sed 's,.*/,,;s,\.sh$,,'`

 # prefix of 2^64
 p=184467440737
@@ -38,8 +38,8 @@ case $t in
   t06) set     60000000     70000000 689bc70d681791e5d1b8ac1316a05d0c4473d6db ;;
   t07) set     70000000     80000000 d370808f2ab8c865f64c2ff909c5722db5b7d58d ;;
   t08) set     80000000     90000000 7978aa66bf2bdb446398336ea6f02605e9a77581 ;;
-  t09) set        ${t1}        ${t1} 4622287c5f040cdb7b3bbe4d19d29a71ab277827 ;;
-  t10) set        ${t2}        ${t2} dea308253708b57afad357e8c0d2a111460ef50e ;;
+  t09) set          $t1          $t1 4622287c5f040cdb7b3bbe4d19d29a71ab277827 ;;
+  t10) set          $t2          $t2 dea308253708b57afad357e8c0d2a111460ef50e ;;
   t11) set ${p}08551616 ${p}08651615 66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1 ;;
   t12) set ${p}08651616 ${p}08751615 729228e693b1a568ecc85b199927424c7d16d410 ;;
   t13) set ${p}08751616 ${p}08851615 5a0c985017c2d285e4698f836f5a059e0b684563 ;;
@@ -67,20 +67,17 @@ case $t in
   t35) set   ${q}958336   ${q}960335 2374919a89196e1fce93adfe779cb4664556d4b6 ;;
   t36) set   ${q}960336   ${q}962335 569e4363e8d9e8830a187d9ab27365eef08abde1 ;;
   *)
-    echo "$0: error: unknown test: '$testname' -> '$t'" >&2
+    echo "$0: error: unknown test: '$test_name' -> '$t'" >&2
     exit 1
     ;;
 esac

-TEMPLATE="TEST SCRIPT DERIVED FROM THE TEMPLATE tests\/factor\/run.sh"
+TEMPLATE="TEST SCRIPT DERIVED FROM THE TEMPLATE $template"

 # Create the test script from the template for this test
 # by substituting the START, the END and the CKSUM.
-sed \
+exec sed \
   -e "s/__START__/$1/" \
   -e "s/__END__/$2/" \
   -e "s/__CKSUM__/$3/" \
-  -e "s/__TEMPLATE__/$TEMPLATE/" \
-  || exit 1
-
-exit 0
+  -e "s!__TEMPLATE__!$TEMPLATE!" "$template"
diff --git a/tests/factor/run.sh b/tests/factor/run.sh
old mode 100755
new mode 100644
diff --git a/tests/local.mk b/tests/local.mk
index 9ee696a..8fc4030 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -640,10 +640,10 @@ factor_tests = \

 $(factor_tests): $(tf)/run.sh $(tf)/create-test.sh
 	$(AM_V_GEN)$(MKDIR_P) $(tf)
-	$(AM_V_at)$(srcdir)/$(tf)/create-test.sh $@ \
-	  < $(srcdir)/$(tf)/run.sh \
-	  > $@
-	@chmod a+x $@
+	$(AM_V_at)$(SHELL) $(srcdir)/$(tf)/create-test.sh $@ \
+	  $(srcdir)/$(tf)/run.sh > $@-t
+	$(AM_V_at)chmod a+x $@-t
+	$(AM_V_at)mv $@-t $@

 CLEANFILES += $(factor_tests)


From MAILER-DAEMON Sat Oct 27 06:18:55 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TS3Tj-0006Er-Ux
	for mharc-coreutils@gnu.org; Sat, 27 Oct 2012 06:18:55 -0400
Received: from eggs.gnu.org ([208.118.235.92]:47759)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS3Tg-0006BT-TG
	for coreutils@gnu.org; Sat, 27 Oct 2012 06:18:53 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS3Tg-0000Y2-0n
	for coreutils@gnu.org; Sat, 27 Oct 2012 06:18:52 -0400
Received: from mx.meyering.net ([88.168.87.75]:34860)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS3Tf-0000Xw-Qq
	for coreutils@gnu.org; Sat, 27 Oct 2012 06:18:51 -0400
Received: from rho (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id E77CF60195;
	Sat, 27 Oct 2012 12:18:50 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: Re: factor tests: ugly long file names
In-Reply-To: <508ABE1A.8070107@bernhard-voelker.de> (Bernhard Voelker's
	message of "Fri, 26 Oct 2012 18:45:14 +0200")
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net> <508ABE1A.8070107@bernhard-voelker.de>
Date: Sat, 27 Oct 2012 12:18:50 +0200
Message-ID: <87ip9wz08l.fsf@meyering.net>
Lines: 7
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Oct 2012 10:18:53 -0000

Bernhard Voelker wrote:
> Subject: [PATCH] maint: refactor new tests for refactored factor

Oh, and the subject of that patch, while cute, could be more accurate,
e.g.,

  tests: shorten factor's inordinately-long test file names


From MAILER-DAEMON Sat Oct 27 07:38:57 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TS4jB-0004HV-Ok
	for mharc-coreutils@gnu.org; Sat, 27 Oct 2012 07:38:57 -0400
Received: from eggs.gnu.org ([208.118.235.92]:44747)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TS4j7-0004Gu-9o
	for coreutils@gnu.org; Sat, 27 Oct 2012 07:38:55 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TS4j5-0003k1-BW
	for coreutils@gnu.org; Sat, 27 Oct 2012 07:38:53 -0400
Received: from moutng.kundenserver.de ([212.227.126.187]:65208)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TS4j4-0003ju-Uk
	for coreutils@gnu.org; Sat, 27 Oct 2012 07:38:51 -0400
Received: from [192.168.2.108] (p4FF74369.dip.t-dialin.net [79.247.67.105])
	by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis)
	id 0M5Ksl-1TClKo0lTT-00z5gl; Sat, 27 Oct 2012 13:38:49 +0200
Message-ID: <508BC7C7.8080605@bernhard-voelker.de>
Date: Sat, 27 Oct 2012 13:38:47 +0200
From: Bernhard Voelker <mail@bernhard-voelker.de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: factor tests: ugly long file names
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net>
	<508ABE1A.8070107@bernhard-voelker.de> <508ACE7E.4080204@gmail.com>
	<508B253D.3000107@bernhard-voelker.de>
	<508B8FD3.6030100@gmail.com> <87txtgz37s.fsf@meyering.net>
	<508BA895.90401@gmail.com> <87objoz108.fsf@meyering.net>
In-Reply-To: <87objoz108.fsf@meyering.net>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Provags-ID: V02:K0:kATG2fbsVQeOftbJFh6ZVNLWgVMSYNAPIrsf85rNmHD
	ViD9Q1Bz+n3472d79G7YsqUJqa1DsWmLpzweD2qejSnnFVDasW
	AA67VH+AYWoHLaxMBm6fh4VBxDFierLt9MQtFiBaYsMBpH7yfs
	DhK6cT+Il8H/JG/+H6WQ3o7i9c+dBLI2QJYhp0k5pJmg1zWcRK
	UjLgjJnptMmB+l2MjXeKxSMQPEyxflIrw+y32j+lNHjWbjgpph
	zj0pUJ4t8eos+IUzdcORyA3V7z6TkxM9dwNn3rilvAVI5qgvdF
	hGXEvMzE7L1JJ78hU0P+/YPm4qefjN4e540wDPNbvjau7xHE3Y
	KwcCXyb/VCsA2DOrvxmuVCJlOMuhmc4+YZSomg2hf
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 212.227.126.187
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>,
	Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Oct 2012 11:38:56 -0000



On 10/27/2012 12:02 PM, Jim Meyering wrote:
> Berny,

Thanks for looking into this.

> Here are some changes I'd appreciate:
>   - shorten a regexp
>   - remove two mentions of tests/factor/run.sh in create-test.sh
>   - change create-test.sh to take 2 arguments
>   - change $testname to $test_name; more readable
>   - remove useless curly braces around ${t1} ${t2}.
>       The other uses are required, but not those.
>   - avoid the need for backslash-escaped slashes in TEMPLATE
>   - simply exec "sed"

Good points. Done.

I had to exempt the new test also for the backticks check:

  exclude_file_name_regexp--sc_prohibit_test_backticks = \
  -  ^tests/(init\.sh|local.mk|misc/stdbuf\.sh)$$
  +  ^tests/(init\.sh|local.mk|misc/stdbuf\.sh|factor/create-test.sh)$$

Additionally, I added this to the commit message:

  +    Besides what the subject says, this commit moves the test data
  +    for the factor tests from tests/local.mk into the directory
  +    tests/factor/ where it belongs.

and

  -    * tests/factor/run.sh: Turn this script into a template.
  +    * tests/factor/run.sh: Turn this script into a template, and
  +    therefore remove it's executable permission bit.

and listed Stefano's and your name:

+    Improved-by: Stefano Lattarini
+    Improved by: Jim Meyering

Here comes the full new patch.

Have a nice day,
Berny

>From b6a09d05d2794cc1df64a468e573729c92e37ad1 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <mail@bernhard-voelker.de>
Date: Sat, 27 Oct 2012 13:24:18 +0200
Subject: [PATCH] tests: shorten factor's inordinately-long test file names

Besides what the subject says, this commit moves the test data
for the factor tests from tests/local.mk into the directory
tests/factor/ where it belongs.

* tests/local.mk (EXTRA_DIST): Add new tests/factor/create-test.sh.
(p,q,t1,t2) Factor out the factor-related magic numbers.
(factor_tests): Rename the test names to t{00..36}.sh. Factor out
the triples of test data.
($(factor_tests)): Add dependency to new
tests/factor/create-factor.sh.
Call that script to generate the test scripts.
* tests/factor/run.sh: Turn this script into a template, and
therefore remove it's executable permission bit.
Add template variables START, END and CKSUM, replacing the code
to split the test data from the test script's file name.
Use the new template variables in the call to seq and for
creating the exp file.
* tests/factor/create-test.sh: Add new script to create the
test scripts from the template tests/factor/run.sh.
Use test data and magic numbers factored out from the above
files. Let the script also change the __TEMPLATE__ line in
run.sh to make clear that the test scripts are generated.
* cfg.mk (sc_tests_list_consistency): Exempt the new test.
(exclude_file_name_regexp--sc_prohibit_test_backticks):
Likewise.

Improved-by: Stefano Lattarini
Improved by: Jim Meyering
---
 cfg.mk                      |    4 +-
 tests/factor/create-test.sh |   83 +++++++++++++++++++++++++++++++++++++++++++
 tests/factor/run.sh         |   22 ++++++-----
 tests/local.mk              |   70 ++++++++----------------------------
 4 files changed, 112 insertions(+), 67 deletions(-)
 create mode 100755 tests/factor/create-test.sh
 mode change 100755 => 100644 tests/factor/run.sh

diff --git a/cfg.mk b/cfg.mk
index 08f6c3d..ab0f0c6 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -111,7 +111,7 @@ sc_tests_list_consistency:
 	  for t in $(all_tests); do echo $$t; done;			\
 	  cd $(top_srcdir);						\
 	  $(SHELL) build-aux/vc-list-files tests			\
-	    | grep -Ev '^tests/(factor/run|init)\.sh$$'			\
+	    | grep -Ev '^tests/(factor/(run|create-test)|init)\.sh$$'	\
 	    | $(EGREP) "$$test_extensions_rx\$$";			\
 	} | sort | uniq -u | grep . && exit 1; :

@@ -572,7 +572,7 @@ exclude_file_name_regexp--sc_prohibit_continued_string_alpha_in_column_1 = \
   ^src/(system\.h|od\.c|printf\.c)$$

 exclude_file_name_regexp--sc_prohibit_test_backticks = \
-  ^tests/(init\.sh|local.mk|misc/stdbuf\.sh)$$
+  ^tests/(init\.sh|local.mk|misc/stdbuf\.sh|factor/create-test.sh)$$

 # Exempt test.c, since it's nominally shared, and relatively static.
 exclude_file_name_regexp--sc_prohibit_operator_at_end_of_line = \
diff --git a/tests/factor/create-test.sh b/tests/factor/create-test.sh
new file mode 100755
index 0000000..180e89a
--- /dev/null
+++ b/tests/factor/create-test.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+# Create the factor test scripts.
+
+# Copyright (C) 2012 Free Software Foundation, Inc.
+
+test_name=$1
+template=$2
+
+# Extract the test name: remove .sh suffix from the basename.
+t=`echo "$test_name"|sed 's,.*/,,;s,\.sh$,,'`
+
+# prefix of 2^64
+p=184467440737
+
+# prefix of 2^96
+q=79228162514264337593543
+
+# Each of these numbers has a Pollard rho factor larger than 2^64,
+# and thus exercises some hard-to-reach code in factor.c.
+t1=170141183460469225450570946617781744489
+t2=170141183460469229545748130981302223887
+
+# Factors of the above:
+# t1: 9223372036854775421 18446744073709551709
+# t2: 9223372036854775643 18446744073709551709
+
+# Each test is a triple: lo, hi, sha1 of result.
+# The test script, run.sh, runs seq lo hi|factor|sha1sum
+# and verifies that the actual and expected checksums are the same.
+# New tests must be added to tests/local.mk (factor_tests), too.
+case $t in
+  t00) set            0     10000000 a451244522b1b662c86cb3cbb55aee3e085a61a0 ;;
+  t01) set     10000000     20000000 c792a2e02f1c8536b5121f624b04039d20187016 ;;
+  t02) set     20000000     30000000 8115e8dff97d1674134ec054598d939a2a5f6113 ;;
+  t03) set     30000000     40000000 fe7b832c8e0ed55035152c0f9ebd59de73224a60 ;;
+  t04) set     40000000     50000000 b8786d66c432e48bc5b342ee3c6752b7f096f206 ;;
+  t05) set     50000000     60000000 a74fe518c5f79873c2b9016745b88b42c8fd3ede ;;
+  t06) set     60000000     70000000 689bc70d681791e5d1b8ac1316a05d0c4473d6db ;;
+  t07) set     70000000     80000000 d370808f2ab8c865f64c2ff909c5722db5b7d58d ;;
+  t08) set     80000000     90000000 7978aa66bf2bdb446398336ea6f02605e9a77581 ;;
+  t09) set          $t1          $t1 4622287c5f040cdb7b3bbe4d19d29a71ab277827 ;;
+  t10) set          $t2          $t2 dea308253708b57afad357e8c0d2a111460ef50e ;;
+  t11) set ${p}08551616 ${p}08651615 66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1 ;;
+  t12) set ${p}08651616 ${p}08751615 729228e693b1a568ecc85b199927424c7d16d410 ;;
+  t13) set ${p}08751616 ${p}08851615 5a0c985017c2d285e4698f836f5a059e0b684563 ;;
+  t14) set ${p}08851616 ${p}08951615 0482295c514e371c98ce9fd335deed0c9c44a4f4 ;;
+  t15) set ${p}08951616 ${p}09051615 9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71 ;;
+  t16) set ${p}09051616 ${p}09151615 604366d2b1d75371d0679e6a68962d66336cd383 ;;
+  t17) set ${p}09151616 ${p}09251615 9192d2bdee930135b28d7160e6d395a7027871da ;;
+  t18) set ${p}09251616 ${p}09351615 bcf56ae55d20d700690cff4d3327b78f83fc01bf ;;
+  t19) set ${p}09351616 ${p}09451615 16b106398749e5f24d278ba7c58229ae43f650ac ;;
+  t20) set ${p}09451616 ${p}09551615 ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c ;;
+  t21) set ${p}09551616 ${p}09651615 2b6f9c11742d9de045515a6627c27a042c49f8ba ;;
+  t22) set ${p}09651616 ${p}09751615 54851acd51c4819beb666e26bc0100dc9adbc310 ;;
+  t23) set ${p}09751616 ${p}09851615 6939c2a7afd2d81f45f818a159b7c5226f83a50b ;;
+  t24) set ${p}09851616 ${p}09951615 0f2c8bc011d2a45e2afa01459391e68873363c6c ;;
+  t25) set ${p}09951616 ${p}10051615 630dc2ad72f4c222bad1405e6c5bea590f92a98c ;;
+  t26) set   ${q}940336   ${q}942335 63cbd6313d78247b04d63bbbac50cb8f8d33ff71 ;;
+  t27) set   ${q}942336   ${q}944335 0d03d63653767173182491b86fa18f8f680bb036 ;;
+  t28) set   ${q}944336   ${q}946335 ca43bd38cd9f97cc5bb63613cb19643578640f0b ;;
+  t29) set   ${q}946336   ${q}948335 86d59545a0c13567fa96811821ea5cde950611b1 ;;
+  t30) set   ${q}948336   ${q}950335 c3740e702fa9c97e6cf00150860e0b936a141a6b ;;
+  t31) set   ${q}950336   ${q}952335 551c3c4c4640d86fda311b5c3006dac45505c0ce ;;
+  t32) set   ${q}952336   ${q}954335 b1b0b00463c2f853d70ef9c4f7a96de5cb614156 ;;
+  t33) set   ${q}954336   ${q}956335 8938a484a9ef6bb16478091d294fcde9f8ecea69 ;;
+  t34) set   ${q}956336   ${q}958335 d1ae6bc712d994f35edf55c785d71ddf31f16535 ;;
+  t35) set   ${q}958336   ${q}960335 2374919a89196e1fce93adfe779cb4664556d4b6 ;;
+  t36) set   ${q}960336   ${q}962335 569e4363e8d9e8830a187d9ab27365eef08abde1 ;;
+  *)
+    echo "$0: error: unknown test: '$test_name' -> '$t'" >&2
+    exit 1
+    ;;
+esac
+
+TEMPLATE="TEST SCRIPT DERIVED FROM THE TEMPLATE $template"
+
+# Create the test script from the template for this test
+# by substituting the START, the END and the CKSUM.
+exec sed \
+  -e "s/__START__/$1/" \
+  -e "s/__END__/$2/" \
+  -e "s/__CKSUM__/$3/" \
+  -e "s!__TEMPLATE__!$TEMPLATE!" "$template"
diff --git a/tests/factor/run.sh b/tests/factor/run.sh
old mode 100755
new mode 100644
index 6ff24c3..33ec8cd
--- a/tests/factor/run.sh
+++ b/tests/factor/run.sh
@@ -1,11 +1,14 @@
 #!/bin/sh
+
+# === THIS IS A __TEMPLATE__ ===
+
 # Test the factor rewrite.
-# Expect to be invoked via a file whose basename matches
-# /^(\d+)\-(\d+)\-([\da-f]{40})\.sh$/
 # The test is to run this command
-# seq $1 $2 | factor | shasum -c --status <(echo $3  -)
+# seq $START $END | factor | shasum -c --status <(echo $CKSUM  -)
 # I.e., to ensure that the factorizations of integers $1..$2
 # match what we expect.
+#
+# See: tests/factor/create-test.sh

 # Copyright (C) 2012 Free Software Foundation, Inc.

@@ -16,15 +19,14 @@ very_expensive_

 print_ver_ factor seq

-# Remove the ".sh" suffix:
-t=${ME_%.sh}
+# Template variables.
+START=__START__
+  END=__END__
+CKSUM=__CKSUM__

-# Make IFS include "-", so that a simple "set" will separate the args:
-IFS=-$IFS
-set $t
-echo "$3  -" > exp
+echo "$CKSUM  -" > exp

 f=1
-seq $1 $2 | factor | shasum -c --status exp && f=0
+seq $START $END | factor | shasum -c --status exp && f=0

 Exit $f
diff --git a/tests/local.mk b/tests/local.mk
index f31c8b0..8fc4030 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -96,6 +96,7 @@ EXTRA_DIST +=			\
   tests/d_type-check		\
   tests/envvar-check		\
   tests/factor/run.sh		\
+  tests/factor/create-test.sh	\
   tests/filefrag-extent-compare \
   tests/fiemap-capable		\
   tests/init.sh			\
@@ -625,65 +626,24 @@ all_tests =					\
   tests/touch/trailing-slash.sh			\
   $(all_root_tests)

-# prefix of 2^64
-p = 184467440737
-# prefix of 2^96
-q = 79228162514264337593543
-
-# Each of these numbers has a Pollard rho factor larger than 2^64,
-# and thus exercises some hard-to-reach code in factor.c.
-t1 = 170141183460469225450570946617781744489
-t2 = 170141183460469229545748130981302223887
-# Factors of the above:
-# t1: 9223372036854775421 18446744073709551709
-# t2: 9223372036854775643 18446744073709551709
-
-# Each tests is a triple: lo, hi, sha1 of result.
-# The test script, run.sh, runs seq lo hi|factor|sha1sum
-# and verifies that the actual and expected checksums are the same.
+# See tests/factor/create-test.sh.
 tf = tests/factor
 factor_tests = \
-  $(tf)/0-10000000-a451244522b1b662c86cb3cbb55aee3e085a61a0.sh \
-  $(tf)/10000000-20000000-c792a2e02f1c8536b5121f624b04039d20187016.sh \
-  $(tf)/20000000-30000000-8115e8dff97d1674134ec054598d939a2a5f6113.sh \
-  $(tf)/30000000-40000000-fe7b832c8e0ed55035152c0f9ebd59de73224a60.sh \
-  $(tf)/40000000-50000000-b8786d66c432e48bc5b342ee3c6752b7f096f206.sh \
-  $(tf)/50000000-60000000-a74fe518c5f79873c2b9016745b88b42c8fd3ede.sh \
-  $(tf)/60000000-70000000-689bc70d681791e5d1b8ac1316a05d0c4473d6db.sh \
-  $(tf)/70000000-80000000-d370808f2ab8c865f64c2ff909c5722db5b7d58d.sh \
-  $(tf)/80000000-90000000-7978aa66bf2bdb446398336ea6f02605e9a77581.sh \
-  $(tf)/$(t1)-$(t1)-4622287c5f040cdb7b3bbe4d19d29a71ab277827.sh \
-  $(tf)/$(t2)-$(t2)-dea308253708b57afad357e8c0d2a111460ef50e.sh \
-  $(tf)/$(p)08551616-$(p)08651615-66c57cd58f4fb572df7f088d17e4f4c1d4f01bb1.sh \
-  $(tf)/$(p)08651616-$(p)08751615-729228e693b1a568ecc85b199927424c7d16d410.sh \
-  $(tf)/$(p)08751616-$(p)08851615-5a0c985017c2d285e4698f836f5a059e0b684563.sh \
-  $(tf)/$(p)08851616-$(p)08951615-0482295c514e371c98ce9fd335deed0c9c44a4f4.sh \
-  $(tf)/$(p)08951616-$(p)09051615-9c0e1105ac7c45e27e7bbeb5e213f530d2ad1a71.sh \
-  $(tf)/$(p)09051616-$(p)09151615-604366d2b1d75371d0679e6a68962d66336cd383.sh \
-  $(tf)/$(p)09151616-$(p)09251615-9192d2bdee930135b28d7160e6d395a7027871da.sh \
-  $(tf)/$(p)09251616-$(p)09351615-bcf56ae55d20d700690cff4d3327b78f83fc01bf.sh \
-  $(tf)/$(p)09351616-$(p)09451615-16b106398749e5f24d278ba7c58229ae43f650ac.sh \
-  $(tf)/$(p)09451616-$(p)09551615-ad2c6ed63525f8e7c83c4c416e7715fa1bebc54c.sh \
-  $(tf)/$(p)09551616-$(p)09651615-2b6f9c11742d9de045515a6627c27a042c49f8ba.sh \
-  $(tf)/$(p)09651616-$(p)09751615-54851acd51c4819beb666e26bc0100dc9adbc310.sh \
-  $(tf)/$(p)09751616-$(p)09851615-6939c2a7afd2d81f45f818a159b7c5226f83a50b.sh \
-  $(tf)/$(p)09851616-$(p)09951615-0f2c8bc011d2a45e2afa01459391e68873363c6c.sh \
-  $(tf)/$(p)09951616-$(p)10051615-630dc2ad72f4c222bad1405e6c5bea590f92a98c.sh \
-  $(tf)/$(q)940336-$(q)942335-63cbd6313d78247b04d63bbbac50cb8f8d33ff71.sh \
-  $(tf)/$(q)942336-$(q)944335-0d03d63653767173182491b86fa18f8f680bb036.sh \
-  $(tf)/$(q)944336-$(q)946335-ca43bd38cd9f97cc5bb63613cb19643578640f0b.sh \
-  $(tf)/$(q)946336-$(q)948335-86d59545a0c13567fa96811821ea5cde950611b1.sh \
-  $(tf)/$(q)948336-$(q)950335-c3740e702fa9c97e6cf00150860e0b936a141a6b.sh \
-  $(tf)/$(q)950336-$(q)952335-551c3c4c4640d86fda311b5c3006dac45505c0ce.sh \
-  $(tf)/$(q)952336-$(q)954335-b1b0b00463c2f853d70ef9c4f7a96de5cb614156.sh \
-  $(tf)/$(q)954336-$(q)956335-8938a484a9ef6bb16478091d294fcde9f8ecea69.sh \
-  $(tf)/$(q)956336-$(q)958335-d1ae6bc712d994f35edf55c785d71ddf31f16535.sh \
-  $(tf)/$(q)958336-$(q)960335-2374919a89196e1fce93adfe779cb4664556d4b6.sh \
-  $(tf)/$(q)960336-$(q)962335-569e4363e8d9e8830a187d9ab27365eef08abde1.sh
+  $(tf)/t00.sh $(tf)/t01.sh $(tf)/t02.sh $(tf)/t03.sh $(tf)/t04.sh \
+  $(tf)/t05.sh $(tf)/t06.sh $(tf)/t07.sh $(tf)/t08.sh $(tf)/t09.sh \
+  $(tf)/t10.sh $(tf)/t11.sh $(tf)/t12.sh $(tf)/t13.sh $(tf)/t14.sh \
+  $(tf)/t15.sh $(tf)/t16.sh $(tf)/t17.sh $(tf)/t18.sh $(tf)/t19.sh \
+  $(tf)/t20.sh $(tf)/t21.sh $(tf)/t22.sh $(tf)/t23.sh $(tf)/t24.sh \
+  $(tf)/t25.sh $(tf)/t26.sh $(tf)/t27.sh $(tf)/t28.sh $(tf)/t29.sh \
+  $(tf)/t30.sh $(tf)/t31.sh $(tf)/t32.sh $(tf)/t33.sh $(tf)/t34.sh \
+  $(tf)/t35.sh $(tf)/t36.sh

-$(factor_tests): tests/factor/run.sh
+$(factor_tests): $(tf)/run.sh $(tf)/create-test.sh
 	$(AM_V_GEN)$(MKDIR_P) $(tf)
-	$(AM_V_at)ln -f $(srcdir)/tests/factor/run.sh $@
+	$(AM_V_at)$(SHELL) $(srcdir)/$(tf)/create-test.sh $@ \
+	  $(srcdir)/$(tf)/run.sh > $@-t
+	$(AM_V_at)chmod a+x $@-t
+	$(AM_V_at)mv $@-t $@

 CLEANFILES += $(factor_tests)

-- 
1.7.7



From MAILER-DAEMON Sat Oct 27 11:46:48 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TS8b2-0004KH-2V
	for mharc-coreutils@gnu.org; Sat, 27 Oct 2012 11:46:48 -0400
Received: from eggs.gnu.org ([208.118.235.92]:60582)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS8ay-0004H0-OK
	for coreutils@gnu.org; Sat, 27 Oct 2012 11:46:46 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS8ax-0006Ci-Hj
	for coreutils@gnu.org; Sat, 27 Oct 2012 11:46:44 -0400
Received: from mx.meyering.net ([88.168.87.75]:35214)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TS8ax-0006CT-6e
	for coreutils@gnu.org; Sat, 27 Oct 2012 11:46:43 -0400
Received: from rho (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 5623D60161;
	Sat, 27 Oct 2012 17:46:41 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: Re: factor tests: ugly long file names
In-Reply-To: <508BC7C7.8080605@bernhard-voelker.de> (Bernhard Voelker's
	message of "Sat, 27 Oct 2012 13:38:47 +0200")
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net> <508ABE1A.8070107@bernhard-voelker.de>
	<508ACE7E.4080204@gmail.com> <508B253D.3000107@bernhard-voelker.de>
	<508B8FD3.6030100@gmail.com> <87txtgz37s.fsf@meyering.net>
	<508BA895.90401@gmail.com> <87objoz108.fsf@meyering.net>
	<508BC7C7.8080605@bernhard-voelker.de>
Date: Sat, 27 Oct 2012 17:46:41 +0200
Message-ID: <87625vzzmm.fsf@meyering.net>
Lines: 77
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>,
	Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Oct 2012 15:46:46 -0000

Bernhard Voelker wrote:
...
> Here comes the full new patch.
>
> Have a nice day,
> Berny
>
>>From b6a09d05d2794cc1df64a468e573729c92e37ad1 Mon Sep 17 00:00:00 2001
> From: Bernhard Voelker <mail@bernhard-voelker.de>
> Date: Sat, 27 Oct 2012 13:24:18 +0200
> Subject: [PATCH] tests: shorten factor's inordinately-long test file names
>
> Besides what the subject says, this commit moves the test data
> for the factor tests from tests/local.mk into the directory
> tests/factor/ where it belongs.
>
> * tests/local.mk (EXTRA_DIST): Add new tests/factor/create-test.sh.
> (p,q,t1,t2) Factor out the factor-related magic numbers.
> (factor_tests): Rename the test names to t{00..36}.sh. Factor out
> the triples of test data.
> ($(factor_tests)): Add dependency to new
> tests/factor/create-factor.sh.
> Call that script to generate the test scripts.
> * tests/factor/run.sh: Turn this script into a template, and
> therefore remove it's executable permission bit.
> Add template variables START, END and CKSUM, replacing the code
> to split the test data from the test script's file name.
> Use the new template variables in the call to seq and for
> creating the exp file.
> * tests/factor/create-test.sh: Add new script to create the
> test scripts from the template tests/factor/run.sh.
> Use test data and magic numbers factored out from the above
> files. Let the script also change the __TEMPLATE__ line in
> run.sh to make clear that the test scripts are generated.
> * cfg.mk (sc_tests_list_consistency): Exempt the new test.
> (exclude_file_name_regexp--sc_prohibit_test_backticks):
> Likewise.
>
> Improved-by: Stefano Lattarini
> Improved by: Jim Meyering
> ---
>  cfg.mk                      |    4 +-
>  tests/factor/create-test.sh |   83 +++++++++++++++++++++++++++++++++++++++++++
>  tests/factor/run.sh         |   22 ++++++-----
>  tests/local.mk              |   70 ++++++++----------------------------
>  4 files changed, 112 insertions(+), 67 deletions(-)
>  create mode 100755 tests/factor/create-test.sh
>  mode change 100755 => 100644 tests/factor/run.sh
>
> diff --git a/cfg.mk b/cfg.mk
> index 08f6c3d..ab0f0c6 100644
> --- a/cfg.mk
> +++ b/cfg.mk
> @@ -111,7 +111,7 @@ sc_tests_list_consistency:
>  	  for t in $(all_tests); do echo $$t; done;			\
>  	  cd $(top_srcdir);						\
>  	  $(SHELL) build-aux/vc-list-files tests			\
> -	    | grep -Ev '^tests/(factor/run|init)\.sh$$'			\
> +	    | grep -Ev '^tests/(factor/(run|create-test)|init)\.sh$$'	\
>  	    | $(EGREP) "$$test_extensions_rx\$$";			\
>  	} | sort | uniq -u | grep . && exit 1; :
>
> @@ -572,7 +572,7 @@ exclude_file_name_regexp--sc_prohibit_continued_string_alpha_in_column_1 = \
>    ^src/(system\.h|od\.c|printf\.c)$$
>
>  exclude_file_name_regexp--sc_prohibit_test_backticks = \
> -  ^tests/(init\.sh|local.mk|misc/stdbuf\.sh)$$
> +  ^tests/(init\.sh|local.mk|misc/stdbuf\.sh|factor/create-test.sh)$$

Thanks again.
I noticed that there were two unescaped '.'s in that regexp,
so I fixed the one in '.mk' and factored out the '\\.sh' suffix:

-  ^tests/(init\.sh|local.mk|misc/stdbuf\.sh|factor/create-test.sh)$$
+  ^tests/(local\.mk|(init|misc/stdbuf|factor/create-test)\.sh)$$

With that, I pushed your change.


From MAILER-DAEMON Sat Oct 27 11:57:24 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TS8lI-0005Ns-7T
	for mharc-coreutils@gnu.org; Sat, 27 Oct 2012 11:57:24 -0400
Received: from eggs.gnu.org ([208.118.235.92]:42256)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TS8lG-0005MH-Hg
	for coreutils@gnu.org; Sat, 27 Oct 2012 11:57:23 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TS8lF-0000nS-Hp
	for coreutils@gnu.org; Sat, 27 Oct 2012 11:57:22 -0400
Received: from moutng.kundenserver.de ([212.227.17.9]:64343)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mail@bernhard-voelker.de>) id 1TS8lF-0000n9-8f
	for coreutils@gnu.org; Sat, 27 Oct 2012 11:57:21 -0400
Received: from [192.168.2.108] (p4FF74369.dip.t-dialin.net [79.247.67.105])
	by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis)
	id 0M2oZ4-1TACCX1uGE-00ruGc; Sat, 27 Oct 2012 17:57:20 +0200
Message-ID: <508C045E.3090902@bernhard-voelker.de>
Date: Sat, 27 Oct 2012 17:57:18 +0200
From: Bernhard Voelker <mail@bernhard-voelker.de>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Re: factor tests: ugly long file names
References: <5089C756.7050205@bernhard-voelker.de>
	<87mwz94oo8.fsf@meyering.net>
	<508ABE1A.8070107@bernhard-voelker.de> <508ACE7E.4080204@gmail.com>
	<508B253D.3000107@bernhard-voelker.de>
	<508B8FD3.6030100@gmail.com> <87txtgz37s.fsf@meyering.net>
	<508BA895.90401@gmail.com> <87objoz108.fsf@meyering.net>
	<508BC7C7.8080605@bernhard-voelker.de>
	<87625vzzmm.fsf@meyering.net>
In-Reply-To: <87625vzzmm.fsf@meyering.net>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Provags-ID: V02:K0:nYlW3eXKcjk1KkBguuKlFz8UCLhT1lIe+7/1iuJZxH5
	V7bqv6bd+/375OEic9AT6awx63iMgLREcCqfyrNnkHt4BWMR8e
	Sike4jat3aH4m18BLESnLBzAQnOjcyRciKvH77RV1NQyQNJuNn
	rF8U6tKI50lxB+wkqH3t/xa4wXEHUdGev6ynIAbCNEIZYMScXI
	MflRxJQhyZtCLXEwIUZw4ipJ5xdCoX2zP2uj9U9PE00in65iQ5
	D9utjgq9oaFjEd7BY91lXtc2t77ewukFdIl3knlUK2ILk4LE9o
	vE+bYjiYgPBjY5+CwckXuVqF8t9mcyUTyaPZrFZ30+A7J/eptG
	sETE5CPXTQHPOI3SMwJHVdbrKw2sQUTc128VkzisK
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 212.227.17.9
Cc: Stefano Lattarini <stefano.lattarini@gmail.com>,
	Coreutils <coreutils@gnu.org>
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 27 Oct 2012 15:57:23 -0000



On 10/27/2012 05:46 PM, Jim Meyering wrote:
> Bernhard Voelker wrote:
> ...
>> Here comes the full new patch.
[...]

> Thanks again.
> I noticed that there were two unescaped '.'s in that regexp,
> so I fixed the one in '.mk' and factored out the '\\.sh' suffix:
> 
> -  ^tests/(init\.sh|local.mk|misc/stdbuf\.sh|factor/create-test.sh)$$
> +  ^tests/(local\.mk|(init|misc/stdbuf|factor/create-test)\.sh)$$

Oops, thanks!

> With that, I pushed your change.

Thanks & have a nice day,
Berny



From MAILER-DAEMON Sun Oct 28 20:48:40 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TSdWy-00037r-Lf
	for mharc-coreutils@gnu.org; Sun, 28 Oct 2012 20:48:40 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37492)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TSdWw-00036x-T0
	for coreutils@gnu.org; Sun, 28 Oct 2012 20:48:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TSdWv-0000wl-Uy
	for coreutils@gnu.org; Sun, 28 Oct 2012 20:48:38 -0400
Received: from mx1.redhat.com ([209.132.183.28]:57554)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TSdWv-0000wb-My
	for coreutils@gnu.org; Sun, 28 Oct 2012 20:48:37 -0400
Received: from int-mx02.intmail.prod.int.phx2.redhat.com
	(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9T0mYtL002499
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Sun, 28 Oct 2012 20:48:34 -0400
Received: from pb-n5110.redhat.com (ovpn-116-16.ams2.redhat.com [10.36.116.16])
	by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9T0mXsm013240; Sun, 28 Oct 2012 20:48:33 -0400
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
To: coreutils@gnu.org
Subject: [PATCH] tests: use sub-second timeouts to speed up a timeout test
Date: Mon, 29 Oct 2012 00:48:31 +0000
Message-Id: <1351471711-12291-1-git-send-email-P@draigBrady.com>
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 29 Oct 2012 00:48:39 -0000

* tests/misc/timeout.sh: Take advantage of recent support for
sub-second timeouts to decrease runtime from about 6s to 2s.
---
 tests/misc/timeout.sh |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/misc/timeout.sh b/tests/misc/timeout.sh
index 3fa8522..662b4be 100755
--- a/tests/misc/timeout.sh
+++ b/tests/misc/timeout.sh
@@ -33,18 +33,18 @@ timeout 10 sh -c 'exit 2'
 test $? = 2 || fail=1
 
 # timeout
-timeout 1 sleep 10
+timeout .1 sleep 10
 test $? = 124 || fail=1
 
 # exit status propagation even on timeout
-timeout --exit-status 1 sleep 10
+timeout --exit-status .1 sleep 10
 # exit status should be 128+TERM
 test $? = 124 && fail=1
 
 # kill delay. Note once the initial timeout triggers,
 # the exit status will be 124 even if the command
 # exits on its own accord.
-timeout -s0 -k1 1 sleep 10
+timeout -s0 -k1 .1 sleep 10
 test $? = 124 && fail=1
 
 # Ensure 'timeout' is immune to parent's SIGCHLD handler
@@ -57,7 +57,7 @@ test $? = 124 && fail=1
 ) || fail=1
 
 # Don't be confused when starting off with a child (Bug#9098).
-out=$(sleep 1 & exec timeout 2 sh -c 'sleep 3; echo foo')
+out=$(sleep .1 & exec timeout .5 sh -c 'sleep 2; echo foo')
 status=$?
 test "$out" = "" && test $status = 124 || fail=1
 
-- 
1.7.6.4



From MAILER-DAEMON Tue Oct 30 10:44:28 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TTD3M-0001Ok-64
	for mharc-coreutils@gnu.org; Tue, 30 Oct 2012 10:44:28 -0400
Received: from eggs.gnu.org ([208.118.235.92]:59429)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TTD39-0001I9-FB
	for coreutils@gnu.org; Tue, 30 Oct 2012 10:44:26 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TTD31-0002E0-06
	for coreutils@gnu.org; Tue, 30 Oct 2012 10:44:15 -0400
Received: from mx1.redhat.com ([209.132.183.28]:51849)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <dwalsh@redhat.com>) id 1TTD30-0002Ch-Jb
	for coreutils@gnu.org; Tue, 30 Oct 2012 10:44:06 -0400
Received: from int-mx02.intmail.prod.int.phx2.redhat.com
	(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9UEi2Dd016459
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 30 Oct 2012 10:44:03 -0400
Received: from [10.16.60.53] (redsox.boston.devel.redhat.com [10.16.60.53])
	by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
	id q9UEi1cK031331; Tue, 30 Oct 2012 10:44:01 -0400
Message-ID: <508FE7AF.5000003@redhat.com>
Date: Tue, 30 Oct 2012 10:43:59 -0400
From: Daniel J Walsh <dwalsh@redhat.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:16.0) Gecko/20121016 Thunderbird/16.0.1
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
Subject: Make coretutils work better with SELinux.
References: <50733664.5000503@redhat.com> <50733CC1.9000506@draigBrady.com>
	<87626jolel.fsf@rho.meyering.net> <507D5C87.3030501@redhat.com>
	<87wqyqwnik.fsf@rho.meyering.net> <5081CBB0.2020507@redhat.com>
	<877gqly15j.fsf@rho.meyering.net>
In-Reply-To: <877gqly15j.fsf@rho.meyering.net>
X-Enigmail-Version: 1.4.5
Content-Type: multipart/mixed; boundary="------------040301020904010101060107"
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 30 Oct 2012 14:44:27 -0000

This is a multi-part message in MIME format.
--------------040301020904010101060107
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

For some reason I could not get git to take more then a one line comment.
This is the comment I was trying to add.


        build: Change -Z opt w/out arg label target with default label

        The -Z without argument will ask SELinux what the default label of the i
        dest object should be and then attempt to change it.

        The -Z with an optional context will create all targets with the
        optional label. This is still supported for backwards compatability.

        The mv command does not support the optional argument.


BTW, it looks like coreutils has removed -ZCONTEXT from cp, if I had my
druthers, I would make all commands just use -Z and not allow the optional
arg.  Then -Z would just set the default label.  I would bet that no one in
history has executed a command like:

mkdir -Zunconfined_u:object_r:httpd_user_content_t:s0 ~/myweb


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlCP568ACgkQrlYvE4MpobOSDgCfZE0KRKJobvMW4Fb8i7j6Hfd9
fHIAoID4PBCyoqc0omlu07kst5ouAjJp
=Hc8s
-----END PGP SIGNATURE-----

--------------040301020904010101060107
Content-Type: text/x-patch;
 name="0001-build-Change-Z-opt-w-out-arg-label-target-with-defau.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0001-build-Change-Z-opt-w-out-arg-label-target-with-defau.pa";
 filename*1="tch"

>From aa0c25ceeda99cb9df0e089aa927a4ac382c67bf Mon Sep 17 00:00:00 2001
From: rhatdan <dwalsh@redhat.com>
Date: Tue, 30 Oct 2012 09:48:15 -0400
Subject: [PATCH] build: Change -Z opt w/out arg label target with default
 label

---
 src/chcon.c   |   2 +-
 src/copy.c    |  52 +++++-------
 src/copy.h    |   3 +
 src/cp.c      |  35 ++++++--
 src/install.c |  16 ++--
 src/local.mk  |  15 +++-
 src/mkdir.c   |  19 ++++-
 src/mkfifo.c  |  13 ++-
 src/mknod.c   |  14 ++-
 src/mv.c      |  16 +++-
 src/runcon.c  |   2 +-
 src/selinux.c | 269 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/selinux.h |  26 ++++++
 13 files changed, 425 insertions(+), 57 deletions(-)
 create mode 100644 src/selinux.c
 create mode 100644 src/selinux.h

diff --git a/src/chcon.c b/src/chcon.c
index 34e92e4..0cf8fa6 100644
--- a/src/chcon.c
+++ b/src/chcon.c
@@ -355,7 +355,7 @@ Usage: %s [OPTION]... CONTEXT FILE...\n\
 "),
         program_name, program_name, program_name);
       fputs (_("\
-Change the security context of each FILE to CONTEXT.\n\
+Change the SELinux security context of each FILE to CONTEXT.\n\
 With --reference, change the security context of each FILE to that of RFILE.\n\
 \n\
 "), stdout);
diff --git a/src/copy.c b/src/copy.c
index 16aed03..c91a756 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -60,6 +60,7 @@
 #include "write-any-file.h"
 #include "areadlink.h"
 #include "yesno.h"
+#include "selinux.h"
 
 #if USE_XATTR
 # include <attr/error_context.h>
@@ -837,41 +838,18 @@ copy_reg (char const *src_name, char const *dst_name,
          1) the src context may prohibit writing, and
          2) because it's more consistent to use the same context
          that is used when the destination file doesn't already exist.  */
-      if (x->preserve_security_context && 0 <= dest_desc)
+      if ((x->set_security_context || x->preserve_security_context) && 0 <= dest_desc)
         {
           bool all_errors = (!x->data_copy_required
                              || x->require_preserve_context);
           bool some_errors = !all_errors && !x->reduce_diagnostics;
-          security_context_t con = NULL;
 
-          if (getfscreatecon (&con) < 0)
-            {
-              if (all_errors || (some_errors && !errno_unsupported (errno)))
-                error (0, errno, _("failed to get file system create context"));
-              if (x->require_preserve_context)
-                {
-                  return_val = false;
-                  goto close_src_and_dst_desc;
-                }
-            }
-
-          if (con)
-            {
-              if (fsetfilecon (dest_desc, con) < 0)
-                {
-                  if (all_errors || (some_errors && !errno_unsupported (errno)))
-                    error (0, errno,
-                           _("failed to set the security context of %s to %s"),
-                           quote_n (0, dst_name), quote_n (1, con));
-                  if (x->require_preserve_context)
-                    {
-                      return_val = false;
-                      freecon (con);
-                      goto close_src_and_dst_desc;
-                    }
-                }
-              freecon (con);
-            }
+          if (restorecon(dst_name, 0, x->preserve_security_context) < 0)  {
+            if (all_errors || (some_errors && !errno_unsupported (errno)))
+              error (0, errno, _("failed to set file system context on %s"), quote_n (0, dst_name));
+            return_val = false;
+            goto close_src_and_dst_desc;
+          }
         }
 
       if (dest_desc < 0 && x->unlink_dest_after_failed_open)
@@ -892,6 +870,9 @@ copy_reg (char const *src_name, char const *dst_name,
 
   if (*new_dst)
     {
+      if (x->set_security_context && (! x->require_preserve_context))
+        defaultcon(dst_name, dst_mode);
+
     open_with_O_CREAT:;
 
       int open_flags = O_WRONLY | O_CREAT | O_BINARY;
@@ -974,6 +955,9 @@ copy_reg (char const *src_name, char const *dst_name,
       goto close_src_and_dst_desc;
     }
 
+  if (x->set_security_context && ! x->preserve_security_context)
+    restorecon(dst_name, 1, false);
+
   /* --attributes-only overrides --reflink.  */
   if (data_copy_required && x->reflink_mode)
     {
@@ -2092,6 +2076,9 @@ copy_internal (char const *src_name, char const *dst_name,
             emit_verbose (src_name, dst_name,
                           backup_succeeded ? dst_backup : NULL);
 
+          if (x->set_security_context)
+            restorecon(dst_name, 1, false);
+
           if (rename_succeeded)
             *rename_succeeded = true;
 
@@ -2231,6 +2218,11 @@ copy_internal (char const *src_name, char const *dst_name,
             return false;
         }
     }
+  else
+  {
+    if (x->set_security_context)
+      restorecon(dst_name, 1, false);
+  }
 
   if (S_ISDIR (src_mode))
     {
diff --git a/src/copy.h b/src/copy.h
index 440d3bb..d6044aa 100644
--- a/src/copy.h
+++ b/src/copy.h
@@ -159,6 +159,9 @@ struct cp_options
   bool preserve_timestamps;
   bool explicit_no_preserve_mode;
 
+  /* If true, attempt to set specified security context */
+  bool set_security_context;
+
   /* Enabled for mv, and for cp by the --preserve=links option.
      If true, attempt to preserve in the destination files any
      logical hard links between the source files.  If used with cp's
diff --git a/src/cp.c b/src/cp.c
index 61b31af..017e4da 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -141,6 +141,7 @@ static struct option const long_opts[] =
   {"target-directory", required_argument, NULL, 't'},
   {"update", no_argument, NULL, 'u'},
   {"verbose", no_argument, NULL, 'v'},
+  {GETOPT_SELINUX_CONTEXT_OPTION_DECL},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -229,6 +230,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
                                  destination file is missing\n\
   -v, --verbose                explain what is being done\n\
   -x, --one-file-system        stay on this file system\n\
+  -Z, --context[=CONTEXT]      set security context of destination file to default type or to CONTEXT if specified\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -786,6 +788,7 @@ cp_option_init (struct cp_options *x)
   x->explicit_no_preserve_mode = false;
   x->preserve_security_context = false;
   x->require_preserve_context = false;
+  x->set_security_context = false;
   x->preserve_xattr = false;
   x->reduce_diagnostics = false;
   x->require_preserve_xattr = false;
@@ -877,8 +880,10 @@ decode_preserve_arg (char const *arg, struct cp_options *x, bool on_off)
           break;
 
         case PRESERVE_CONTEXT:
-          x->preserve_security_context = on_off;
-          x->require_preserve_context = on_off;
+          if (! x->set_security_context) {
+            x->preserve_security_context = on_off;
+            x->require_preserve_context = on_off;
+          }
           break;
 
         case PRESERVE_XATTR:
@@ -892,7 +897,7 @@ decode_preserve_arg (char const *arg, struct cp_options *x, bool on_off)
           x->preserve_ownership = on_off;
           x->preserve_links = on_off;
           x->explicit_no_preserve_mode = !on_off;
-          if (selinux_enabled)
+          if (selinux_enabled && (! x->set_security_context))
             x->preserve_security_context = on_off;
           x->preserve_xattr = on_off;
           break;
@@ -935,7 +940,7 @@ main (int argc, char **argv)
      we'll actually use backup_suffix_string.  */
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
 
-  while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:T",
+  while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:TZ::",
                            long_opts, NULL))
          != -1)
     {
@@ -962,7 +967,7 @@ main (int argc, char **argv)
           x.preserve_mode = true;
           x.preserve_timestamps = true;
           x.require_preserve = true;
-          if (selinux_enabled)
+          if (selinux_enabled && (! x.set_security_context))
              x.preserve_security_context = true;
           x.preserve_xattr = true;
           x.reduce_diagnostics = true;
@@ -1092,6 +1097,26 @@ main (int argc, char **argv)
           x.one_file_system = true;
           break;
 
+
+        case 'Z':
+          /* politely decline if we're not on a selinux-enabled kernel. */
+          if( !selinux_enabled ) {
+             fprintf( stderr, "Warning:  ignoring --context (-Z). "
+                              "It requires a SELinux enabled kernel.\n" );
+             break;
+         }
+         if (optarg) {
+           /* if there's a security_context given set new path
+              components to that context, too */
+           if ( setfscreatecon(optarg) < 0 ) {
+             (void) fprintf(stderr, _("cannot set default security context %s\n"), optarg);
+             exit( 1 );
+           }
+         }
+         x.set_security_context = true;
+         x.preserve_security_context = false;
+         break;
+
         case 'S':
           make_backups = true;
           backup_suffix_string = optarg;
diff --git a/src/install.c b/src/install.c
index 8ea5491..a1511bf 100644
--- a/src/install.c
+++ b/src/install.c
@@ -280,6 +280,7 @@ cp_option_init (struct cp_options *x)
   x->data_copy_required = true;
   x->require_preserve = false;
   x->require_preserve_context = false;
+  x->set_security_context = false;
   x->require_preserve_xattr = false;
   x->recursive = false;
   x->sparse_mode = SPARSE_AUTO;
@@ -641,7 +642,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
 "), stdout);
       fputs (_("\
       --preserve-context  preserve SELinux security context\n\
-  -Z, --context=CONTEXT  set SELinux security context of files and directories\
+  -Z, --context[=CONTEXT] set SELinux security context of files and directories\
 \n\
 "), stdout);
 
@@ -783,7 +784,7 @@ main (int argc, char **argv)
      we'll actually use backup_suffix_string.  */
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
 
-  while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z:", long_options,
+  while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z::", long_options,
                               NULL)) != -1)
     {
       switch (optc)
@@ -860,8 +861,11 @@ main (int argc, char **argv)
                              "this kernel is not SELinux-enabled"));
               break;
             }
+          if ( x.set_security_context || scontext ) {
+             (void) fprintf(stderr, "%s: cannot force target context and preserve it\n", argv[0]);
+             exit( 1 );
+          }
           x.preserve_security_context = true;
-          use_default_selinux_context = false;
           break;
         case 'Z':
           if ( ! selinux_enabled)
@@ -870,8 +874,10 @@ main (int argc, char **argv)
                              "this kernel is not SELinux-enabled"));
               break;
             }
-          scontext = optarg;
-          use_default_selinux_context = false;
+          if (optarg)
+                  scontext = optarg;
+          else
+                  x.set_security_context = true;
           break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
diff --git a/src/local.mk b/src/local.mk
index f40f681..113544a 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -306,6 +306,10 @@ RELEASE_YEAR = \
   `sed -n '/.*COPYRIGHT_YEAR = \([0-9][0-9][0-9][0-9]\) };/s//\1/p' \
     $(top_srcdir)/lib/version-etc.c`
 
+selinux_sources = \
+  src/selinux.c \
+  src/selinux.h
+
 copy_sources = \
   src/copy.c \
   src/cp-hash.c \
@@ -317,12 +321,12 @@ copy_sources = \
 # to install before applying any user-specified name transformations.
 
 transform = s/ginstall/install/; $(program_transform_name)
-src_ginstall_SOURCES = src/install.c src/prog-fprintf.c $(copy_sources)
+src_ginstall_SOURCES = src/install.c src/prog-fprintf.c $(copy_sources) $(selinux_sources)
 
 # This is for the '[' program.  Automake transliterates '[' and '/' to '_'.
 src___SOURCES = src/lbracket.c
 
-src_cp_SOURCES = src/cp.c $(copy_sources)
+src_cp_SOURCES = src/cp.c $(copy_sources) $(selinux_sources)
 src_dir_SOURCES = src/ls.c src/ls-dir.c
 src_vdir_SOURCES = src/ls.c src/ls-vdir.c
 src_id_SOURCES = src/id.c src/group-list.c
@@ -335,12 +339,15 @@ src_kill_SOURCES = src/kill.c src/operand2sig.c
 src_realpath_SOURCES = src/realpath.c src/relpath.c src/relpath.h
 src_timeout_SOURCES = src/timeout.c src/operand2sig.c
 
-src_mv_SOURCES = src/mv.c src/remove.c $(copy_sources)
+src_mv_SOURCES = src/mv.c src/remove.c $(copy_sources) $(selinux_sources)
 src_rm_SOURCES = src/rm.c src/remove.c
 
-src_mkdir_SOURCES = src/mkdir.c src/prog-fprintf.c
+src_mkdir_SOURCES = src/mkdir.c src/prog-fprintf.c $(selinux_sources)
 src_rmdir_SOURCES = src/rmdir.c src/prog-fprintf.c
 
+src_mkfifo_SOURCES = src/mkfifo.c $(selinux_sources)
+src_mknod_SOURCES = src/mknod.c $(selinux_sources)
+
 src_df_SOURCES = src/df.c src/find-mount-point.c
 src_stat_SOURCES = src/stat.c src/find-mount-point.c
 
diff --git a/src/mkdir.c b/src/mkdir.c
index 32f79d4..80e9fa5 100644
--- a/src/mkdir.c
+++ b/src/mkdir.c
@@ -29,6 +29,7 @@
 #include "prog-fprintf.h"
 #include "quote.h"
 #include "savewd.h"
+#include "selinux.h"
 
 /* The official name of this program (e.g., no 'g' prefix).  */
 #define PROGRAM_NAME "mkdir"
@@ -65,8 +66,8 @@ Mandatory arguments to long options are mandatory for short options too.\n\
   -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask\n\
   -p, --parents     no error if existing, make parent directories as needed\n\
   -v, --verbose     print a message for each created directory\n\
-  -Z, --context=CTX  set the SELinux security context of each created\n\
-                      directory to CTX\n\
+  -Z, --context[=CTX]  set the SELinux security context of each created\n\
+                      directory to default type or to CTX if specified\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -91,6 +92,9 @@ struct mkdir_options
   /* File mode bits affected by MODE.  */
   mode_t mode_bits;
 
+  /* Set the SELinux File Context.  */
+  int set_security_context;
+
   /* If not null, format to use when reporting newly made directories.  */
   char const *created_directory_format;
 };
@@ -113,6 +117,9 @@ static int
 make_ancestor (char const *dir, char const *component, void *options)
 {
   struct mkdir_options const *o = options;
+
+  if (o->set_security_context)
+    defaultcon(dir, S_IFDIR);
   int r = mkdir (component, o->ancestor_mode);
   if (r == 0)
     {
@@ -146,6 +153,7 @@ main (int argc, char **argv)
   options.mode = S_IRWXUGO;
   options.mode_bits = 0;
   options.created_directory_format = NULL;
+  options.set_security_context = false;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -155,7 +163,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  while ((optc = getopt_long (argc, argv, "pm:vZ:", longopts, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "pm:vZ::", longopts, NULL)) != -1)
     {
       switch (optc)
         {
@@ -169,7 +177,10 @@ main (int argc, char **argv)
           options.created_directory_format = _("created directory %s");
           break;
         case 'Z':
-          scontext = optarg;
+          if (optarg)
+            scontext = optarg;
+          else
+            options.set_security_context = true;
           break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
diff --git a/src/mkfifo.c b/src/mkfifo.c
index e524c44..bd51a53 100644
--- a/src/mkfifo.c
+++ b/src/mkfifo.c
@@ -26,6 +26,7 @@
 #include "error.h"
 #include "modechange.h"
 #include "quote.h"
+#include "selinux.h"
 
 /* The official name of this program (e.g., no 'g' prefix).  */
 #define PROGRAM_NAME "mkfifo"
@@ -60,7 +61,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
   -m, --mode=MODE    set file permission bits to MODE, not a=rw - umask\n\
 "), stdout);
       fputs (_("\
-  -Z, --context=CTX  set the SELinux security context of each NAME to CTX\n\
+  -Z, --context[=CTX]  set the SELinux security context of each NAME to default type or CTX if specified\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -74,6 +75,7 @@ main (int argc, char **argv)
 {
   mode_t newmode;
   char const *specified_mode = NULL;
+  int set_security_context = false;
   int exit_status = EXIT_SUCCESS;
   int optc;
   security_context_t scontext = NULL;
@@ -86,7 +88,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  while ((optc = getopt_long (argc, argv, "m:Z:", longopts, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "m:Z::", longopts, NULL)) != -1)
     {
       switch (optc)
         {
@@ -94,7 +96,10 @@ main (int argc, char **argv)
           specified_mode = optarg;
           break;
         case 'Z':
-          scontext = optarg;
+          if (optarg)
+            scontext = optarg;
+          else
+            set_security_context = true;
           break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -128,6 +133,8 @@ main (int argc, char **argv)
     }
 
   for (; optind < argc; ++optind)
+    if (set_security_context)
+      defaultcon(argv[optind], S_IFIFO);
     if (mkfifo (argv[optind], newmode) != 0)
       {
         error (0, errno, _("cannot create fifo %s"), quote (argv[optind]));
diff --git a/src/mknod.c b/src/mknod.c
index dc158b4..b1b35eb 100644
--- a/src/mknod.c
+++ b/src/mknod.c
@@ -27,6 +27,7 @@
 #include "modechange.h"
 #include "quote.h"
 #include "xstrtol.h"
+#include "selinux.h"
 
 /* The official name of this program (e.g., no 'g' prefix).  */
 #define PROGRAM_NAME "mknod"
@@ -62,7 +63,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
   -m, --mode=MODE    set file permission bits to MODE, not a=rw - umask\n\
 "), stdout);
       fputs (_("\
-  -Z, --context=CTX  set the SELinux security context of NAME to CTX\n\
+  -Z, --context[=CTX]  set the SELinux security context of NAME to default type or to CTX if specified\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -94,6 +95,7 @@ main (int argc, char **argv)
   int expected_operands;
   mode_t node_type;
   security_context_t scontext = NULL;
+  int set_security_context = false;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -103,7 +105,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  while ((optc = getopt_long (argc, argv, "m:Z:", longopts, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "m:Z::", longopts, NULL)) != -1)
     {
       switch (optc)
         {
@@ -111,7 +113,10 @@ main (int argc, char **argv)
           specified_mode = optarg;
           break;
         case 'Z':
-          scontext = optarg;
+          if (optarg)
+            scontext = optarg;
+          else
+            set_security_context = true;
           break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -212,6 +217,9 @@ main (int argc, char **argv)
           error (EXIT_FAILURE, 0, _("invalid device %s %s"), s_major, s_minor);
 #endif
 
+        if (set_security_context)
+          defaultcon(argv[optind], node_type);
+
         if (mknod (argv[optind], newmode | node_type, device) != 0)
           error (EXIT_FAILURE, errno, "%s", quote (argv[optind]));
       }
diff --git a/src/mv.c b/src/mv.c
index 5b08fdd..2711d9f 100644
--- a/src/mv.c
+++ b/src/mv.c
@@ -55,6 +55,7 @@ static bool remove_trailing_slashes;
 static struct option const long_options[] =
 {
   {"backup", optional_argument, NULL, 'b'},
+  {"context", no_argument, NULL, 'Z'},
   {"force", no_argument, NULL, 'f'},
   {"interactive", no_argument, NULL, 'i'},
   {"no-clobber", no_argument, NULL, 'n'},
@@ -120,6 +121,7 @@ cp_option_init (struct cp_options *x)
   x->preserve_timestamps = true;
   x->explicit_no_preserve_mode= false;
   x->preserve_security_context = selinux_enabled;
+  x->set_security_context = false;
   x->reduce_diagnostics = false;
   x->data_copy_required = true;
   x->require_preserve = false;  /* FIXME: maybe make this an option */
@@ -317,6 +319,7 @@ If you specify more than one of -i, -f, -n, only the final one takes effect.\n\
                                  than the destination file or when the\n\
                                  destination file is missing\n\
   -v, --verbose                explain what is being done\n\
+  -Z, --context                set security context of destination file to default type\n \
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -351,6 +354,7 @@ main (int argc, char **argv)
   bool no_target_directory = false;
   int n_files;
   char **file;
+  bool selinux_enabled = (0 < is_selinux_enabled ());
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -369,7 +373,7 @@ main (int argc, char **argv)
      we'll actually use backup_suffix_string.  */
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
 
-  while ((c = getopt_long (argc, argv, "bfint:uvS:T", long_options, NULL))
+  while ((c = getopt_long (argc, argv, "bfint:uvS:TZ", long_options, NULL))
          != -1)
     {
       switch (c)
@@ -418,6 +422,16 @@ main (int argc, char **argv)
           make_backups = true;
           backup_suffix_string = optarg;
           break;
+        case 'Z':
+          /* politely decline if we're not on a selinux-enabled kernel. */
+          if( !selinux_enabled ) {
+             fprintf( stderr, "Warning:  ignoring --context (-Z). "
+                              "It requires a SELinux enabled kernel.\n" );
+             break;
+          }
+          x.preserve_security_context = false;
+          x.set_security_context = true;
+          break;
         case_GETOPT_HELP_CHAR;
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
         default:
diff --git a/src/runcon.c b/src/runcon.c
index 875441f..7162f65 100644
--- a/src/runcon.c
+++ b/src/runcon.c
@@ -85,7 +85,7 @@ Usage: %s CONTEXT COMMAND [args]\n\
   or:  %s [ -c ] [-u USER] [-r ROLE] [-t TYPE] [-l RANGE] COMMAND [args]\n\
 "), program_name, program_name);
       fputs (_("\
-Run a program in a different security context.\n\
+Run a program in a different SELinux security context.\n\
 With neither CONTEXT nor COMMAND, print the current security context.\n\
 \n\
   CONTEXT            Complete security context\n\
diff --git a/src/selinux.c b/src/selinux.c
new file mode 100644
index 0000000..6045dd5
--- /dev/null
+++ b/src/selinux.c
@@ -0,0 +1,269 @@
+/* selinux - core functions for maintaining SELinux labelking
+   Copyright (C) 2012 Red Hat, 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 <http://www.gnu.org/licenses/>.  */
+
+/* Written by Daniel Walsh <dwalsh@redhat.com> */
+
+#include <config.h>
+#include <selinux/selinux.h>
+#include <selinux/flask.h>
+#include <selinux/context.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include "selinux.h"
+
+#include "error.h"
+#include "system.h"
+#include "fts.h"
+
+/*
+  This function has being added to libselinux-2.1.12-5, but is here
+  for support with older versions of SELinux
+
+  Translates a mode into an Internal SELinux security_class definition.
+  Returns 0 on failure, with errno set to EINVAL.
+*/
+static security_class_t mode_to_security_class(mode_t m) {
+
+  if (S_ISREG(m))
+    return string_to_security_class("file");
+  if (S_ISDIR(m))
+    return string_to_security_class("dir");
+  if (S_ISCHR(m))
+    return string_to_security_class("chr_file");
+  if (S_ISBLK(m))
+    return string_to_security_class("blk_file");
+  if (S_ISFIFO(m))
+    return string_to_security_class("fifo_file");
+  if (S_ISLNK(m))
+    return string_to_security_class("lnk_file");
+  if (S_ISSOCK(m))
+    return string_to_security_class("sock_file");
+
+  errno=EINVAL;
+  return 0;
+}
+
+/*
+  This function takes a path and a mode and then asks SELinux what the label
+  of the path object would be if the current process label created it.
+  it then returns the label.
+
+  Returns -1 on failure. errno will be set approptiately.
+*/
+
+static int computecon(char const *path, mode_t mode, security_context_t *con) {
+  security_context_t scon = NULL;
+  security_context_t tcon = NULL;
+  security_class_t tclass;
+  int rc = -1;
+
+  char *dir = strdup(path);
+  if (!dir)
+    goto quit;
+  if (getcon(&scon) < 0)
+    goto quit;
+  if (getfilecon(dirname((char *) dir), &tcon) < 0)
+    goto quit;
+  tclass = mode_to_security_class(mode);
+  if (!tclass)
+    goto quit;
+  rc = security_compute_create(scon, tcon, tclass, con);
+
+quit:
+  free(dir);
+  freecon(scon);
+  freecon(tcon);
+  return rc;
+}
+
+/*
+  This function takes a path and a mode, it asks calls computecon to get the
+  label of the path object if the current process created it, then it calls
+  matchpathcon to get the default type for the object.  It substitutes the
+  default type into label.  It tells the SELinux Kernel to label all new file
+  system objects created by the current process with this label.
+
+  Returns -1 on failure. errno will be set approptiately.
+*/
+int defaultcon (char const *path, mode_t mode) {
+  int rc = -1;
+  security_context_t scon = NULL, tcon = NULL;
+  context_t scontext = NULL, tcontext = NULL;
+
+  rc = matchpathcon(path, mode,  &scon);
+  if (rc < 0)
+    goto quit;
+  rc = computecon(path, mode,  &tcon);
+  if (rc < 0)
+    goto quit;
+  scontext = context_new(scon);
+  rc = -1;
+  if (!scontext)
+    goto quit;
+  tcontext = context_new(tcon);
+  if (!tcontext)
+    goto quit;
+
+  context_type_set(tcontext, context_type_get(scontext));
+  rc = setfscreatecon (context_str(tcontext));
+
+//  printf("defaultcon %s %s\n", path, context_str(tcontext));
+quit:
+  if (scontext)
+    context_free(scontext);
+  if (scontext)
+    context_free(tcontext);
+  freecon(scon);
+  freecon(tcon);
+  return rc;
+}
+
+/*
+  This function takes a path of an existing file system object, and a boolean
+  that indicates whether the function should preserve the objects label or
+  generate a new label using matchpathcon.  If the function
+  is called with preserve, it will ask the SELinux Kernel what the default label
+  for all objects created should be and then sets the label on the object.
+  Otherwise it calls matchpathcon on the object to ask the system what the
+  default label should be, extracts the type field and then modifies the file
+  system object.
+
+  Returns -1 on failure. errno will be set approptiately.
+*/
+static int restorecon_private (char const *path, bool preserve) {
+  int rc = -1;
+  struct stat sb;
+  security_context_t scon = NULL, tcon = NULL;
+  context_t scontext = NULL, tcontext = NULL;
+  int fd;
+
+  if (preserve) {
+    if (getfscreatecon (&tcon) < 0)
+      return rc;
+    rc = lsetfilecon (path, tcon);
+    freecon(tcon);
+    return rc;
+  }
+
+  fd = open (path, O_RDONLY | O_NOFOLLOW);
+  if (!fd && (errno != ELOOP))
+    goto quit;
+
+  if (fd) {
+    rc = fstat (fd, &sb);
+    if (rc < 0)
+      goto quit;
+  } else {
+    rc = lstat (path, &sb);
+    if (rc < 0)
+      goto quit;
+  }
+
+  rc = matchpathcon(path, sb.st_mode,  &scon);
+  if (rc < 0)
+    goto quit;
+  scontext = context_new(scon);
+  rc = -1;
+  if (!scontext)
+    goto quit;
+
+  if (fd) {
+    rc = fgetfilecon (fd, &tcon);
+    if (!rc)
+      goto quit;
+  } else  {
+    rc = lgetfilecon (path, &tcon);
+    if (!rc)
+      goto quit;
+  }
+  tcontext = context_new(tcon);
+  if (!tcontext)
+    goto quit;
+
+  context_type_set(tcontext, context_type_get(scontext));
+
+  if (fd)
+        rc = fsetfilecon (fd, context_str(tcontext));
+  else
+        rc = lsetfilecon (path, context_str(tcontext));
+
+//  printf("restorcon %s %s\n", path, context_str(tcontext));
+quit:
+  close(fd);
+  if (scontext)
+    context_free(scontext);
+  if (scontext)
+    context_free(tcontext);
+  freecon(scon);
+  freecon(tcon);
+  return rc;
+}
+
+/*
+  This function takes three parameters:
+  Path of an existing file system object.
+  A boolean indicating whether it should call restorecon_private recursively
+  or not.
+  A boolean that indicates whether the function should preserve the objects
+  label or generate a new label using matchpathcon.
+
+  If Recurse is selected and the file system object is a directory, restorecon
+  calls restorecon_private on every file system object in the directory.
+
+  Returns false on failure. errno will be set approptiately.
+*/
+bool restorecon (char const *path, bool recurse, bool preserve) {
+  const char *mypath[2] = { path, NULL };
+  FTS *fts;
+  bool ok = true;
+
+  if (!recurse)
+    return restorecon_private(path, preserve);
+
+  fts = fts_open ((char *const *)mypath, FTS_PHYSICAL, NULL);
+  while (1)
+    {
+      FTSENT *ent;
+
+      ent = fts_read (fts);
+      if (ent == NULL)
+        {
+          if (errno != 0)
+            {
+              /* FIXME: try to give a better message  */
+              error (0, errno, _("fts_read failed"));
+              ok = false;
+            }
+          break;
+        }
+
+      ok &= restorecon_private(fts->fts_path, preserve);
+    }
+
+  if (fts_close (fts) != 0)
+    {
+      error (0, errno, _("fts_close failed"));
+      ok = false;
+    }
+
+  return ok;
+}
diff --git a/src/selinux.h b/src/selinux.h
new file mode 100644
index 0000000..c032c05
--- /dev/null
+++ b/src/selinux.h
@@ -0,0 +1,26 @@
+/* selinux - core functions for maintaining SELinux labelking
+   Copyright (C) 2012 Red Hat, 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 <http://www.gnu.org/licenses/>.  */
+
+/* Written by Daniel Walsh <dwalsh@redhat.com> */
+
+#ifndef COREUTILS_SELINUX_H
+#define COREUTILS_SELINUX_H
+
+#include <stdbool.h>
+#include <sys/stat.h>
+extern bool restorecon (char const *path, bool recurse, bool preserve);
+extern int defaultcon (char const *path, mode_t mode);
+#endif
-- 
1.7.12.1


--------------040301020904010101060107--


From MAILER-DAEMON Wed Oct 31 20:54:16 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TTj32-0003AQ-8I
	for mharc-coreutils@gnu.org; Wed, 31 Oct 2012 20:54:16 -0400
Received: from eggs.gnu.org ([208.118.235.92]:39570)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TTj2x-0003AH-Av
	for coreutils@gnu.org; Wed, 31 Oct 2012 20:54:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TTj2w-0004jl-96
	for coreutils@gnu.org; Wed, 31 Oct 2012 20:54:11 -0400
Received: from mx1.redhat.com ([209.132.183.28]:49705)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <P@draigBrady.com>) id 1TTj2w-0004jA-01
	for coreutils@gnu.org; Wed, 31 Oct 2012 20:54:10 -0400
Received: from int-mx12.intmail.prod.int.phx2.redhat.com
	(int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qA10s7uK004889
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Wed, 31 Oct 2012 20:54:07 -0400
Received: from [10.36.116.79] (ovpn-116-79.ams2.redhat.com [10.36.116.79])
	by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id qA10s4HV014408
	(version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO);
	Wed, 31 Oct 2012 20:54:06 -0400
Message-ID: <5091C82C.9030104@draigBrady.com>
Date: Thu, 01 Nov 2012 00:54:04 +0000
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@draigBrady.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version: 1.0
To: Daniel J Walsh <dwalsh@redhat.com>
Subject: Re: Make coretutils work better with SELinux.
References: <50733664.5000503@redhat.com> <50733CC1.9000506@draigBrady.com>
	<87626jolel.fsf@rho.meyering.net> <507D5C87.3030501@redhat.com>
	<87wqyqwnik.fsf@rho.meyering.net> <5081CBB0.2020507@redhat.com>
	<877gqly15j.fsf@rho.meyering.net> <508FE7AF.5000003@redhat.com>
In-Reply-To: <508FE7AF.5000003@redhat.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
	qA10s7uK004889
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 209.132.183.28
Cc: coreutils@gnu.org
X-BeenThere: coreutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: GNU coreutils General Discussion <coreutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/coreutils>
List-Post: <mailto:coreutils@gnu.org>
List-Help: <mailto:coreutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/coreutils>,
	<mailto:coreutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 01 Nov 2012 00:54:15 -0000

On 10/30/2012 02:43 PM, Daniel J Walsh wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> For some reason I could not get git to take more then a one line commen=
t.
> This is the comment I was trying to add.
>
>
>          build: Change -Z opt w/out arg label target with default label
>
>          The -Z without argument will ask SELinux what the default labe=
l of the i
>          dest object should be and then attempt to change it.
>
>          The -Z with an optional context will create all targets with t=
he
>          optional label. This is still supported for backwards compatab=
ility.
>
>          The mv command does not support the optional argument.
>
>
> BTW, it looks like coreutils has removed -ZCONTEXT from cp, if I had my
> druthers, I would make all commands just use -Z and not allow the optio=
nal
> arg.  Then -Z would just set the default label.  I would bet that no on=
e in
> history has executed a command like:
>
> mkdir -Zunconfined_u:object_r:httpd_user_content_t:s0 ~/myweb

Thanks for the update.

Short options with optional args are very problematic.
It would mean `cp -aZ` was OK while `cp -Za` was not etc.
Also in Red Hat distros, `cp -Z` requires an arg, so changing that
would mean that older scripts that used `cp -Z blah...` would
break with newer cp, as a space is not allowed for optional args.

For that reason I would keep -Z and --context as is,
but deprecate them for the commands that set a context,
and add a new --new-context option that could take the optional arg:

In that way, -Z can continue to be used as it is commonly
with commands like `ls` etc. to _read_ the context.
Whereas the currently rare form of {mkdir,cp,install} -Z context:to_write
can be deprecated in favor of:

     --new-context[=3DCONTEXT]
        set security context to CONTEXT, or set context to
        the system default for the destination.

I'm mildly in favor of introducing --new-context, over just
making --context take an optional arg (so that it's obvious
a new context is being set, rather than one being copied),
but I'm strongly against making -Z take an optional arg.

cheers,
P=E1draig.


