This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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  <>

	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);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]