From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 21 17:07:56 2010 Received: (at submit) by debbugs.gnu.org; 21 Dec 2010 22:07:56 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PVAN9-0005SB-NE for submit@debbugs.gnu.org; Tue, 21 Dec 2010 17:07:55 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PVAN7-0005S0-C2 for submit@debbugs.gnu.org; Tue, 21 Dec 2010 17:07:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PVATR-0008Uz-CB for submit@debbugs.gnu.org; Tue, 21 Dec 2010 17:14:26 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([199.232.76.165]:43720) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PVATR-0008Uv-9V for submit@debbugs.gnu.org; Tue, 21 Dec 2010 17:14:25 -0500 Received: from [140.186.70.92] (port=34691 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PVATQ-0002Ak-AD for bug-coreutils@gnu.org; Tue, 21 Dec 2010 17:14:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PVATP-0008Ub-1F for bug-coreutils@gnu.org; Tue, 21 Dec 2010 17:14:24 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]:45171) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PVATO-0008TN-JX for bug-coreutils@gnu.org; Tue, 21 Dec 2010 17:14:22 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 8278C39E8108 for ; Tue, 21 Dec 2010 14:14:20 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jw2Wbmmsqldi for ; Tue, 21 Dec 2010 14:14:19 -0800 (PST) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id BD87139E8083 for ; Tue, 21 Dec 2010 14:14:19 -0800 (PST) Message-ID: <4D1126B7.90403@cs.ucla.edu> Date: Tue, 21 Dec 2010 14:14:15 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: bug-coreutils@gnu.org Subject: [PATCH] getlimits: port to hosts with very wide int, or non-ASCII Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Spam-Score: -4.6 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.6 (----) I haven't pushed this, since the portability bugs it fixes aren't triggered on any hosts that I know of, and we're currently just fixing known bugs. >From dc02fc920e6f866e0e0ed407681ef5c4795e4e77 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 21 Dec 2010 13:53:34 -0800 Subject: [PATCH] getlimits: port to hosts with very wide int, or non-ASCII * src/getlimits.c (decimal_ascii_add): Remove, replacing with ... (decimal_absval_add_one): New function, with different signature, which does not assume ASCII. All callers changed. (print_int): Remove assumptions that integers fit in 206 bits, and that characters are ASCII. These assumptions are portable in practice but are easy to remove here. --- src/getlimits.c | 74 ++++++++++++++++++------------------------------------- 1 files changed, 24 insertions(+), 50 deletions(-) diff --git a/src/getlimits.c b/src/getlimits.c index 93d4035..986a5d7 100644 --- a/src/getlimits.c +++ b/src/getlimits.c @@ -79,53 +79,31 @@ Output platform dependent limits in a format useful for shell scripts.\n\ exit (status); } -/* Add absolute values of ascii decimal strings. - * Strings can have leading spaces. - * If any string has a '-' it's preserved in the output: - * I.E. - * 1 + 1 -> 2 - * -1 + -1 -> -2 - * -1 + 1 -> -2 - * 1 + -1 -> -2 - */ -static char * -decimal_ascii_add (const char *str1, const char *str2) +/* Add one to the absolute value of the number whose textual + representation is BUF + 1. Do this in-place, in the buffer. + Return a pointer to the result, which is normally BUF + 1, but is + BUF if the representation grew in size. */ +static char const * +decimal_absval_add_one (char *buf) { - int len1 = strlen (str1); - int len2 = strlen (str2); - int rlen = MAX (len1, len2) + 3; /* space for extra digit or sign + NUL */ - char *result = xmalloc (rlen); - char *rp = result + rlen - 1; - const char *d1 = str1 + len1 - 1; - const char *d2 = str2 + len2 - 1; - int carry = 0; - *rp = '\0'; - - while (1) - { - char c1 = (d1 < str1 ? ' ' : (*d1 == '-' ? ' ' : *d1--)); - char c2 = (d2 < str2 ? ' ' : (*d2 == '-' ? ' ' : *d2--)); - char t1 = c1 + c2 + carry; /* ASCII digits are BCD */ - if (!c_isdigit (c1) && !c_isdigit (c2) && !carry) - break; - carry = t1 > '0' + '9' || t1 == ' ' + '9' + 1; - t1 += 6 * carry; - *--rp = (t1 & 0x0F) | 0x30; /* top nibble to ASCII */ - } - if ((d1 >= str1 && *d1 == '-') || (d2 >= str2 && (*d2 == '-'))) - *--rp = '-'; - - if (rp != result) - memmove (result, rp, rlen - (rp - result)); - + bool negative = (buf[1] == '-'); + char *absnum = buf + 1 + negative; + char *p = absnum + strlen (absnum); + absnum[-1] = '0'; + while (*--p == '9') + *p = '0'; + ++*p; + char *result = MIN (absnum, p); + if (negative) + *--result = '-'; return result; } int main (int argc, char **argv) { - char limit[64]; /* big enough for 128 bit integers at least */ - char *oflow; + char limit[1 + MAX (INT_BUFSIZE_BOUND (intmax_t), + INT_BUFSIZE_BOUND (uintmax_t))]; initialize_main (&argc, &argv); set_program_name (argv[0]); @@ -140,18 +118,14 @@ main (int argc, char **argv) usage, AUTHORS, (char const *) NULL); #define print_int(TYPE) \ - snprintf (limit, sizeof limit, "%"PRIuMAX, (uintmax_t)TYPE##_MAX); \ - printf (#TYPE"_MAX=%s\n", limit); \ - oflow = decimal_ascii_add (limit, "1"); \ - printf (#TYPE"_OFLOW=%s\n", oflow); \ - free (oflow); \ + sprintf (limit + 1, "%"PRIuMAX, (uintmax_t) TYPE##_MAX); \ + printf (#TYPE"_MAX=%s\n", limit + 1); \ + printf (#TYPE"_OFLOW=%s\n", decimal_absval_add_one (limit)); \ if (TYPE##_MIN) \ { \ - snprintf (limit, sizeof limit, "%"PRIdMAX, (intmax_t)TYPE##_MIN); \ - printf (#TYPE"_MIN=%s\n", limit); \ - oflow = decimal_ascii_add (limit, "-1"); \ - printf (#TYPE"_UFLOW=%s\n", oflow); \ - free (oflow); \ + sprintf (limit + 1, "%"PRIdMAX, (intmax_t) TYPE##_MIN); \ + printf (#TYPE"_MIN=%s\n", limit + 1); \ + printf (#TYPE"_UFLOW=%s\n", decimal_absval_add_one (limit)); \ } #define print_float(TYPE) \ -- 1.7.2 From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 21 17:55:30 2010 Received: (at 7701-done) by debbugs.gnu.org; 21 Dec 2010 22:55:31 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PVB7C-0006U8-3m for submit@debbugs.gnu.org; Tue, 21 Dec 2010 17:55:30 -0500 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1PVB79-0006Tw-Ph for 7701-done@debbugs.gnu.org; Tue, 21 Dec 2010 17:55:28 -0500 Received: (qmail 35799 invoked from network); 21 Dec 2010 23:01:59 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 21 Dec 2010 23:01:59 -0000 Message-ID: <4D113119.5070103@draigBrady.com> Date: Tue, 21 Dec 2010 22:58:33 +0000 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#7701: [PATCH] getlimits: port to hosts with very wide int, or non-ASCII References: <4D1126B7.90403@cs.ucla.edu> In-Reply-To: <4D1126B7.90403@cs.ucla.edu> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 7701-done Cc: 7701-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) On 21/12/10 22:14, Paul Eggert wrote: > I haven't pushed this, since the portability bugs it fixes aren't triggered on > any hosts that I know of, and we're currently just fixing known bugs. Thanks for the cleanup Paul. Your 'add' routine is less general but also simpler, so you're free to push that after the imminent release. Mildly related to this is; speeding up seq. That might be able to use the more general routine (without allocs) in certain cases. It might be simple/faster than using gmp? cheers, Pádraig. p.s. savannah is down ATM From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 21 20:40:08 2010 Received: (at 7701-done) by debbugs.gnu.org; 22 Dec 2010 01:40:09 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PVDgW-0001lR-Ig for submit@debbugs.gnu.org; Tue, 21 Dec 2010 20:40:08 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PVDgU-0001ks-0I for 7701-done@debbugs.gnu.org; Tue, 21 Dec 2010 20:40:06 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 857A139E80F9; Tue, 21 Dec 2010 17:46:38 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zdFdjT3k5SD2; Tue, 21 Dec 2010 17:46:38 -0800 (PST) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 2846B39E80DB; Tue, 21 Dec 2010 17:46:38 -0800 (PST) Message-ID: <4D11587D.2050200@cs.ucla.edu> Date: Tue, 21 Dec 2010 17:46:37 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= Subject: Re: bug#7701: [PATCH] getlimits: port to hosts with very wide int, or non-ASCII References: <4D1126B7.90403@cs.ucla.edu> <4D113119.5070103@draigBrady.com> In-Reply-To: <4D113119.5070103@draigBrady.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.0 (---) X-Debbugs-Envelope-To: 7701-done Cc: 7701-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.9 (--) On 12/21/2010 02:58 PM, P=C3=A1draig Brady wrote: > Mildly related to this is; speeding up seq. Oh *yeah*. Seq is abysmally slow, and could probably be sped up by a factor of 10 without too much effort. Maybe I'll assign that to my students; it's a nice little project. From unknown Fri Jun 20 19:50:18 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 19 Jan 2011 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator