From unknown Wed Jun 18 23:08:23 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#24311 <24311@debbugs.gnu.org> To: bug#24311 <24311@debbugs.gnu.org> Subject: Status: [PATCH] maint: accommodate LP64 systems Reply-To: bug#24311 <24311@debbugs.gnu.org> Date: Thu, 19 Jun 2025 06:08:23 +0000 retitle 24311 [PATCH] maint: accommodate LP64 systems reassign 24311 diffutils submitter 24311 Peter Rosin severity 24311 normal tag 24311 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 26 04:42:10 2016 Received: (at submit) by debbugs.gnu.org; 26 Aug 2016 08:42:10 +0000 Received: from localhost ([127.0.0.1]:41030 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdCiH-000752-K5 for submit@debbugs.gnu.org; Fri, 26 Aug 2016 04:42:10 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56731) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdCiF-00074o-U5 for submit@debbugs.gnu.org; Fri, 26 Aug 2016 04:42:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bdCi8-0003Au-Ez for submit@debbugs.gnu.org; Fri, 26 Aug 2016 04:42:02 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:33170) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdCi8-0003Ap-BR for submit@debbugs.gnu.org; Fri, 26 Aug 2016 04:42:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdCi5-0007iB-4k for bug-diffutils@gnu.org; Fri, 26 Aug 2016 04:41:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bdChz-0003AH-4M for bug-diffutils@gnu.org; Fri, 26 Aug 2016 04:41:56 -0400 Received: from mail.lysator.liu.se ([2001:6b0:17:f0a0::3]:46587) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdChy-000395-KI for bug-diffutils@gnu.org; Fri, 26 Aug 2016 04:41:51 -0400 Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 5F7084000E; Fri, 26 Aug 2016 10:41:38 +0200 (CEST) Received: from localhost.localdomain (217-210-101-82-no95.business.telia.com [217.210.101.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id EC4E04000C; Fri, 26 Aug 2016 10:41:36 +0200 (CEST) From: Peter Rosin To: bug-diffutils@gnu.org Subject: [PATCH] maint: accommodate LP64 systems Date: Fri, 26 Aug 2016 10:41:24 +0200 Message-Id: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> X-Mailer: git-send-email 2.1.4 X-Virus-Scanned: ClamAV using ClamSMTP X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.4 (----) X-Debbugs-Envelope-To: submit Cc: Peter Rosin X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.4 (----) It is wrong to assume that pointers fit in long int. * src/context.c (print_context_number_range): Use intptr_t and the %PRIdPTR format when printing the lin type. (print_unidiff_number_rande): Likewise. * src/diff.h (translate_range): Likewise. * src/diff3.c (output_diff3): Likewise. (undotlines): Likewise. (output_diff3_edscript): Likewise. * src/ed.c (print_rcs_hunk): Likewise. * src/side.c (print_sdiff_common_lines): Likewise. (print_sdiff_hunk): Likewise. * src/system.h: Likewise. * src/ifdef.c (do_printf_spec): Likewise, but also make use of the formats PRIoPTR, PRIxPTR and PRIXPTR. --- src/context.c | 12 ++++++------ src/diff.h | 2 +- src/diff3.c | 37 +++++++++++++++++++------------------ src/ed.c | 8 +++++--- src/ifdef.c | 30 +++++++++++++++++++++++------- src/sdiff.c | 16 ++++++++-------- src/side.c | 12 ++++++------ src/system.h | 2 +- src/util.c | 23 ++++++++++++----------- 9 files changed, 81 insertions(+), 61 deletions(-) diff --git a/src/context.c b/src/context.c index 1a92a60..4fcf0b8 100644 --- a/src/context.c +++ b/src/context.c @@ -126,7 +126,7 @@ print_context_script (struct change *script, bool unidiff) static void print_context_number_range (struct file_data const *file, lin a, lin b) { - long int trans_a, trans_b; + intptr_t trans_a, trans_b; translate_range (file, a, b, &trans_a, &trans_b); /* We can have B <= A in the case of a range of no lines. @@ -139,9 +139,9 @@ print_context_number_range (struct file_data const *file, lin a, lin b) specification. */ if (trans_b <= trans_a) - fprintf (outfile, "%ld", trans_b); + fprintf (outfile, "%"PRIdPTR, trans_b); else - fprintf (outfile, "%ld,%ld", trans_a, trans_b); + fprintf (outfile, "%"PRIdPTR",%"PRIdPTR, trans_a, trans_b); } /* Print FUNCTION in a context header. */ @@ -299,7 +299,7 @@ pr_context_hunk (struct change *hunk) static void print_unidiff_number_range (struct file_data const *file, lin a, lin b) { - long int trans_a, trans_b; + intptr_t trans_a, trans_b; translate_range (file, a, b, &trans_a, &trans_b); /* We can have B < A in the case of a range of no lines. @@ -307,9 +307,9 @@ print_unidiff_number_range (struct file_data const *file, lin a, lin b) which is B. It would be more logical to print A, but 'patch' expects B in order to detect diffs against empty files. */ if (trans_b <= trans_a) - fprintf (outfile, trans_b < trans_a ? "%ld,0" : "%ld", trans_b); + fprintf (outfile, trans_b < trans_a ? "%"PRIdPTR",0" : "%"PRIdPTR, trans_b); else - fprintf (outfile, "%ld,%ld", trans_a, trans_b - trans_a + 1); + fprintf (outfile, "%"PRIdPTR",%"PRIdPTR, trans_a, trans_b - trans_a + 1); } /* Print a portion of an edit script in unidiff format. diff --git a/src/diff.h b/src/diff.h index 0983e7c..c4b236d 100644 --- a/src/diff.h +++ b/src/diff.h @@ -406,7 +406,7 @@ extern void print_script (struct change *, struct change * (*) (struct change *) void (*) (struct change *)); extern void setup_output (char const *, char const *, bool); extern void translate_range (struct file_data const *, lin, lin, - long int *, long int *); + intptr_t *, intptr_t *); enum color_context { diff --git a/src/diff3.c b/src/diff3.c index b80aeb3..eb4f729 100644 --- a/src/diff3.c +++ b/src/diff3.c @@ -1428,20 +1428,20 @@ output_diff3 (FILE *outputfile, struct diff3_block *diff, int realfile = mapping[i]; lin lowt = D_LOWLINE (ptr, realfile); lin hight = D_HIGHLINE (ptr, realfile); - long int llowt = lowt; - long int lhight = hight; + intptr_t llowt = lowt; + intptr_t lhight = hight; fprintf (outputfile, "%d:", i + 1); switch (lowt - hight) { case 1: - fprintf (outputfile, "%lda\n", llowt - 1); + fprintf (outputfile, "%"PRIdPTR"a\n", llowt - 1); break; case 0: - fprintf (outputfile, "%ldc\n", llowt); + fprintf (outputfile, "%"PRIdPTR"c\n", llowt); break; default: - fprintf (outputfile, "%ld,%ldc\n", llowt, lhight); + fprintf (outputfile, "%"PRIdPTR",%"PRIdPTR"c\n", llowt, lhight); break; } @@ -1495,19 +1495,20 @@ dotlines (FILE *outputfile, struct diff3_block *b, int filenum) /* Output to OUTPUTFILE a '.' line. If LEADING_DOT is true, also output a command that removes initial '.'s starting with line START - and continuing for NUM lines. (START is long int, not lin, for - convenience with printf %ld formats.) */ + and continuing for NUM lines. (START is intptr_t, not lin, for + convenience with printf formats.) */ static void -undotlines (FILE *outputfile, bool leading_dot, long int start, lin num) +undotlines (FILE *outputfile, bool leading_dot, intptr_t start, lin num) { fputs (".\n", outputfile); if (leading_dot) { if (num == 1) - fprintf (outputfile, "%lds/^\\.//\n", start); + fprintf (outputfile, "%"PRIdPTR"s/^\\.//\n", start); else - fprintf (outputfile, "%ld,%lds/^\\.//\n", start, start + num - 1); + fprintf (outputfile, "%"PRIdPTR",%"PRIdPTR"s/^\\.//\n", + start, start + num - 1); } } @@ -1548,7 +1549,7 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, ? DIFF_ALL : DIFF_1ST + rev_mapping[b->correspond - DIFF_1ST]); - long int low0, high0; + intptr_t low0, high0; /* If we aren't supposed to do this output block, skip it. */ switch (type) @@ -1569,7 +1570,7 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, /* Mark end of conflict. */ - fprintf (outputfile, "%lda\n", high0); + fprintf (outputfile, "%"PRIdPTR"a\n", high0); leading_dot = false; if (type == DIFF_ALL) { @@ -1591,7 +1592,7 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, /* Mark start of conflict. */ - fprintf (outputfile, "%lda\n<<<<<<< %s\n", low0 - 1, + fprintf (outputfile, "%"PRIdPTR"a\n<<<<<<< %s\n", low0 - 1, type == DIFF_ALL ? file0 : file1); leading_dot = false; if (type == DIFF_2ND) @@ -1607,9 +1608,9 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, /* Write out a delete */ { if (low0 == high0) - fprintf (outputfile, "%ldd\n", low0); + fprintf (outputfile, "%"PRIdPTR"d\n", low0); else - fprintf (outputfile, "%ld,%ldd\n", low0, high0); + fprintf (outputfile, "%"PRIdPTR",%"PRIdPTR"d\n", low0, high0); } else /* Write out an add or change */ @@ -1617,13 +1618,13 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, switch (high0 - low0) { case -1: - fprintf (outputfile, "%lda\n", high0); + fprintf (outputfile, "%"PRIdPTR"a\n", high0); break; case 0: - fprintf (outputfile, "%ldc\n", high0); + fprintf (outputfile, "%"PRIdPTR"c\n", high0); break; default: - fprintf (outputfile, "%ld,%ldc\n", low0, high0); + fprintf (outputfile, "%"PRIdPTR",%"PRIdPTR"c\n", low0, high0); break; } diff --git a/src/ed.c b/src/ed.c index 1fae2b8..14f9a43 100644 --- a/src/ed.c +++ b/src/ed.c @@ -144,7 +144,7 @@ static void print_rcs_hunk (struct change *hunk) { lin i, f0, l0, f1, l1; - long int tf0, tl0, tf1, tl1; + intptr_t tf0, tl0, tf1, tl1; /* Determine range of line numbers involved in each file. */ enum changes changes = analyze_hunk (hunk, &f0, &l0, &f1, &l1); @@ -159,14 +159,16 @@ print_rcs_hunk (struct change *hunk) { /* For deletion, print just the starting line number from file 0 and the number of lines deleted. */ - fprintf (outfile, "d%ld %ld\n", tf0, tf0 <= tl0 ? tl0 - tf0 + 1 : 1); + fprintf (outfile, "d%"PRIdPTR" %"PRIdPTR"\n", + tf0, tf0 <= tl0 ? tl0 - tf0 + 1 : 1); } if (changes & NEW) { /* Take last-line-number from file 0 and # lines from file 1. */ translate_range (&files[1], f1, l1, &tf1, &tl1); - fprintf (outfile, "a%ld %ld\n", tl0, tf1 <= tl1 ? tl1 - tf1 + 1 : 1); + fprintf (outfile, "a%"PRIdPTR" %"PRIdPTR"\n", + tl0, tf1 <= tl1 ? tl1 - tf1 + 1 : 1); /* Print the inserted lines. */ for (i = f1; i <= l1; i++) diff --git a/src/ifdef.c b/src/ifdef.c index b8b084f..4a38404 100644 --- a/src/ifdef.c +++ b/src/ifdef.c @@ -358,19 +358,35 @@ do_printf_spec (FILE *out, char const *spec, if (out) { /* For example, if the spec is "%3xn", use the printf - format spec "%3lx". Here the spec prefix is "%3". */ - long int long_value = value; + format spec "%3"PRIxPTR. Here the spec prefix is "%3". */ + intptr_t long_value = value; size_t spec_prefix_len = f - spec - 2; + size_t max_format = MAX(strlen(PRIdPTR), + MAX(strlen(PRIoPTR), + MAX(strlen(PRIxPTR), + strlen(PRIXPTR)))); #if HAVE_C_VARARRAYS - char format[spec_prefix_len + 3]; + char format[spec_prefix_len + max_format + 1]; #else - char *format = xmalloc (spec_prefix_len + 3); + char *format = xmalloc (spec_prefix_len + max_format + 1); #endif char *p = format + spec_prefix_len; memcpy (format, spec, spec_prefix_len); - *p++ = 'l'; - *p++ = c; - *p = '\0'; + switch (c) + { + case 'd': + strcpy(p, PRIdPTR); + break; + case 'o': + strcpy(p, PRIoPTR); + break; + case 'x': + strcpy(p, PRIxPTR); + break; + case 'X': + strcpy(p, PRIXPTR); + break; + } fprintf (out, format, long_value); #if ! HAVE_C_VARARRAYS free (format); diff --git a/src/sdiff.c b/src/sdiff.c index 22d6e5b..ed5b246 100644 --- a/src/sdiff.c +++ b/src/sdiff.c @@ -968,11 +968,11 @@ edit (struct line_filter *left, char const *lname, lin lline, lin llen, if (llen) { if (llen == 1) - fprintf (tmp, "--- %s %ld\n", lname, (long int) lline); + fprintf (tmp, "--- %s %"PRIdPTR"\n", lname, (intptr_t) lline); else - fprintf (tmp, "--- %s %ld,%ld\n", lname, - (long int) lline, - (long int) (lline + llen - 1)); + fprintf (tmp, "--- %s %"PRIdPTR",%"PRIdPTR"\n", lname, + (intptr_t) lline, + (intptr_t) (lline + llen - 1)); } /* Fall through. */ case '1': case 'b': case 'l': @@ -990,11 +990,11 @@ edit (struct line_filter *left, char const *lname, lin lline, lin llen, if (rlen) { if (rlen == 1) - fprintf (tmp, "+++ %s %ld\n", rname, (long int) rline); + fprintf (tmp, "+++ %s %"PRIdPTR"\n", rname, (intptr_t) rline); else - fprintf (tmp, "+++ %s %ld,%ld\n", rname, - (long int) rline, - (long int) (rline + rlen - 1)); + fprintf (tmp, "+++ %s %"PRIdPTR",%"PRIdPTR"\n", rname, + (intptr_t) rline, + (intptr_t) (rline + rlen - 1)); } /* Fall through. */ case '2': case 'b': case 'r': diff --git a/src/side.c b/src/side.c index 2276385..f5f1027 100644 --- a/src/side.c +++ b/src/side.c @@ -260,9 +260,9 @@ print_sdiff_common_lines (lin limit0, lin limit1) { if (sdiff_merge_assist) { - long int len0 = limit0 - i0; - long int len1 = limit1 - i1; - fprintf (outfile, "i%ld,%ld\n", len0, len1); + intptr_t len0 = limit0 - i0; + intptr_t len1 = limit1 - i1; + fprintf (outfile, "i%"PRIdPTR",%"PRIdPTR"\n", len0, len1); } if (!left_column) @@ -302,9 +302,9 @@ print_sdiff_hunk (struct change *hunk) if (sdiff_merge_assist) { - long int len0 = last0 - first0 + 1; - long int len1 = last1 - first1 + 1; - fprintf (outfile, "c%ld,%ld\n", len0, len1); + intptr_t len0 = last0 - first0 + 1; + intptr_t len1 = last1 - first1 + 1; + fprintf (outfile, "c%"PRIdPTR",%"PRIdPTR"\n", len0, len1); } /* Print "xxx | xxx " lines. */ diff --git a/src/system.h b/src/system.h index be1c0bd..70b8678 100644 --- a/src/system.h +++ b/src/system.h @@ -134,7 +134,7 @@ typedef ptrdiff_t lin; #define LIN_MAX PTRDIFF_MAX verify (TYPE_SIGNED (lin)); verify (sizeof (ptrdiff_t) <= sizeof (lin)); -verify (sizeof (lin) <= sizeof (long int)); +verify (sizeof (lin) <= sizeof (intptr_t)); /* Limit so that 2 * CONTEXT + 1 does not overflow. */ diff --git a/src/util.c b/src/util.c index 76872cb..f4e24e4 100644 --- a/src/util.c +++ b/src/util.c @@ -1401,13 +1401,13 @@ translate_line_number (struct file_data const *file, lin i) } /* Translate a line number range. This is always done for printing, - so for convenience translate to long int rather than lin, so that the - caller can use printf with "%ld" without casting. */ + so for convenience translate to intptr_t rather than lin, so that the + caller can use printf without casting. */ void translate_range (struct file_data const *file, lin a, lin b, - long int *aptr, long int *bptr) + intptr_t *aptr, intptr_t *bptr) { *aptr = translate_line_number (file, a - 1) + 1; *bptr = translate_line_number (file, b + 1) - 1; @@ -1422,16 +1422,16 @@ translate_range (struct file_data const *file, void print_number_range (char sepchar, struct file_data *file, lin a, lin b) { - long int trans_a, trans_b; + intptr_t trans_a, trans_b; translate_range (file, a, b, &trans_a, &trans_b); /* Note: we can have B < A in the case of a range of no lines. In this case, we should print the line number before the range, which is B. */ if (trans_b > trans_a) - fprintf (outfile, "%ld%c%ld", trans_a, sepchar, trans_b); + fprintf (outfile, "%"PRIdPTR"%c%"PRIdPTR, trans_a, sepchar, trans_b); else - fprintf (outfile, "%ld", trans_b); + fprintf (outfile, "%"PRIdPTR, trans_b); } /* Look at a hunk of edit script and report the range of lines in each file @@ -1565,11 +1565,12 @@ debug_script (struct change *sp) for (; sp; sp = sp->link) { - long int line0 = sp->line0; - long int line1 = sp->line1; - long int deleted = sp->deleted; - long int inserted = sp->inserted; - fprintf (stderr, "%3ld %3ld delete %ld insert %ld\n", + intptr_t line0 = sp->line0; + intptr_t line1 = sp->line1; + intptr_t deleted = sp->deleted; + intptr_t inserted = sp->inserted; + fprintf (stderr, "%3"PRIdPTR" %3"PRIdPTR" " + "delete %"PRIdPTR" insert %"PRIdPTR"\n", line0, line1, deleted, inserted); } -- 2.8.3 From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 26 14:42:57 2016 Received: (at 24311) by debbugs.gnu.org; 26 Aug 2016 18:42:57 +0000 Received: from localhost ([127.0.0.1]:41690 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdM5g-0002gz-R2 for submit@debbugs.gnu.org; Fri, 26 Aug 2016 14:42:57 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:55230) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdM5e-0002gk-1r for 24311@debbugs.gnu.org; Fri, 26 Aug 2016 14:42:54 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 4B4DD161267; Fri, 26 Aug 2016 11:42:48 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id bd4kAx8DkK1o; Fri, 26 Aug 2016 11:42:47 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 5618216127C; Fri, 26 Aug 2016 11:42:47 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 2GAyJhB2kGOY; Fri, 26 Aug 2016 11:42:47 -0700 (PDT) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 3C66D161267; Fri, 26 Aug 2016 11:42:47 -0700 (PDT) Subject: Re: [bug-diffutils] bug#24311: [PATCH] maint: accommodate LP64 systems To: Peter Rosin , 24311@debbugs.gnu.org References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> Date: Fri, 26 Aug 2016 11:42:42 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.2 (/) X-Debbugs-Envelope-To: 24311 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.2 (/) On 08/26/2016 01:41 AM, Peter Rosin wrote: > It is wrong to assume that pointers fit in long int. Not in GNU code. ) id 1bdMzx-00044W-Nr for submit@debbugs.gnu.org; Fri, 26 Aug 2016 15:41:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44268) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdMzw-00043v-Eg for 24311@debbugs.gnu.org; Fri, 26 Aug 2016 15:41:05 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 79B24C0567A1; Fri, 26 Aug 2016 19:40:58 +0000 (UTC) Received: from [10.3.116.4] (ovpn-116-4.phx2.redhat.com [10.3.116.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7QJevDu029364; Fri, 26 Aug 2016 15:40:58 -0400 Subject: Re: [bug-diffutils] bug#24311: bug#24311: [PATCH] maint: accommodate LP64 systems To: Paul Eggert , Peter Rosin , 24311@debbugs.gnu.org References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Organization: Red Hat, Inc. Message-ID: <57C09B49.2010507@redhat.com> Date: Fri, 26 Aug 2016 14:40:57 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="k0jr3QQqw13PMPfCNC9pq8WfP9Iwmem71" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 26 Aug 2016 19:40:58 +0000 (UTC) X-Spam-Score: -5.3 (-----) X-Debbugs-Envelope-To: 24311 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.3 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --k0jr3QQqw13PMPfCNC9pq8WfP9Iwmem71 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 08/26/2016 01:42 PM, Paul Eggert wrote: > On 08/26/2016 01:41 AM, Peter Rosin wrote: >> It is wrong to assume that pointers fit in long int. >=20 > Not in GNU code. > that GNU programs should not make any effort to cater to the possibilit= y > that 'long' will be narrower than ptrdiff_t. >=20 Except that the mingw64 platform is indeed a modern platform where pointers are 8 bytes but long is 4 bytes. So maybe it is time to propose a patch to the GNU Coding Standards that document the reality of existing systems, and then start the process of auditing which programs have been relying on the assumptions now rendered untrue by catering to such a platform. > Every POSIX platform is supposed to provide a compilation environment > where 'long' is no wider than ptrdiff_t, so if you're using a POSIX > platform you should be able to build diffutils without modifying its > source code. See: >=20 > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html >=20 But GNU software often tries to be portable to more than just POSIX platforms, and gnulib is already useful for catering to mingw64 where we indeed have long narrower than intptr_t (I'm not sure off-hand whether intptr_t and ptrdiff_t are the same size, or if ptrdiff_t is only 4 bytes= ). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --k0jr3QQqw13PMPfCNC9pq8WfP9Iwmem71 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXwJtJAAoJEKeha0olJ0Nqi3kH/3nAfGHWjixNmVXnZBVcrEzw 8WmElmbfYUx+CyqzVg0ewF8MtQGzC9NYfTGWlcEzZxrLXyK9rLhQSNo79YIw0ShA pHns/YshD1IyuJFdGG0zZqZF9+DSWMjKb+IgN359OATqdk95UVIQ4Q8xwWEZgQxV 49wWRt4XK/Zl9FGlHxUtG+OHEAc+P5h/Y2/LpVK1tpzsI4qE3mrlw2Cj/EQhXXwU vGKYpkarfYz7fdLj/Soq+0mZB76Mv1w3RUoRoBxZlHnKCo/H3e3Ogb14m/tjga2/ Wwl+49S8u9Lz+mjuUgJ5XTMsMvRjmZ7j6OWhstQu9CSadyU9kVSewsTAH+ntFL8= =Ky71 -----END PGP SIGNATURE----- --k0jr3QQqw13PMPfCNC9pq8WfP9Iwmem71-- From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 26 17:59:50 2016 Received: (at 24311) by debbugs.gnu.org; 26 Aug 2016 21:59:50 +0000 Received: from localhost ([127.0.0.1]:41743 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdPAE-00079U-4y for submit@debbugs.gnu.org; Fri, 26 Aug 2016 17:59:50 -0400 Received: from mail.lysator.liu.se ([130.236.254.3]:40660) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdPAC-00079L-0p for 24311@debbugs.gnu.org; Fri, 26 Aug 2016 17:59:48 -0400 Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 6166C40012; Fri, 26 Aug 2016 23:59:45 +0200 (CEST) Received: from [192.168.0.125] (217-210-101-82-no95.business.telia.com [217.210.101.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id 157244000F; Fri, 26 Aug 2016 23:59:44 +0200 (CEST) Subject: Re: [bug-diffutils] bug#24311: [PATCH] maint: accommodate LP64 systems To: Paul Eggert , 24311@debbugs.gnu.org References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> From: Peter Rosin Message-ID: Date: Fri, 26 Aug 2016 23:59:44 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Score: -2.5 (--) X-Debbugs-Envelope-To: 24311 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.5 (--) On 2016-08-26 20:42, Paul Eggert wrote: > On 08/26/2016 01:41 AM, Peter Rosin wrote: >> It is wrong to assume that pointers fit in long int. > > Not in GNU code. Then GNU has abandoned portability. Sad. > that GNU programs should not make any effort to cater to the possibility > that 'long' will be narrower than ptrdiff_t. Feels designed to target 64-bit Windows. Sad. > (It should be safe to convert ptrdiff_t to long in an LP64 system, so I > assume you meant to write "LLP64" in the Subject: line. Also, the values > in questions are offsets, not pointers, so I assume you meant to write > "pointer differences" not "pointers" in the above-quoted sentence.) Yes, I fat-fingered the subject and was a bit careless, sorry about that. Feel free to reword if you end up taking the patch. > A problem with the proposed patch is that it uses PRIdPTR, and thus > won't work on platforms with older C libraries that lack support for > PRIdPTR. Although this can be worked around with some effort, as a > general rule we prefer to avoid the effort. > > Every POSIX platform is supposed to provide a compilation environment > where 'long' is no wider than ptrdiff_t, so if you're using a POSIX > platform you should be able to build diffutils without modifying its > source code. See: > > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html I find these two complaints a little bit contradicting. Do you, or do you not require c99? Because the POSIX part seems to be connected to c99, but what do I know? Besides, I thought the gnulib inttypes module (or whatever it's called) provided the PRI?PTR macros if missing/broken? Cheers, Peter From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 26 18:24:12 2016 Received: (at 24311) by debbugs.gnu.org; 26 Aug 2016 22:24:12 +0000 Received: from localhost ([127.0.0.1]:41755 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdPXo-0007jj-D4 for submit@debbugs.gnu.org; Fri, 26 Aug 2016 18:24:12 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:42323) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdPXm-0007jW-Qp for 24311@debbugs.gnu.org; Fri, 26 Aug 2016 18:24:11 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id C076B161338; Fri, 26 Aug 2016 15:24:03 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 0WnBwRsFqAPb; Fri, 26 Aug 2016 15:24:03 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 031D7161368; Fri, 26 Aug 2016 15:24:03 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id rPVX66Daqr_t; Fri, 26 Aug 2016 15:24:02 -0700 (PDT) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id DDD19161338; Fri, 26 Aug 2016 15:24:02 -0700 (PDT) Subject: Re: [bug-diffutils] bug#24311: [PATCH] maint: accommodate LP64 systems To: Peter Rosin , 24311@debbugs.gnu.org References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: Date: Fri, 26 Aug 2016 15:24:02 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.2 (/) X-Debbugs-Envelope-To: 24311 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.2 (/) On 08/26/2016 02:59 PM, Peter Rosin wrote: > Feels designed to target 64-bit Windows. It isn't. It's more the other way round. The Unix (and GNU) LP64 tradition came first, and the 64-bit MS-Windows designers made it hard to write 64-bit code that is portable among the platforms. > Do you, or do you not require c99? It's not that simple. Although many GNU apps (including diffutils, I expect) assume some C99 features, they are typically portable to less-than-perfect POSIXish implementations that don't have all features that C99 requires. The main sticking point in this particular case is support for printf formats like %td. This requires library support, which in practice trails behind compiler support. We can reasonably ask people to use a C99ish compiler even when running on older platforms (just install GCC). It hasn't been so easy to insist on a C99ish C library. > the POSIX part seems to be connected to c99, but what do I know? POSIX assumes C99 or later nowadays. > Besides, I thought the gnulib inttypes module (or whatever it's called) > provided the PRI?PTR macros if missing/broken? PRI?PTR are not the right macros to use here. The values in question are of type ptrdiff_t, and ptrdiff_t != intptr_t on some (admittedly unusual) platforms. From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 27 18:07:41 2016 Received: (at 24311-done) by debbugs.gnu.org; 27 Aug 2016 22:07:41 +0000 Received: from localhost ([127.0.0.1]:42254 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdllM-0003c7-Sx for submit@debbugs.gnu.org; Sat, 27 Aug 2016 18:07:41 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:33340) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdllK-0003bt-Ft for 24311-done@debbugs.gnu.org; Sat, 27 Aug 2016 18:07:39 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 8DC13161104; Sat, 27 Aug 2016 15:07:32 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id k0DgAJ4nB0uQ; Sat, 27 Aug 2016 15:07:31 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id F33CF161117; Sat, 27 Aug 2016 15:07:30 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 35uXMdatfKR0; Sat, 27 Aug 2016 15:07:30 -0700 (PDT) Received: from [192.168.1.9] (unknown [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id CC972161104; Sat, 27 Aug 2016 15:07:30 -0700 (PDT) Subject: Re: [bug-diffutils] bug#24311: bug#24311: [PATCH] maint: accommodate LP64 systems To: Peter Rosin , 24311-done@debbugs.gnu.org References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: Date: Sat, 27 Aug 2016 15:07:30 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------863258D096C94DCC9E018297" X-Spam-Score: -0.2 (/) X-Debbugs-Envelope-To: 24311-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.2 (/) This is a multi-part message in MIME format. --------------863258D096C94DCC9E018297 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On further thought, I came up with a patch that should be portable without overly complicating the code or hurting efficiency, so I installed it (attached). Please give it a try on your platform. I am still leery about changing the GNU coding standards, though. In general we shouldn't ask developers to jump through these sorts of hoops for platforms so far from the typical GNU environment. --------------863258D096C94DCC9E018297 Content-Type: text/x-diff; name="0001-diff-port-line-numbers-to-mingw64.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-diff-port-line-numbers-to-mingw64.patch" >From 6f9c561a1ef3b170011908727a6570bf4e210279 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 27 Aug 2016 14:59:13 -0700 Subject: [PATCH] diff: port line numbers to mingw64 Problem reported by Peter Rosin (Bug#24311). * src/system.h (printint, pI): New typedef and macro. All uses of 'long int' and "%l" in printf format replaced by 'printint' and "%"pI respectively. * src/ifdef.c (do_printf_spec): Don't assume pI is length 1. --- NEWS | 4 ++++ src/context.c | 12 ++++++------ src/diff.h | 2 +- src/diff3.c | 35 +++++++++++++++++------------------ src/ed.c | 8 +++++--- src/ifdef.c | 15 ++++++++------- src/sdiff.c | 16 ++++++++-------- src/side.c | 12 ++++++------ src/system.h | 24 ++++++++++++++++++++---- src/util.c | 22 +++++++++++----------- 10 files changed, 86 insertions(+), 64 deletions(-) diff --git a/NEWS b/NEWS index accdf88..473332e 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ GNU diffutils NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Bug fixes + + diff no longer mishandles line numbers exceeding 2**31 on Mingw-w64. + * Noteworthy changes in release 3.5 (2016-08-20) [stable] diff --git a/src/context.c b/src/context.c index 1a92a60..1a663ba 100644 --- a/src/context.c +++ b/src/context.c @@ -126,7 +126,7 @@ print_context_script (struct change *script, bool unidiff) static void print_context_number_range (struct file_data const *file, lin a, lin b) { - long int trans_a, trans_b; + printint trans_a, trans_b; translate_range (file, a, b, &trans_a, &trans_b); /* We can have B <= A in the case of a range of no lines. @@ -139,9 +139,9 @@ print_context_number_range (struct file_data const *file, lin a, lin b) specification. */ if (trans_b <= trans_a) - fprintf (outfile, "%ld", trans_b); + fprintf (outfile, "%"pI"d", trans_b); else - fprintf (outfile, "%ld,%ld", trans_a, trans_b); + fprintf (outfile, "%"pI"d,%"pI"d", trans_a, trans_b); } /* Print FUNCTION in a context header. */ @@ -299,7 +299,7 @@ pr_context_hunk (struct change *hunk) static void print_unidiff_number_range (struct file_data const *file, lin a, lin b) { - long int trans_a, trans_b; + printint trans_a, trans_b; translate_range (file, a, b, &trans_a, &trans_b); /* We can have B < A in the case of a range of no lines. @@ -307,9 +307,9 @@ print_unidiff_number_range (struct file_data const *file, lin a, lin b) which is B. It would be more logical to print A, but 'patch' expects B in order to detect diffs against empty files. */ if (trans_b <= trans_a) - fprintf (outfile, trans_b < trans_a ? "%ld,0" : "%ld", trans_b); + fprintf (outfile, trans_b < trans_a ? "%"pI"d,0" : "%"pI"d", trans_b); else - fprintf (outfile, "%ld,%ld", trans_a, trans_b - trans_a + 1); + fprintf (outfile, "%"pI"d,%"pI"d", trans_a, trans_b - trans_a + 1); } /* Print a portion of an edit script in unidiff format. diff --git a/src/diff.h b/src/diff.h index 0983e7c..6eda1e6 100644 --- a/src/diff.h +++ b/src/diff.h @@ -406,7 +406,7 @@ extern void print_script (struct change *, struct change * (*) (struct change *) void (*) (struct change *)); extern void setup_output (char const *, char const *, bool); extern void translate_range (struct file_data const *, lin, lin, - long int *, long int *); + printint *, printint *); enum color_context { diff --git a/src/diff3.c b/src/diff3.c index b80aeb3..b2de4b6 100644 --- a/src/diff3.c +++ b/src/diff3.c @@ -1428,20 +1428,20 @@ output_diff3 (FILE *outputfile, struct diff3_block *diff, int realfile = mapping[i]; lin lowt = D_LOWLINE (ptr, realfile); lin hight = D_HIGHLINE (ptr, realfile); - long int llowt = lowt; - long int lhight = hight; + printint llowt = lowt; + printint lhight = hight; fprintf (outputfile, "%d:", i + 1); switch (lowt - hight) { case 1: - fprintf (outputfile, "%lda\n", llowt - 1); + fprintf (outputfile, "%"pI"da\n", llowt - 1); break; case 0: - fprintf (outputfile, "%ldc\n", llowt); + fprintf (outputfile, "%"pI"dc\n", llowt); break; default: - fprintf (outputfile, "%ld,%ldc\n", llowt, lhight); + fprintf (outputfile, "%"pI"d,%"pI"dc\n", llowt, lhight); break; } @@ -1495,19 +1495,18 @@ dotlines (FILE *outputfile, struct diff3_block *b, int filenum) /* Output to OUTPUTFILE a '.' line. If LEADING_DOT is true, also output a command that removes initial '.'s starting with line START - and continuing for NUM lines. (START is long int, not lin, for - convenience with printf %ld formats.) */ + and continuing for NUM lines. */ static void -undotlines (FILE *outputfile, bool leading_dot, long int start, lin num) +undotlines (FILE *outputfile, bool leading_dot, printint start, printint num) { fputs (".\n", outputfile); if (leading_dot) { if (num == 1) - fprintf (outputfile, "%lds/^\\.//\n", start); + fprintf (outputfile, "%"pI"ds/^\\.//\n", start); else - fprintf (outputfile, "%ld,%lds/^\\.//\n", start, start + num - 1); + fprintf (outputfile, "%"pI"d,%"pI"ds/^\\.//\n", start, start + num - 1); } } @@ -1548,7 +1547,7 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, ? DIFF_ALL : DIFF_1ST + rev_mapping[b->correspond - DIFF_1ST]); - long int low0, high0; + printint low0, high0; /* If we aren't supposed to do this output block, skip it. */ switch (type) @@ -1569,7 +1568,7 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, /* Mark end of conflict. */ - fprintf (outputfile, "%lda\n", high0); + fprintf (outputfile, "%"pI"da\n", high0); leading_dot = false; if (type == DIFF_ALL) { @@ -1591,7 +1590,7 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, /* Mark start of conflict. */ - fprintf (outputfile, "%lda\n<<<<<<< %s\n", low0 - 1, + fprintf (outputfile, "%"pI"da\n<<<<<<< %s\n", low0 - 1, type == DIFF_ALL ? file0 : file1); leading_dot = false; if (type == DIFF_2ND) @@ -1607,9 +1606,9 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, /* Write out a delete */ { if (low0 == high0) - fprintf (outputfile, "%ldd\n", low0); + fprintf (outputfile, "%"pI"dd\n", low0); else - fprintf (outputfile, "%ld,%ldd\n", low0, high0); + fprintf (outputfile, "%"pI"d,%"pI"dd\n", low0, high0); } else /* Write out an add or change */ @@ -1617,13 +1616,13 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, switch (high0 - low0) { case -1: - fprintf (outputfile, "%lda\n", high0); + fprintf (outputfile, "%"pI"da\n", high0); break; case 0: - fprintf (outputfile, "%ldc\n", high0); + fprintf (outputfile, "%"pI"dc\n", high0); break; default: - fprintf (outputfile, "%ld,%ldc\n", low0, high0); + fprintf (outputfile, "%"pI"d,%"pI"dc\n", low0, high0); break; } diff --git a/src/ed.c b/src/ed.c index 1fae2b8..6c9192c 100644 --- a/src/ed.c +++ b/src/ed.c @@ -144,7 +144,7 @@ static void print_rcs_hunk (struct change *hunk) { lin i, f0, l0, f1, l1; - long int tf0, tl0, tf1, tl1; + printint tf0, tl0, tf1, tl1; /* Determine range of line numbers involved in each file. */ enum changes changes = analyze_hunk (hunk, &f0, &l0, &f1, &l1); @@ -159,14 +159,16 @@ print_rcs_hunk (struct change *hunk) { /* For deletion, print just the starting line number from file 0 and the number of lines deleted. */ - fprintf (outfile, "d%ld %ld\n", tf0, tf0 <= tl0 ? tl0 - tf0 + 1 : 1); + fprintf (outfile, "d%"pI"d %"pI"d\n", tf0, + tf0 <= tl0 ? tl0 - tf0 + 1 : 1); } if (changes & NEW) { /* Take last-line-number from file 0 and # lines from file 1. */ translate_range (&files[1], f1, l1, &tf1, &tl1); - fprintf (outfile, "a%ld %ld\n", tl0, tf1 <= tl1 ? tl1 - tf1 + 1 : 1); + fprintf (outfile, "a%"pI"d %"pI"d\n", tl0, + tf1 <= tl1 ? tl1 - tf1 + 1 : 1); /* Print the inserted lines. */ for (i = f1; i <= l1; i++) diff --git a/src/ifdef.c b/src/ifdef.c index b8b084f..d67eb5b 100644 --- a/src/ifdef.c +++ b/src/ifdef.c @@ -357,21 +357,22 @@ do_printf_spec (FILE *out, char const *spec, if (out) { - /* For example, if the spec is "%3xn", use the printf + /* For example, if the spec is "%3xn" and pI is "l", use the printf format spec "%3lx". Here the spec prefix is "%3". */ - long int long_value = value; + printint print_value = value; size_t spec_prefix_len = f - spec - 2; + size_t pI_len = sizeof pI - 1; #if HAVE_C_VARARRAYS - char format[spec_prefix_len + 3]; + char format[spec_prefix_len + pI_len + 2]; #else - char *format = xmalloc (spec_prefix_len + 3); + char *format = xmalloc (spec_prefix_len + pI_len + 2); #endif - char *p = format + spec_prefix_len; + char *p = format + spec_prefix_len + pI_len; memcpy (format, spec, spec_prefix_len); - *p++ = 'l'; + memcpy (format + spec_prefix_len, pI, pI_len); *p++ = c; *p = '\0'; - fprintf (out, format, long_value); + fprintf (out, format, print_value); #if ! HAVE_C_VARARRAYS free (format); #endif diff --git a/src/sdiff.c b/src/sdiff.c index 22d6e5b..d900779 100644 --- a/src/sdiff.c +++ b/src/sdiff.c @@ -967,12 +967,12 @@ edit (struct line_filter *left, char const *lname, lin lline, lin llen, case 'd': if (llen) { + printint l1 = lline; + printint l2 = lline + llen - 1; if (llen == 1) - fprintf (tmp, "--- %s %ld\n", lname, (long int) lline); + fprintf (tmp, "--- %s %"pI"d\n", lname, l1); else - fprintf (tmp, "--- %s %ld,%ld\n", lname, - (long int) lline, - (long int) (lline + llen - 1)); + fprintf (tmp, "--- %s %"pI"d,%"pI"d\n", lname, l1, l2); } /* Fall through. */ case '1': case 'b': case 'l': @@ -989,12 +989,12 @@ edit (struct line_filter *left, char const *lname, lin lline, lin llen, case 'd': if (rlen) { + printint l1 = rline; + printint l2 = rline + rlen - 1; if (rlen == 1) - fprintf (tmp, "+++ %s %ld\n", rname, (long int) rline); + fprintf (tmp, "+++ %s %"pI"d\n", rname, l1); else - fprintf (tmp, "+++ %s %ld,%ld\n", rname, - (long int) rline, - (long int) (rline + rlen - 1)); + fprintf (tmp, "+++ %s %"pI"d,%"pI"d\n", rname, l1, l2); } /* Fall through. */ case '2': case 'b': case 'r': diff --git a/src/side.c b/src/side.c index 2276385..40356c9 100644 --- a/src/side.c +++ b/src/side.c @@ -260,9 +260,9 @@ print_sdiff_common_lines (lin limit0, lin limit1) { if (sdiff_merge_assist) { - long int len0 = limit0 - i0; - long int len1 = limit1 - i1; - fprintf (outfile, "i%ld,%ld\n", len0, len1); + printint len0 = limit0 - i0; + printint len1 = limit1 - i1; + fprintf (outfile, "i%"pI"d,%"pI"d\n", len0, len1); } if (!left_column) @@ -302,9 +302,9 @@ print_sdiff_hunk (struct change *hunk) if (sdiff_merge_assist) { - long int len0 = last0 - first0 + 1; - long int len1 = last1 - first1 + 1; - fprintf (outfile, "c%ld,%ld\n", len0, len1); + printint len0 = last0 - first0 + 1; + printint len1 = last1 - first1 + 1; + fprintf (outfile, "c%"pI"d,%"pI"d\n", len0, len1); } /* Print "xxx | xxx " lines. */ diff --git a/src/system.h b/src/system.h index be1c0bd..481d3a0 100644 --- a/src/system.h +++ b/src/system.h @@ -127,14 +127,30 @@ int strcasecmp (char const *, char const *); # define word size_t #endif -/* The integer type of a line number. Since files are read into main - memory, ptrdiff_t should be wide enough. */ +/* The signed integer type of a line number. Since files are read + into main memory, ptrdiff_t should be wide enough. */ typedef ptrdiff_t lin; #define LIN_MAX PTRDIFF_MAX + +/* The signed integer type for printing line numbers, and its printf + length modifier. Prefer 'long int' if it suffices, to cater to C + implementations that lack support for "ll". The natural + C99-or-later implementation with ptrdiff_t and "t" is less portable + in practice. */ + +#if LIN_MAX <= LONG_MAX +typedef long int printint; +# define pI "l" +#else +typedef long long int printint; +# define pI "ll" +#endif + verify (TYPE_SIGNED (lin)); -verify (sizeof (ptrdiff_t) <= sizeof (lin)); -verify (sizeof (lin) <= sizeof (long int)); +verify (TYPE_SIGNED (printint)); +verify (LIN_MAX == TYPE_MAXIMUM (lin)); +verify (LIN_MAX <= TYPE_MAXIMUM (printint)); /* Limit so that 2 * CONTEXT + 1 does not overflow. */ diff --git a/src/util.c b/src/util.c index 76872cb..bef2bff 100644 --- a/src/util.c +++ b/src/util.c @@ -1401,13 +1401,13 @@ translate_line_number (struct file_data const *file, lin i) } /* Translate a line number range. This is always done for printing, - so for convenience translate to long int rather than lin, so that the - caller can use printf with "%ld" without casting. */ + so for convenience translate to printint rather than lin, so that the + caller can use printf with "%"pI"d" without casting. */ void translate_range (struct file_data const *file, lin a, lin b, - long int *aptr, long int *bptr) + printint *aptr, printint *bptr) { *aptr = translate_line_number (file, a - 1) + 1; *bptr = translate_line_number (file, b + 1) - 1; @@ -1422,16 +1422,16 @@ translate_range (struct file_data const *file, void print_number_range (char sepchar, struct file_data *file, lin a, lin b) { - long int trans_a, trans_b; + printint trans_a, trans_b; translate_range (file, a, b, &trans_a, &trans_b); /* Note: we can have B < A in the case of a range of no lines. In this case, we should print the line number before the range, which is B. */ if (trans_b > trans_a) - fprintf (outfile, "%ld%c%ld", trans_a, sepchar, trans_b); + fprintf (outfile, "%"pI"d%c%"pI"d", trans_a, sepchar, trans_b); else - fprintf (outfile, "%ld", trans_b); + fprintf (outfile, "%"pI"d", trans_b); } /* Look at a hunk of edit script and report the range of lines in each file @@ -1565,11 +1565,11 @@ debug_script (struct change *sp) for (; sp; sp = sp->link) { - long int line0 = sp->line0; - long int line1 = sp->line1; - long int deleted = sp->deleted; - long int inserted = sp->inserted; - fprintf (stderr, "%3ld %3ld delete %ld insert %ld\n", + printint line0 = sp->line0; + printint line1 = sp->line1; + printint deleted = sp->deleted; + printint inserted = sp->inserted; + fprintf (stderr, "%3"pI"d %3"pI"d delete %"pI"d insert %"pI"d\n", line0, line1, deleted, inserted); } -- 2.7.4 --------------863258D096C94DCC9E018297-- From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 27 18:39:43 2016 Received: (at 24311) by debbugs.gnu.org; 27 Aug 2016 22:39:43 +0000 Received: from localhost ([127.0.0.1]:42261 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdmGM-0004Mn-Tj for submit@debbugs.gnu.org; Sat, 27 Aug 2016 18:39:43 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33902) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdmGL-0004MY-AP; Sat, 27 Aug 2016 18:39:41 -0400 Received: by mail-wm0-f67.google.com with SMTP id q128so4464282wma.1; Sat, 27 Aug 2016 15:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=FhRt3QpmSMjhSnqo23UHwQ/PgwECzfFyvHQzozfc3sI=; b=hy7yOfTXE7QSti10cSaqdrJsg/IP2UX1Dq9pP0yz0jmO9qYpjnqvn4cfg2PU+U9XG+ yoc17QZc18XD8hI1lnWgnU3VghXznGYa9o45JdwSJxcrOcNVTenQKRDJxz5hDcqE9E2d P/CAN/sdGbbcbR8lkgsaZbVXebR22UsNTBw7Z24u1BGYXWbY6qjcsCZxGpYXN3pI61lQ G5LoHwYnTZUco9AqvvwllVOawYAwvc//F4tq6mJvQeec6fNzeXq+I5CCHge9IsTrlmZc TJX+ikrmx6ufb8vb4vSUdYMx6c0ErD33X2Flrxs8cHeif5ddO7EWdanGZ2P3L44gc0tK 5xnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=FhRt3QpmSMjhSnqo23UHwQ/PgwECzfFyvHQzozfc3sI=; b=YvUoUYlYN2hRcxgg3TyT3ufAiqtnqPGk7VLeW6wG/LgCRQcdQ/d8Qjzig/U6Fe7aBn gnJ44ka/jTWYtK/GE6ati2ILRRqQB4/SYVxZBzPccgGVQxeS1bTyu1zTk2jTy/CdVdn3 PxF9drVRoqgzuGAehG40txt/WGQl1GUokV0uhM4Y4AjITD5o7NylsQeCl3+iQdZnuFPW 8PIFJiu0jfM/4uSz6nYDcmMRue25IyrTq+m9sqhZGy59KQ88eF6LTIGejH+H5EWlNYSr jFY8c8BUgDa1h9+OeU34x6DAaT/vpjkEBNZ9FMNtEZqxU2MdUBzjE61yxEWOhD5/Ve3B YJAg== X-Gm-Message-State: AE9vXwPUFktrQjMAZ7Er5pTweThKcr0j+o4P6RKFbpDSzPAHcBYsw6prL7iEKg0cy75WK25TZ1HRZPHKP/xqgw== X-Received: by 10.194.136.196 with SMTP id qc4mr9537078wjb.136.1472337575363; Sat, 27 Aug 2016 15:39:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.74.17 with HTTP; Sat, 27 Aug 2016 15:39:34 -0700 (PDT) In-Reply-To: References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> From: =?UTF-8?Q?Andreas_Gr=C3=BCnbacher?= Date: Sun, 28 Aug 2016 00:39:34 +0200 X-Google-Sender-Auth: 42z6iLbVDBU2FpINWXwU1AgSUuU Message-ID: Subject: Re: [bug-diffutils] bug#24311: bug#24311: bug#24311: [PATCH] maint: accommodate LP64 systems To: 24311@debbugs.gnu.org, Paul Eggert , peda@lysator.liu.se Content-Type: text/plain; charset=UTF-8 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 24311 Cc: 24311-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) 2016-08-28 0:07 GMT+02:00 Paul Eggert : > On further thought, I came up with a patch that should be portable without > overly complicating the code or hurting efficiency, so I installed it > (attached). Please give it a try on your platform. FWIW, patch has the following typedef for line numbers: typedef off_t lin; Maybe it would be time to switch to int64_t / uint64_t and PRId64 / PRIu64 in diff as well as in patch? Andreas From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 27 18:49:12 2016 Received: (at 24311) by debbugs.gnu.org; 27 Aug 2016 22:49:12 +0000 Received: from localhost ([127.0.0.1]:42269 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdmPY-0004bt-3H for submit@debbugs.gnu.org; Sat, 27 Aug 2016 18:49:12 -0400 Received: from mail.lysator.liu.se ([130.236.254.3]:33397) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdmPV-0004bk-P5 for 24311@debbugs.gnu.org; Sat, 27 Aug 2016 18:49:10 -0400 Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 0A7A440021; Sun, 28 Aug 2016 00:49:08 +0200 (CEST) Received: from [192.168.0.125] (217-210-101-82-no95.business.telia.com [217.210.101.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id A1C374001D; Sun, 28 Aug 2016 00:49:07 +0200 (CEST) Subject: Re: [bug-diffutils] bug#24311: [PATCH] maint: accommodate LP64 systems To: Paul Eggert , 24311@debbugs.gnu.org References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> From: Peter Rosin Message-ID: Date: Sun, 28 Aug 2016 00:49:06 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Score: -2.5 (--) X-Debbugs-Envelope-To: 24311 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.5 (--) On 2016-08-27 00:24, Paul Eggert wrote: > The main sticking point in this particular case is support for printf > formats like %td. This requires library support, which in practice > trails behind compiler support. We can reasonably ask people to use a > C99ish compiler even when running on older platforms (just install GCC). > It hasn't been so easy to insist on a C99ish C library. *snip* > PRI?PTR are not the right macros to use here. The values in question are > of type ptrdiff_t, and ptrdiff_t != intptr_t on some (admittedly > unusual) platforms. Are you trying to argue that there exist some non-theoretical system, where it's useful to actually run diffutils, and where both intptr_t < long int and intptr_t < ptrdiff_t holds? (i.e. a system that would regress with the patch) Because if there is no such system, then PRIdPTR w/ intptr_t will work better than %ld w/ long int (pending the time when %td w/ ptrdiff_t is generally available). Cheers, Peter From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 27 19:09:29 2016 Received: (at 24311) by debbugs.gnu.org; 27 Aug 2016 23:09:29 +0000 Received: from localhost ([127.0.0.1]:42279 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdmjB-00055C-Hy for submit@debbugs.gnu.org; Sat, 27 Aug 2016 19:09:29 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:35005) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdmj9-00054u-Qf; Sat, 27 Aug 2016 19:09:28 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 69271161104; Sat, 27 Aug 2016 16:09:22 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id MylDQt0uSVM0; Sat, 27 Aug 2016 16:09:21 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B233C161197; Sat, 27 Aug 2016 16:09:21 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id IUStNzpvLyik; Sat, 27 Aug 2016 16:09:21 -0700 (PDT) Received: from [192.168.1.9] (unknown [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 8EF98161104; Sat, 27 Aug 2016 16:09:21 -0700 (PDT) Subject: Re: [bug-diffutils] bug#24311: bug#24311: bug#24311: [PATCH] maint: accommodate LP64 systems To: =?UTF-8?Q?Andreas_Gr=c3=bcnbacher?= , 24311@debbugs.gnu.org, peda@lysator.liu.se References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: <9e28d46c-4260-4260-3ad9-3a924fcf308b@cs.ucla.edu> Date: Sat, 27 Aug 2016 16:09:19 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.2 (/) X-Debbugs-Envelope-To: 24311 Cc: 24311-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.2 (/) Andreas Gr=C3=BCnbacher wrote: > FWIW, patch has the following typedef for line numbers: > > typedef off_t lin; > > Maybe it would be time to switch to int64_t / uint64_t and PRId64 / > PRIu64 in diff as well as in patch? No, as 'diff' puts all its data into memory (hence ptrdiff_t is appropria= te),=20 whereas 'patch' can operate on files that do not fit into memory (hence o= ff_t is=20 appropriate). Generally speaking, portable code should be wary of using exact-sized typ= es like=20 int64_t. POSIX and the C standard don't even require int64_t, and there a= re a=20 few (admittedly rare) implementations that lack int64_t. Even if int64_t = was=20 universally available, it would be better to use types like ptrdiff_t and= off_t=20 that reflect actual implementation limitations, as that better documents = the code. From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 27 19:10:30 2016 Received: (at 24311) by debbugs.gnu.org; 27 Aug 2016 23:10:30 +0000 Received: from localhost ([127.0.0.1]:42284 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdmk9-000577-Re for submit@debbugs.gnu.org; Sat, 27 Aug 2016 19:10:29 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:35059) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdmk8-00056w-Qt for 24311@debbugs.gnu.org; Sat, 27 Aug 2016 19:10:29 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 91F20161104; Sat, 27 Aug 2016 16:10:23 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id N07Xd32KAkEQ; Sat, 27 Aug 2016 16:10:22 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id D510C161197; Sat, 27 Aug 2016 16:10:22 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tW6ad7bJ4e6F; Sat, 27 Aug 2016 16:10:22 -0700 (PDT) Received: from [192.168.1.9] (unknown [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id BB4A7161104; Sat, 27 Aug 2016 16:10:22 -0700 (PDT) Subject: Re: [bug-diffutils] bug#24311: [PATCH] maint: accommodate LP64 systems To: Peter Rosin , 24311@debbugs.gnu.org References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: <8aeb650a-87c2-820a-d066-561e60cb8531@cs.ucla.edu> Date: Sat, 27 Aug 2016 16:10:22 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.2 (/) X-Debbugs-Envelope-To: 24311 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.2 (/) Peter Rosin wrote: > Are you trying to argue No, I'm trying to solve the problem. If it's just as easy to solve the pr= oblem=20 even on oddball platforms, then we might as well solve it in a portable w= ay.=20 (After all, that's the main justification for the patch I just installed,= where=20 the "oddball platform" in this case is Mingw-w64. :-) > (pending the time when %td w/ ptrdiff_t is generally available) If "generally available" means "even Microsoft supports it", then I would= n't=20 hold my breath. Although %td has been part of the C standard for 17 years= ,=20 MS-Windows still does not support it. From debbugs-submit-bounces@debbugs.gnu.org Sun Aug 28 16:03:36 2016 Received: (at 24311-done) by debbugs.gnu.org; 28 Aug 2016 20:03:36 +0000 Received: from localhost ([127.0.0.1]:43024 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1be6Iq-0004MB-Lj for submit@debbugs.gnu.org; Sun, 28 Aug 2016 16:03:36 -0400 Received: from mail.lysator.liu.se ([130.236.254.3]:60033) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1be6Ip-0004M3-1s for 24311-done@debbugs.gnu.org; Sun, 28 Aug 2016 16:03:35 -0400 Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id A2D4440020; Sun, 28 Aug 2016 22:03:31 +0200 (CEST) Received: from [192.168.0.125] (217-210-101-82-no95.business.telia.com [217.210.101.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id 12DC24000C; Sun, 28 Aug 2016 22:03:30 +0200 (CEST) Subject: Re: [bug-diffutils] bug#24311: bug#24311: [PATCH] maint: accommodate LP64 systems To: Paul Eggert , 24311-done@debbugs.gnu.org References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> From: Peter Rosin Message-ID: <57a4d64f-ae73-3766-4520-021a14e1d756@lysator.liu.se> Date: Sun, 28 Aug 2016 22:03:30 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Score: -3.8 (---) X-Debbugs-Envelope-To: 24311-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.8 (---) On 2016-08-28 00:07, Paul Eggert wrote: > On further thought, I came up with a patch that should be portable without > overly complicating the code or hurting efficiency, so I installed it > (attached). Please give it a try on your platform. So, I didn't expect that to work, because the C library in question is the system msvcrt, which is compatible with the msvcrt for MSVC 6.0. That msvcrt was released almost 30 years ago. I have a strong suspicion that all system versions of the msvcrt library out there do not support %lld, even if you limit the search to 64-bit Windows... All in all, I was a bit surprised when it actually did work, and started digging. It seems that mingw-w64 includes overrides for the *printf functions, probably because they are so unportable in msvcrt. Anyway, the overrides includes support for the t length modifier, so a better patch might be a configure check to see if %td works, with machinery to set printint/pI to ptrdiff_t/"t" if it does and fall back to long int/"l" if it doesn't. That would be correct even for weird -- but standards conformant -- systems where even long long is too small for some obscure reason. > I am still leery about changing the GNU coding standards, though. In general we > shouldn't ask developers to jump through these sorts of hoops for platforms so > far from the typical GNU environment. My main beef with the GCS on this issue is that it suggests that maintainers should not spend any time at all on this issue, as if that would be contrary to some other goal. It would be much more palatable if it stated that maintainers did not need to spend time on the issue if they didn't want to. Cheers, Peter From debbugs-submit-bounces@debbugs.gnu.org Sun Aug 28 19:55:53 2016 Received: (at 24311-done) by debbugs.gnu.org; 28 Aug 2016 23:55:53 +0000 Received: from localhost ([127.0.0.1]:43167 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1be9vc-0001RG-QO for submit@debbugs.gnu.org; Sun, 28 Aug 2016 19:55:53 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:45840) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1be9va-0001R1-HM for 24311-done@debbugs.gnu.org; Sun, 28 Aug 2016 19:55:51 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 75F30160095; Sun, 28 Aug 2016 16:55:44 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id qzp89qPzLzLZ; Sun, 28 Aug 2016 16:55:43 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 9FB2316066C; Sun, 28 Aug 2016 16:55:43 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id XENV8x0UTQZp; Sun, 28 Aug 2016 16:55:43 -0700 (PDT) Received: from [192.168.1.9] (unknown [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 81436160095; Sun, 28 Aug 2016 16:55:43 -0700 (PDT) Subject: Re: [bug-diffutils] bug#24311: bug#24311: [PATCH] maint: accommodate LP64 systems To: Peter Rosin , 24311-done@debbugs.gnu.org References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> <57a4d64f-ae73-3766-4520-021a14e1d756@lysator.liu.se> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: <6bf11058-538d-7c73-504c-25118f01a049@cs.ucla.edu> Date: Sun, 28 Aug 2016 16:55:43 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <57a4d64f-ae73-3766-4520-021a14e1d756@lysator.liu.se> Content-Type: multipart/mixed; boundary="------------821BF511798A9547B865F206" X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: 24311-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.4 (-) This is a multi-part message in MIME format. --------------821BF511798A9547B865F206 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Peter Rosin wrote: > better patch might be a configure check to see > if %td works, with machinery to set printint/pI to ptrdiff_t/"t" if it = does and > fall back to long int/"l" if it doesn't. That'd be more work to develop and would be more likely to go wrong and w= ould=20 slow down 'configure'. I installed the attached patch instead. > My main beef with the GCS on this issue is that it suggests that mainta= iners > should not spend any time at all on this issue, as if that would be con= trary > to some other goal. It sucks away resources that could be used to support more-important goal= s.=20 We've already spent more time on Bug#24311 than the problem was worth.=20 Maintainers should not expend any significant time going down this rabbit= hole. --------------821BF511798A9547B865F206 Content-Type: text/x-diff; name="0001-diff-don-t-assume-ptrdiff_t-long-long-int.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-diff-don-t-assume-ptrdiff_t-long-long-int.patch" =46rom 92f3cb47aebf576987c97744028f1775c5518cf0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 28 Aug 2016 16:46:34 -0700 Subject: [PATCH] diff: don't assume ptrdiff_t <=3D long long int * src/system.h (printint, pI): Port to (theoretical) platforms where ptrdiff_t is wider than long long int (Bug#24311). --- src/system.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/system.h b/src/system.h index 481d3a0..028113e 100644 --- a/src/system.h +++ b/src/system.h @@ -134,17 +134,19 @@ typedef ptrdiff_t lin; #define LIN_MAX PTRDIFF_MAX =20 /* The signed integer type for printing line numbers, and its printf - length modifier. Prefer 'long int' if it suffices, to cater to C - implementations that lack support for "ll". The natural - C99-or-later implementation with ptrdiff_t and "t" is less portable - in practice. */ + length modifier. This is not simply ptrdiff_t, to cater to older + and/or nonstandard C libraries where "l" works but "ll" and "t" do + not, or where 'long' is too narrow and "ll" works but "t" does not. = */ =20 #if LIN_MAX <=3D LONG_MAX typedef long int printint; # define pI "l" -#else +#elif LIN_MAX <=3D LLONG_MAX typedef long long int printint; # define pI "ll" +#else +typedef ptrdiff_t printint; +# define pI "t" #endif =20 verify (TYPE_SIGNED (lin)); --=20 2.7.4 --------------821BF511798A9547B865F206-- From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 30 10:42:14 2016 Received: (at 24311) by debbugs.gnu.org; 30 Aug 2016 14:42:14 +0000 Received: from localhost ([127.0.0.1]:44497 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bekEq-0001lh-L5 for submit@debbugs.gnu.org; Tue, 30 Aug 2016 10:42:14 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:44333) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bekEj-0001l5-G4 for 24311@debbugs.gnu.org; Tue, 30 Aug 2016 10:42:07 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id CAD5E161358; Tue, 30 Aug 2016 07:41:54 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id ogABT4x_q2aS; Tue, 30 Aug 2016 07:41:54 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1EA3816136D; Tue, 30 Aug 2016 07:41:54 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 1wzweHQd9-mD; Tue, 30 Aug 2016 07:41:54 -0700 (PDT) Received: from [192.168.1.9] (unknown [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id DF435161376; Tue, 30 Aug 2016 07:41:53 -0700 (PDT) Subject: Re: [bug-diffutils] bug#24311: bug#24311: bug#24311: [PATCH] maint: accommodate LP64 systems To: Claude References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> <57a4d64f-ae73-3766-4520-021a14e1d756@lysator.liu.se> <6bf11058-538d-7c73-504c-25118f01a049@cs.ucla.edu> <05c585dd-d9f7-3ee3-0e7b-026ae31f2eb4@gmail.com> <14539abb-6525-864e-0689-723659291ccb@cs.ucla.edu> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: <20a34d02-666a-4d74-d28a-ef716d6f31c1@cs.ucla.edu> Date: Tue, 30 Aug 2016 07:41:50 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Score: -1.5 (-) X-Debbugs-Envelope-To: 24311 Cc: 24311@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.5 (-) Claude wrote: > xvasprintf.c: In function 'xvasprintf': > xvasprintf.c:102:3: error: function might be possible candidate for 'gn= u_printf' > format attribute [-Werror=3Dsuggest-attribute=3Dformat] > if (vasprintf (&result, format, args) < 0) > ^ I wouldn't worry about that warning. Either configure without=20 --with-gcc-warnings or build with 'make WERROR_CFLAGS=3D'. > when compiling with cygwin > > CC xstrtol.o > In file included from xstrtol.h:22:0, > from xstrtol.c:31: > ./getopt.h:198:8: error: redefinition of 'struct option' > struct option > ^ Sounds like your Cygwin configuration is busted somehow. Look in config.l= og and=20 see why 'configure' decided that getopt didn't work on your platform. > Aren't these tests on $cross_compiling contradictory in configure ? > > > if test $cross_compilin= g =3D no; then > if test "$cross_compiling" =3D yes; then = : > { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 > $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} > as_fn_error $? "cannot run test program while cross compiling > See \`config.log' for more details" "$LINENO" 5; } > else > cat confdefs.h - <<_ACEOF >conftest.$ac_ext I don't see any contradiction. From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 30 12:46:00 2016 Received: (at 24311) by debbugs.gnu.org; 30 Aug 2016 16:46:00 +0000 Received: from localhost ([127.0.0.1]:44597 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bemAi-0004hi-88 for submit@debbugs.gnu.org; Tue, 30 Aug 2016 12:46:00 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:55461) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bemAg-0004hV-Qa for 24311@debbugs.gnu.org; Tue, 30 Aug 2016 12:45:59 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 75CC6161173; Tue, 30 Aug 2016 09:45:53 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id EwLKnARM0ZPP; Tue, 30 Aug 2016 09:45:52 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id A38DD161378; Tue, 30 Aug 2016 09:45:52 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id apAWQ0DEE0Hb; Tue, 30 Aug 2016 09:45:52 -0700 (PDT) Received: from [192.168.1.9] (unknown [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 42104161173; Tue, 30 Aug 2016 09:45:52 -0700 (PDT) Subject: Re: [bug-diffutils] bug#24311: bug#24311: bug#24311: [PATCH] maint: accommodate LP64 systems To: Claude References: <1472200884-12485-1-git-send-email-peda@lysator.liu.se> <2e4f5b69-20fa-f7f6-1277-35cbf9bd7685@cs.ucla.edu> <57a4d64f-ae73-3766-4520-021a14e1d756@lysator.liu.se> <6bf11058-538d-7c73-504c-25118f01a049@cs.ucla.edu> <05c585dd-d9f7-3ee3-0e7b-026ae31f2eb4@gmail.com> <14539abb-6525-864e-0689-723659291ccb@cs.ucla.edu> <20a34d02-666a-4d74-d28a-ef716d6f31c1@cs.ucla.edu> <33ccbe44-462c-9e56-6aad-ce77f7f91aec@gmail.com> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: Date: Tue, 30 Aug 2016 09:45:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <33ccbe44-462c-9e56-6aad-ce77f7f91aec@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -1.5 (-) X-Debbugs-Envelope-To: 24311 Cc: 24311@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.5 (-) Claude wrote: > - the cross_compiling thing... If I read this right, and I may be wrong, the > first two line of my snapshot stipulate that cross_compiling have to be set to > no AND yes at the same time to enter the block. That could never happen. Ah, I see it now. Well, 'configure' scripts are notoriously inefficient.... > - cygwin. I didn't see anything that went wrong. I am attaching the config.log Nothing was attached. But really, this is something you need to debug; Cygwin is low priority for me. All I'm saying is that Cygwin should already have getopt so why are you compiling getopt? You need to figure it out by looking at config.log etc. From unknown Wed Jun 18 23:08:23 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, 28 Sep 2016 11: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