This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR 18710: unformatted I/O of COMPLEX numbers
- From: Tobias Schlüter <tobias dot schlueter at physik dot uni-muenchen dot de>
- To: GCC Fortran mailing list <fortran at gcc dot gnu dot org>,patch <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 30 Nov 2004 13:10:30 +0100
- Subject: [PATCH] Fix PR 18710: unformatted I/O of COMPLEX numbers
In an unformatted write or read only the real part of a complex number was
transferred. This is because the library's interface to transfer functions
passes the variables data kind, but the unformatted data transfer routines
expect the data's width which is twice the kind for complex numbers.
Fortunately, the data type also gets passed to the transfer routine, so this
is easily fixed.
Bubblestrapped & tested on i686-pc-linux-gnu, this fixes the testcase from the
PR, and I will commit a similar testcase alongside the patch. Ok?
- Tobi
2004-11-30 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
PR fortran/18710
* io/transfer.c (unformatted_read, unformatted_write): width of
a COMPLEX is twice its kind.
Index: libgfortran/io/transfer.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/transfer.c,v
retrieving revision 1.17
diff -u -p -r1.17 transfer.c
--- libgfortran/io/transfer.c 7 Oct 2004 21:30:50 -0000 1.17
+++ libgfortran/io/transfer.c 29 Nov 2004 23:33:11 -0000
@@ -271,6 +271,10 @@ unformatted_read (bt type, void *dest, i
{
void *source;
int w;
+
+ if (type == BT_COMPLEX)
+ length *= 2;
+
w = length;
source = read_block (&w);
@@ -288,9 +292,13 @@ static void
unformatted_write (bt type, void *source, int length)
{
void *dest;
- dest = write_block (length);
- if (dest != NULL)
- memcpy (dest, source, length);
+
+ if (type == BT_COMPLEX)
+ length *= 2;
+
+ dest = write_block (length);
+ if (dest != NULL)
+ memcpy (dest, source, length);
}