This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR 78534 Change character length from int to size_t
- From: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- To: Jerry DeLisle <jvdelisle at charter dot net>
- Cc: Thomas Koenig <tkoenig at netcologne dot de>, Fortran List <fortran at gcc dot gnu dot org>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 3 Jan 2018 13:37:04 +0200
- Subject: Re: [PATCH] PR 78534 Change character length from int to size_t
- Authentication-results: sourceware.org; auth=none
- References: <1514554310-27231-1-git-send-email-blomqvist.janne@gmail.com> <40a2fbf9-d997-0e88-3754-e5e80629b4d1@netcologne.de> <CAO9iq9G=b1WSELO2M+hQTOjcCdn4QHH4NVX_g0iFT=DAe3yodQ@mail.gmail.com> <6e2a8ac3-41e2-3503-1d9e-6a9dfe6be52f@netcologne.de> <CAO9iq9FeA3nr-ZXgQPk4zz8HOR7iEkQnKwGP=YGYe0gF69p4Bw@mail.gmail.com> <1751d219-7012-1b17-e2f2-b358a60d1d21@charter.net>
On Sat, Dec 30, 2017 at 10:58 PM, Jerry DeLisle <jvdelisle@charter.net> wrote:
> On 12/30/2017 12:35 PM, Janne Blomqvist wrote:
>> On Sat, Dec 30, 2017 at 7:16 PM, Thomas Koenig <tkoenig@netcologne.de> wrote:
> ---snip---
>>
>> I can provide that stuff as a separate patch, or merge it into the
>> original megapatch and resubmit that, whichever way you prefer.
>
> I would prefer we split into two patches. This will make review of the library
> I/O changes easier. The int len is used in a lot of places also where it really
> happens to also be the kind (which is a length in our implementation).
Hi,
attached is a patch that makes the two attached testcases work. It
applies on top of the charlen->size_t patch. In the formatted I/O
stuff, I have mostly used ptrdiff_t to avoid having to deal with
signed/unsigned issues, as the previous code was using int.
--
Janne Blomqvist
From 72799c5587ee1e830bb424278286cff309d0c4a7 Mon Sep 17 00:00:00 2001
From: Janne Blomqvist <blomqvist.janne@gmail.com>
Date: Tue, 2 Jan 2018 14:17:57 +0200
Subject: [PATCH] Use ptrdiff_t for formatted I/O sizes
---
libgfortran/io/fbuf.c | 44 ++++++++++++++---------------
libgfortran/io/fbuf.h | 16 +++++------
libgfortran/io/io.h | 16 +++++------
libgfortran/io/list_read.c | 15 +++++-----
libgfortran/io/read.c | 70 +++++++++++++++++++++++-----------------------
libgfortran/io/transfer.c | 36 ++++++++++++------------
libgfortran/io/unix.c | 20 ++++++-------
libgfortran/io/unix.h | 12 ++++----
libgfortran/io/write.c | 21 +++++++-------
9 files changed, 126 insertions(+), 124 deletions(-)
diff --git a/libgfortran/io/fbuf.c b/libgfortran/io/fbuf.c
index 944469d..d38d003 100644
--- a/libgfortran/io/fbuf.c
+++ b/libgfortran/io/fbuf.c
@@ -33,7 +33,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
void
-fbuf_init (gfc_unit *u, int len)
+fbuf_init (gfc_unit *u, ptrdiff_t len)
{
if (len == 0)
len = 512; /* Default size. */
@@ -64,9 +64,9 @@ fbuf_debug (gfc_unit *u, const char *format, ...)
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
- fprintf (stderr, "fbuf_debug pos: %d, act: %d, buf: ''",
- u->fbuf->pos, u->fbuf->act);
- for (int ii = 0; ii < u->fbuf->act; ii++)
+ fprintf (stderr, "fbuf_debug pos: %ld, act: %ld, buf: ''",
+ (long) u->fbuf->pos, (long) u->fbuf->act);
+ for (ptrdiff_t ii = 0; ii < u->fbuf->act; ii++)
{
putc (u->fbuf->buf[ii], stderr);
}
@@ -84,10 +84,10 @@ fbuf_debug (gfc_unit *u __attribute__ ((unused)),
underlying device. Returns how much the physical position was
modified. */
-int
+ptrdiff_t
fbuf_reset (gfc_unit *u)
{
- int seekval = 0;
+ ptrdiff_t seekval = 0;
if (!u->fbuf)
return 0;
@@ -99,7 +99,7 @@ fbuf_reset (gfc_unit *u)
if (u->mode == READING && u->fbuf->act > u->fbuf->pos)
{
seekval = - (u->fbuf->act - u->fbuf->pos);
- fbuf_debug (u, "fbuf_reset seekval %d, ", seekval);
+ fbuf_debug (u, "fbuf_reset seekval %ld, ", (long) seekval);
}
u->fbuf->act = u->fbuf->pos = 0;
return seekval;
@@ -111,11 +111,11 @@ fbuf_reset (gfc_unit *u)
reallocating if necessary. */
char *
-fbuf_alloc (gfc_unit *u, int len)
+fbuf_alloc (gfc_unit *u, ptrdiff_t len)
{
- int newlen;
+ ptrdiff_t newlen;
char *dest;
- fbuf_debug (u, "fbuf_alloc len %d, ", len);
+ fbuf_debug (u, "fbuf_alloc len %ld, ", (long) len);
if (u->fbuf->pos + len > u->fbuf->len)
{
/* Round up to nearest multiple of the current buffer length. */
@@ -138,7 +138,7 @@ fbuf_alloc (gfc_unit *u, int len)
int
fbuf_flush (gfc_unit *u, unit_mode mode)
{
- int nwritten;
+ ptrdiff_t nwritten;
if (!u->fbuf)
return 0;
@@ -177,7 +177,7 @@ fbuf_flush (gfc_unit *u, unit_mode mode)
int
fbuf_flush_list (gfc_unit *u, unit_mode mode)
{
- int nwritten;
+ ptrdiff_t nwritten;
if (!u->fbuf)
return 0;
@@ -206,8 +206,8 @@ fbuf_flush_list (gfc_unit *u, unit_mode mode)
}
-int
-fbuf_seek (gfc_unit *u, int off, int whence)
+ptrdiff_t
+fbuf_seek (gfc_unit *u, ptrdiff_t off, int whence)
{
if (!u->fbuf)
return -1;
@@ -226,7 +226,7 @@ fbuf_seek (gfc_unit *u, int off, int whence)
return -1;
}
- fbuf_debug (u, "fbuf_seek, off %d ", off);
+ fbuf_debug (u, "fbuf_seek, off %ld ", (long) off);
/* The start of the buffer is always equal to the left tab
limit. Moving to the left past the buffer is illegal in C and
would also imply moving past the left tab limit, which is never
@@ -248,21 +248,21 @@ fbuf_seek (gfc_unit *u, int off, int whence)
of bytes actually processed. */
char *
-fbuf_read (gfc_unit *u, int *len)
+fbuf_read (gfc_unit *u, ptrdiff_t *len)
{
char *ptr;
- int oldact, oldpos;
- int readlen = 0;
+ ptrdiff_t oldact, oldpos;
+ ptrdiff_t readlen = 0;
- fbuf_debug (u, "fbuf_read, len %d: ", *len);
+ fbuf_debug (u, "fbuf_read, len %ld: ", (long) *len);
oldact = u->fbuf->act;
oldpos = u->fbuf->pos;
ptr = fbuf_alloc (u, *len);
u->fbuf->pos = oldpos;
if (oldpos + *len > oldact)
{
- fbuf_debug (u, "reading %d bytes starting at %d ",
- oldpos + *len - oldact, oldact);
+ fbuf_debug (u, "reading %ld bytes starting at %ld ",
+ (long) oldpos + *len - oldact, (long) oldact);
readlen = sread (u->s, u->fbuf->buf + oldact, oldpos + *len - oldact);
if (readlen < 0)
return NULL;
@@ -281,7 +281,7 @@ fbuf_read (gfc_unit *u, int *len)
int
fbuf_getc_refill (gfc_unit *u)
{
- int nread;
+ ptrdiff_t nread;
char *p;
fbuf_debug (u, "fbuf_getc_refill ");
diff --git a/libgfortran/io/fbuf.h b/libgfortran/io/fbuf.h
index a0c5713..a18592f 100644
--- a/libgfortran/io/fbuf.h
+++ b/libgfortran/io/fbuf.h
@@ -39,21 +39,21 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
struct fbuf
{
char *buf; /* Start of buffer. */
- int len; /* Length of buffer. */
- int act; /* Active bytes in buffer. */
- int pos; /* Current position in buffer. */
+ ptrdiff_t len; /* Length of buffer. */
+ ptrdiff_t act; /* Active bytes in buffer. */
+ ptrdiff_t pos; /* Current position in buffer. */
};
-extern void fbuf_init (gfc_unit *, int);
+extern void fbuf_init (gfc_unit *, ptrdiff_t);
internal_proto(fbuf_init);
extern void fbuf_destroy (gfc_unit *);
internal_proto(fbuf_destroy);
-extern int fbuf_reset (gfc_unit *);
+extern ptrdiff_t fbuf_reset (gfc_unit *);
internal_proto(fbuf_reset);
-extern char *fbuf_alloc (gfc_unit *, int);
+extern char *fbuf_alloc (gfc_unit *, ptrdiff_t);
internal_proto(fbuf_alloc);
extern int fbuf_flush (gfc_unit *, unit_mode);
@@ -62,10 +62,10 @@ internal_proto(fbuf_flush);
extern int fbuf_flush_list (gfc_unit *, unit_mode);
internal_proto(fbuf_flush_list);
-extern int fbuf_seek (gfc_unit *, int, int);
+extern ptrdiff_t fbuf_seek (gfc_unit *, ptrdiff_t, int);
internal_proto(fbuf_seek);
-extern char *fbuf_read (gfc_unit *, int *);
+extern char *fbuf_read (gfc_unit *, ptrdiff_t *);
internal_proto(fbuf_read);
/* Never call this function, only use fbuf_getc(). */
diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h
index c5e73d8..b61b3fe 100644
--- a/libgfortran/io/io.h
+++ b/libgfortran/io/io.h
@@ -794,13 +794,13 @@ internal_proto(new_unit);
extern const char *type_name (bt);
internal_proto(type_name);
-extern void * read_block_form (st_parameter_dt *, int *);
+extern void * read_block_form (st_parameter_dt *, ptrdiff_t *);
internal_proto(read_block_form);
-extern void * read_block_form4 (st_parameter_dt *, int *);
+extern void * read_block_form4 (st_parameter_dt *, ptrdiff_t *);
internal_proto(read_block_form4);
-extern void *write_block (st_parameter_dt *, int);
+extern void *write_block (st_parameter_dt *, ptrdiff_t);
internal_proto(write_block);
extern gfc_offset next_array_record (st_parameter_dt *, array_loop_spec *,
@@ -834,10 +834,10 @@ internal_proto(convert_real);
extern int convert_infnan (st_parameter_dt *, void *, const char *, int);
internal_proto(convert_infnan);
-extern void read_a (st_parameter_dt *, const fnode *, char *, int);
+extern void read_a (st_parameter_dt *, const fnode *, char *, ptrdiff_t);
internal_proto(read_a);
-extern void read_a_char4 (st_parameter_dt *, const fnode *, char *, int);
+extern void read_a_char4 (st_parameter_dt *, const fnode *, char *, ptrdiff_t);
internal_proto(read_a);
extern void read_f (st_parameter_dt *, const fnode *, char *, int);
@@ -846,7 +846,7 @@ internal_proto(read_f);
extern void read_l (st_parameter_dt *, const fnode *, char *, int);
internal_proto(read_l);
-extern void read_x (st_parameter_dt *, int);
+extern void read_x (st_parameter_dt *, ptrdiff_t);
internal_proto(read_x);
extern void read_radix (st_parameter_dt *, const fnode *, char *, int, int);
@@ -878,10 +878,10 @@ internal_proto(namelist_write);
/* write.c */
-extern void write_a (st_parameter_dt *, const fnode *, const char *, int);
+extern void write_a (st_parameter_dt *, const fnode *, const char *, ptrdiff_t);
internal_proto(write_a);
-extern void write_a_char4 (st_parameter_dt *, const fnode *, const char *, int);
+extern void write_a_char4 (st_parameter_dt *, const fnode *, const char *, ptrdiff_t);
internal_proto(write_a_char4);
extern void write_b (st_parameter_dt *, const fnode *, const char *, int);
diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index 037f2da..da56c19 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -2100,7 +2100,8 @@ list_formatted_read_scalar (st_parameter_dt *dtp, bt type, void *p,
int kind, size_t size)
{
gfc_char4_t *q, *r;
- int c, i, m;
+ size_t m;
+ int c;
int err = 0;
/* Set the next_char and push_char worker functions. */
@@ -2255,20 +2256,20 @@ list_formatted_read_scalar (st_parameter_dt *dtp, bt type, void *p,
case BT_CHARACTER:
if (dtp->u.p.saved_string)
{
- m = ((int) size < dtp->u.p.saved_used)
- ? (int) size : dtp->u.p.saved_used;
+ m = (size < (size_t) dtp->u.p.saved_used)
+ ? size : (size_t) dtp->u.p.saved_used;
q = (gfc_char4_t *) p;
r = (gfc_char4_t *) dtp->u.p.saved_string;
if (dtp->u.p.current_unit->flags.encoding == ENCODING_UTF8)
- for (i = 0; i < m; i++)
+ for (size_t i = 0; i < m; i++)
*q++ = *r++;
else
{
if (kind == 1)
memcpy (p, dtp->u.p.saved_string, m);
else
- for (i = 0; i < m; i++)
+ for (size_t i = 0; i < m; i++)
*q++ = *r++;
}
}
@@ -2276,14 +2277,14 @@ list_formatted_read_scalar (st_parameter_dt *dtp, bt type, void *p,
/* Just delimiters encountered, nothing to copy but SPACE. */
m = 0;
- if (m < (int) size)
+ if (m < size)
{
if (kind == 1)
memset (((char *) p) + m, ' ', size - m);
else
{
q = (gfc_char4_t *) p;
- for (i = m; i < (int) size; i++)
+ for (size_t i = m; i < size; i++)
q[i] = (unsigned char) ' ';
}
}
diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c
index 9eb2196..7f4e6b2 100644
--- a/libgfortran/io/read.c
+++ b/libgfortran/io/read.c
@@ -272,7 +272,7 @@ void
read_l (st_parameter_dt *dtp, const fnode *f, char *dest, int length)
{
char *p;
- int w;
+ ptrdiff_t w;
w = f->u.w;
@@ -316,11 +316,11 @@ read_l (st_parameter_dt *dtp, const fnode *f, char *dest, int length)
static gfc_char4_t
-read_utf8 (st_parameter_dt *dtp, int *nbytes)
+read_utf8 (st_parameter_dt *dtp, ptrdiff_t *nbytes)
{
static const uchar masks[6] = { 0x7F, 0x1F, 0x0F, 0x07, 0x02, 0x01 };
static const uchar patns[6] = { 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
- int i, nb, nread;
+ ptrdiff_t i, nb, nread;
gfc_char4_t c;
char *s;
@@ -383,12 +383,11 @@ read_utf8 (st_parameter_dt *dtp, int *nbytes)
static void
-read_utf8_char1 (st_parameter_dt *dtp, char *p, int len, int width)
+read_utf8_char1 (st_parameter_dt *dtp, char *p, ptrdiff_t len, ptrdiff_t width)
{
gfc_char4_t c;
char *dest;
- int nbytes;
- int i, j;
+ ptrdiff_t nbytes, j;
len = (width < len) ? len : width;
@@ -407,16 +406,16 @@ read_utf8_char1 (st_parameter_dt *dtp, char *p, int len, int width)
}
/* If there was a short read, pad the remaining characters. */
- for (i = j; i < len; i++)
+ for (ptrdiff_t i = j; i < len; i++)
*dest++ = ' ';
return;
}
static void
-read_default_char1 (st_parameter_dt *dtp, char *p, int len, int width)
+read_default_char1 (st_parameter_dt *dtp, char *p, ptrdiff_t len, ptrdiff_t width)
{
char *s;
- int m, n;
+ ptrdiff_t m, n;
s = read_block_form (dtp, &width);
@@ -435,11 +434,10 @@ read_default_char1 (st_parameter_dt *dtp, char *p, int len, int width)
static void
-read_utf8_char4 (st_parameter_dt *dtp, void *p, int len, int width)
+read_utf8_char4 (st_parameter_dt *dtp, void *p, ptrdiff_t len, ptrdiff_t width)
{
gfc_char4_t *dest;
- int nbytes;
- int i, j;
+ ptrdiff_t nbytes, j;
len = (width < len) ? len : width;
@@ -456,16 +454,16 @@ read_utf8_char4 (st_parameter_dt *dtp, void *p, int len, int width)
}
/* If there was a short read, pad the remaining characters. */
- for (i = j; i < len; i++)
+ for (ptrdiff_t i = j; i < len; i++)
*dest++ = (gfc_char4_t) ' ';
return;
}
static void
-read_default_char4 (st_parameter_dt *dtp, char *p, int len, int width)
+read_default_char4 (st_parameter_dt *dtp, char *p, ptrdiff_t len, ptrdiff_t width)
{
- int m, n;
+ ptrdiff_t m, n;
gfc_char4_t *dest;
if (is_char4_unit(dtp))
@@ -479,14 +477,14 @@ read_default_char4 (st_parameter_dt *dtp, char *p, int len, int width)
if (width > len)
s4 += (width - len);
- m = ((int) width > len) ? len : (int) width;
+ m = (width > len) ? len : width;
dest = (gfc_char4_t *) p;
for (n = 0; n < m; n++)
*dest++ = *s4++;
- for (n = 0; n < len - (int) width; n++)
+ for (n = 0; n < len - width; n++)
*dest++ = (gfc_char4_t) ' ';
}
else
@@ -500,14 +498,14 @@ read_default_char4 (st_parameter_dt *dtp, char *p, int len, int width)
if (width > len)
s += (width - len);
- m = ((int) width > len) ? len : (int) width;
+ m = (width > len) ? len : width;
dest = (gfc_char4_t *) p;
for (n = 0; n < m; n++, dest++, s++)
*dest = (unsigned char ) *s;
- for (n = 0; n < len - (int) width; n++, dest++)
+ for (n = 0; n < len - width; n++, dest++)
*dest = (unsigned char) ' ';
}
}
@@ -517,15 +515,13 @@ read_default_char4 (st_parameter_dt *dtp, char *p, int len, int width)
processing UTF-8 encoding if necessary. */
void
-read_a (st_parameter_dt *dtp, const fnode *f, char *p, int length)
+read_a (st_parameter_dt *dtp, const fnode *f, char *p, ptrdiff_t length)
{
- int wi;
- int w;
+ ptrdiff_t w;
- wi = f->u.w;
- if (wi == -1) /* '(A)' edit descriptor */
- wi = length;
- w = wi;
+ w = f->u.w;
+ if (w == -1) /* '(A)' edit descriptor */
+ w = length;
/* Read in w characters, treating comma as not a separator. */
dtp->u.p.sf_read_comma = 0;
@@ -544,9 +540,9 @@ read_a (st_parameter_dt *dtp, const fnode *f, char *p, int length)
processing UTF-8 encoding if necessary. */
void
-read_a_char4 (st_parameter_dt *dtp, const fnode *f, char *p, int length)
+read_a_char4 (st_parameter_dt *dtp, const fnode *f, char *p, ptrdiff_t length)
{
- int w;
+ ptrdiff_t w;
w = f->u.w;
if (w == -1) /* '(A)' edit descriptor */
@@ -568,7 +564,7 @@ read_a_char4 (st_parameter_dt *dtp, const fnode *f, char *p, int length)
ignore the leading spaces. */
static char *
-eat_leading_spaces (int *width, char *p)
+eat_leading_spaces (ptrdiff_t *width, char *p)
{
for (;;)
{
@@ -584,7 +580,7 @@ eat_leading_spaces (int *width, char *p)
static char
-next_char (st_parameter_dt *dtp, char **p, int *w)
+next_char (st_parameter_dt *dtp, char **p, ptrdiff_t *w)
{
char c, *q;
@@ -624,7 +620,8 @@ read_decimal (st_parameter_dt *dtp, const fnode *f, char *dest, int length)
{
GFC_UINTEGER_LARGEST value, maxv, maxv_10;
GFC_INTEGER_LARGEST v;
- int w, negative;
+ ptrdiff_t w;
+ int negative;
char c, *p;
w = f->u.w;
@@ -732,7 +729,8 @@ read_radix (st_parameter_dt *dtp, const fnode *f, char *dest, int length,
{
GFC_UINTEGER_LARGEST value, maxv, maxv_r;
GFC_INTEGER_LARGEST v;
- int w, negative;
+ ptrdiff_t w;
+ int negative;
char c, *p;
w = f->u.w;
@@ -882,7 +880,8 @@ read_f (st_parameter_dt *dtp, const fnode *f, char *dest, int length)
#define READF_TMP 50
char tmp[READF_TMP];
size_t buf_size = 0;
- int w, seen_dp, exponent;
+ ptrdiff_t w;
+ int seen_dp, exponent;
int exponent_sign;
const char *p;
char *buffer;
@@ -1230,9 +1229,10 @@ bad_float:
and never look at it. */
void
-read_x (st_parameter_dt *dtp, int n)
+read_x (st_parameter_dt *dtp, ptrdiff_t n)
{
- int length, q, q2;
+ ptrdiff_t length;
+ int q, q2;
if ((dtp->u.p.current_unit->pad_status == PAD_NO || is_internal_unit (dtp))
&& dtp->u.p.current_unit->bytes_left < n)
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index bfa9565..721c146 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -223,11 +223,11 @@ current_mode (st_parameter_dt *dtp)
/* Read sequential file - internal unit */
static char *
-read_sf_internal (st_parameter_dt *dtp, int *length)
+read_sf_internal (st_parameter_dt *dtp, ptrdiff_t *length)
{
static char *empty_string[0];
char *base = NULL;
- int lorig;
+ ptrdiff_t lorig;
/* Zero size array gives internal unit len of 0. Nothing to read. */
if (dtp->internal_unit_len == 0
@@ -256,11 +256,10 @@ read_sf_internal (st_parameter_dt *dtp, int *length)
lorig = *length;
if (is_char4_unit(dtp))
{
- int i;
gfc_char4_t *p = (gfc_char4_t *) mem_alloc_r4 (dtp->u.p.current_unit->s,
length);
base = fbuf_alloc (dtp->u.p.current_unit, lorig);
- for (i = 0; i < *length; i++, p++)
+ for (ptrdiff_t i = 0; i < *length; i++, p++)
base[i] = *p > 255 ? '?' : (unsigned char) *p;
}
else
@@ -297,11 +296,12 @@ read_sf_internal (st_parameter_dt *dtp, int *length)
/* Read sequential file - external unit */
static char *
-read_sf (st_parameter_dt *dtp, int *length)
+read_sf (st_parameter_dt *dtp, ptrdiff_t *length)
{
static char *empty_string[0];
+ ptrdiff_t lorig, n;
int q, q2;
- int n, lorig, seen_comma;
+ int seen_comma;
/* If we have seen an eor previously, return a length of 0. The
caller is responsible for correctly padding the input field. */
@@ -439,10 +439,10 @@ read_sf (st_parameter_dt *dtp, int *length)
short reads. */
void *
-read_block_form (st_parameter_dt *dtp, int *nbytes)
+read_block_form (st_parameter_dt *dtp, ptrdiff_t *nbytes)
{
char *source;
- int norig;
+ ptrdiff_t norig;
if (!is_stream_io (dtp))
{
@@ -534,11 +534,11 @@ read_block_form (st_parameter_dt *dtp, int *nbytes)
a character(kind=4) variable. Note: Portions of this code borrowed from
read_sf_internal. */
void *
-read_block_form4 (st_parameter_dt *dtp, int *nbytes)
+read_block_form4 (st_parameter_dt *dtp, ptrdiff_t *nbytes)
{
static gfc_char4_t *empty_string[0];
gfc_char4_t *source;
- int lorig;
+ ptrdiff_t lorig;
if (dtp->u.p.current_unit->bytes_left < (gfc_offset) *nbytes)
*nbytes = dtp->u.p.current_unit->bytes_left;
@@ -743,7 +743,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t nbytes)
fill in. Returns NULL on error. */
void *
-write_block (st_parameter_dt *dtp, int length)
+write_block (st_parameter_dt *dtp, ptrdiff_t length)
{
char *dest;
@@ -1792,7 +1792,7 @@ static void
formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kind,
size_t size)
{
- int pos, bytes_used;
+ gfc_offset pos, bytes_used;
const fnode *f;
format_token t;
int n;
@@ -1856,10 +1856,10 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin
{
if (dtp->u.p.skips > 0)
{
- int tmp;
+ gfc_offset tmp;
write_x (dtp, dtp->u.p.skips, dtp->u.p.pending_spaces);
- tmp = (int)(dtp->u.p.current_unit->recl
- - dtp->u.p.current_unit->bytes_left);
+ tmp = dtp->u.p.current_unit->recl
+ - dtp->u.p.current_unit->bytes_left;
dtp->u.p.max_pos =
dtp->u.p.max_pos > tmp ? dtp->u.p.max_pos : tmp;
dtp->u.p.skips = 0;
@@ -1875,8 +1875,8 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin
dtp->u.p.skips = dtp->u.p.pending_spaces = 0;
}
- bytes_used = (int)(dtp->u.p.current_unit->recl
- - dtp->u.p.current_unit->bytes_left);
+ bytes_used = dtp->u.p.current_unit->recl
+ - dtp->u.p.current_unit->bytes_left;
if (is_stream_io(dtp))
bytes_used = 0;
@@ -2231,7 +2231,7 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin
p = ((char *) p) + size;
}
- pos = (int)(dtp->u.p.current_unit->recl - dtp->u.p.current_unit->bytes_left);
+ pos = dtp->u.p.current_unit->recl - dtp->u.p.current_unit->bytes_left;
dtp->u.p.max_pos = (dtp->u.p.max_pos > pos) ? dtp->u.p.max_pos : pos;
}
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index 7a982b3..5df7848 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -776,7 +776,7 @@ buf_init (unix_stream *s)
*********************************************************************/
char *
-mem_alloc_r (stream *strm, int *len)
+mem_alloc_r (stream *strm, ptrdiff_t *len)
{
unix_stream *s = (unix_stream *) strm;
gfc_offset n;
@@ -796,7 +796,7 @@ mem_alloc_r (stream *strm, int *len)
char *
-mem_alloc_r4 (stream *strm, int *len)
+mem_alloc_r4 (stream *strm, ptrdiff_t *len)
{
unix_stream *s = (unix_stream *) strm;
gfc_offset n;
@@ -816,7 +816,7 @@ mem_alloc_r4 (stream *strm, int *len)
char *
-mem_alloc_w (stream *strm, int *len)
+mem_alloc_w (stream *strm, ptrdiff_t *len)
{
unix_stream *s = (unix_stream *)strm;
gfc_offset m;
@@ -837,7 +837,7 @@ mem_alloc_w (stream *strm, int *len)
gfc_char4_t *
-mem_alloc_w4 (stream *strm, int *len)
+mem_alloc_w4 (stream *strm, ptrdiff_t *len)
{
unix_stream *s = (unix_stream *)strm;
gfc_offset m;
@@ -863,7 +863,7 @@ static ssize_t
mem_read (stream *s, void *buf, ssize_t nbytes)
{
void *p;
- int nb = nbytes;
+ ptrdiff_t nb = nbytes;
p = mem_alloc_r (s, &nb);
if (p)
@@ -882,7 +882,7 @@ static ssize_t
mem_read4 (stream *s, void *buf, ssize_t nbytes)
{
void *p;
- int nb = nbytes;
+ ptrdiff_t nb = nbytes;
p = mem_alloc_r4 (s, &nb);
if (p)
@@ -901,7 +901,7 @@ static ssize_t
mem_write (stream *s, const void *buf, ssize_t nbytes)
{
void *p;
- int nb = nbytes;
+ ptrdiff_t nb = nbytes;
p = mem_alloc_w (s, &nb);
if (p)
@@ -920,7 +920,7 @@ static ssize_t
mem_write4 (stream *s, const void *buf, ssize_t nwords)
{
gfc_char4_t *p;
- int nw = nwords;
+ ptrdiff_t nw = nwords;
p = mem_alloc_w4 (s, &nw);
if (p)
@@ -1038,7 +1038,7 @@ static const struct stream_vtable mem4_vtable = {
internal file */
stream *
-open_internal (char *base, int length, gfc_offset offset)
+open_internal (char *base, ptrdiff_t length, gfc_offset offset)
{
unix_stream *s;
@@ -1058,7 +1058,7 @@ open_internal (char *base, int length, gfc_offset offset)
internal file */
stream *
-open_internal4 (char *base, int length, gfc_offset offset)
+open_internal4 (char *base, ptrdiff_t length, gfc_offset offset)
{
unix_stream *s;
diff --git a/libgfortran/io/unix.h b/libgfortran/io/unix.h
index 4ac92ee..80f7f43 100644
--- a/libgfortran/io/unix.h
+++ b/libgfortran/io/unix.h
@@ -108,22 +108,22 @@ internal_proto(compare_files);
extern stream *open_external (st_parameter_open *, unit_flags *);
internal_proto(open_external);
-extern stream *open_internal (char *, int, gfc_offset);
+extern stream *open_internal (char *, ptrdiff_t, gfc_offset);
internal_proto(open_internal);
-extern stream *open_internal4 (char *, int, gfc_offset);
+extern stream *open_internal4 (char *, ptrdiff_t, gfc_offset);
internal_proto(open_internal4);
-extern char *mem_alloc_w (stream *, int *);
+extern char *mem_alloc_w (stream *, ptrdiff_t *);
internal_proto(mem_alloc_w);
-extern char *mem_alloc_r (stream *, int *);
+extern char *mem_alloc_r (stream *, ptrdiff_t *);
internal_proto(mem_alloc_r);
-extern gfc_char4_t *mem_alloc_w4 (stream *, int *);
+extern gfc_char4_t *mem_alloc_w4 (stream *, ptrdiff_t *);
internal_proto(mem_alloc_w4);
-extern char *mem_alloc_r4 (stream *, int *);
+extern char *mem_alloc_r4 (stream *, ptrdiff_t *);
internal_proto(mem_alloc_r4);
extern stream *input_stream (void);
diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c
index 3b1168d..bcae439 100644
--- a/libgfortran/io/write.c
+++ b/libgfortran/io/write.c
@@ -235,7 +235,7 @@ write_utf8_char4 (st_parameter_dt *dtp, gfc_char4_t *source,
is set to the appropriate size to allocate. */
static void
-write_check_cc (st_parameter_dt *dtp, const char **source, int *alloc_len)
+write_check_cc (st_parameter_dt *dtp, const char **source, ptrdiff_t *alloc_len)
{
/* Only valid for CARRIAGECONTROL=FORTRAN. */
if (dtp->u.p.current_unit->flags.cc != CC_FORTRAN
@@ -311,7 +311,7 @@ write_check_cc (st_parameter_dt *dtp, const char **source, int *alloc_len)
after the start-of-record string was inserted. */
static char *
-write_cc (st_parameter_dt *dtp, char *p, int *source_len)
+write_cc (st_parameter_dt *dtp, char *p, ptrdiff_t *source_len)
{
/* Only valid for CARRIAGECONTROL=FORTRAN. */
if (dtp->u.p.current_unit->flags.cc != CC_FORTRAN || source_len == NULL)
@@ -360,9 +360,10 @@ write_cc (st_parameter_dt *dtp, char *p, int *source_len)
}
void
-write_a (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
+
+write_a (st_parameter_dt *dtp, const fnode *f, const char *source, ptrdiff_t len)
{
- int wlen;
+ ptrdiff_t wlen;
char *p;
wlen = f->u.string.length < 0
@@ -376,7 +377,7 @@ write_a (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
if (is_stream_io (dtp))
{
const char crlf[] = "\r\n";
- int i, q, bytes;
+ ptrdiff_t q, bytes;
q = bytes = 0;
/* Write out any padding if needed. */
@@ -389,7 +390,7 @@ write_a (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
}
/* Scan the source string looking for '\n' and convert it if found. */
- for (i = 0; i < wlen; i++)
+ for (ptrdiff_t i = 0; i < wlen; i++)
{
if (source[i] == '\n')
{
@@ -471,9 +472,9 @@ write_a (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
to the UTF-8 encoded string before writing out. */
void
-write_a_char4 (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
+write_a_char4 (st_parameter_dt *dtp, const fnode *f, const char *source, ptrdiff_t len)
{
- int wlen;
+ ptrdiff_t wlen;
gfc_char4_t *q;
wlen = f->u.string.length < 0
@@ -488,7 +489,7 @@ write_a_char4 (st_parameter_dt *dtp, const fnode *f, const char *source, int len
if (is_stream_io (dtp))
{
const gfc_char4_t crlf[] = {0x000d,0x000a};
- int i, bytes;
+ ptrdiff_t bytes;
gfc_char4_t *qq;
bytes = 0;
@@ -504,7 +505,7 @@ write_a_char4 (st_parameter_dt *dtp, const fnode *f, const char *source, int len
/* Scan the source string looking for '\n' and convert it if found. */
qq = (gfc_char4_t *) source;
- for (i = 0; i < wlen; i++)
+ for (ptrdiff_t i = 0; i < wlen; i++)
{
if (qq[i] == '\n')
{
--
2.7.4
program main
character(len=2_8**31+1) :: b
b = ""
b(len(b, 8):len(b, 8)) = "b"
open(10, file="largewrite.txt", status="replace", action="write")
write(10, '(A)') b
close(10)
! Try to read what we wrote
b(len(b, 8):len(b, 8)) = "x"
open(10, file="largewrite.txt", action="read")
read(10, '(A)') b
close(10)
if (b(len(b, 8):len(b, 8)) /= "b") then
print *, "Last char of b: ", b(len(b, 8):len(b, 8)), "END"
call abort()
end if
! Same but with list formatted read
b(len(b, 8):len(b, 8)) = "x"
b(1:1) = 'y'
open(10, file="largewrite.txt", action="read")
read(10, *) b
! List formatted skips the initial blanks, so the last and only
! character in the original string will become the first.
if (b(1:1) /= "b") then
print *, "First char of b: ", b(1:1), 'END'
print *, "Last char of b: ", b(len(b, 8):len(b, 8)), "END"
call abort()
end if
end program main
program main
character(len=2_8**31+1) :: b
b = ""
b(len(b, 8):len(b, 8)) = "b"
open(10, file="largewrite_charunform.dat", access="stream", form="unformatted")
write (10) b
close(10)
b(len(b, 8):len(b, 8)) = "x"
open(10, file="largewrite_charunform.dat", access="stream", form="unformatted")
read (10) b
if (b(len(b, 8):len(b, 8)) /= 'b') then
call abort()
end if
end program main