* [patch, libgfortran] PR99210 X editing for reading file with encoding='utf-8'
@ 2024-02-13 22:55 Jerry DeLisle
2024-02-14 13:11 ` FX Coudert
0 siblings, 1 reply; 2+ messages in thread
From: Jerry DeLisle @ 2024-02-13 22:55 UTC (permalink / raw)
To: gfortran; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 193 bytes --]
The attached patch fixes the X editing.
Fairly self explanatory. I created the patch a few years back.
Regression tested on x86_64 and new test case.
OK for trunk?
Regards,
Jerry
[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 1548 bytes --]
diff --git a/gcc/testsuite/gfortran.dg/pr99210.f90 b/gcc/testsuite/gfortran.dg/pr99210.f90
new file mode 100644
index 00000000000..9fd2fb468df
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr99210.f90
@@ -0,0 +1,29 @@
+! { dg-do run }
+! PR99210 X editing for reading file with encoding='utf-8'
+program test_bug_format_x
+ use iso_fortran_env
+ integer, parameter :: u = selected_char_kind('ISO_10646')
+
+ character(kind=u, len=1) a, b, a1, b1, b2
+
+ open(unit=10, file='test_bug_format_x.tmp', encoding='UTF-8')
+
+ a = char(int(z'03B1'), u)
+ b = char(int(z'03B2'), u)
+ write(10, '(a1, a1)') a, b
+
+ rewind(10)
+ read(10, '(a1, a1)') a1, b1
+
+ rewind(10)
+ read(10, '(1x, a1)') b2
+
+ close (10, status="delete")
+ if(a /= a1 .or. b /= b1) then
+ error stop 1
+ end if
+
+ if(b /= b2) then
+ error stop 2
+ end if
+end program test_bug_format_x
diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c
index 0ffcf76fd38..e2d2f8be806 100644
--- a/libgfortran/io/read.c
+++ b/libgfortran/io/read.c
@@ -1307,6 +1307,23 @@ read_x (st_parameter_dt *dtp, size_t n)
if (n == 0)
return;
+
+ if (dtp->u.p.current_unit->flags.encoding == ENCODING_UTF8)
+ {
+ gfc_char4_t c;
+ size_t nbytes, j;
+
+ /* Proceed with decoding one character at a time. */
+ for (j = 0; j < n; j++)
+ {
+ c = read_utf8 (dtp, &nbytes);
+
+ /* Check for a short read and if so, break out. */
+ if (nbytes == 0 || c == (gfc_char4_t)0)
+ break;
+ }
+ return;
+ }
length = n;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch, libgfortran] PR99210 X editing for reading file with encoding='utf-8'
2024-02-13 22:55 [patch, libgfortran] PR99210 X editing for reading file with encoding='utf-8' Jerry DeLisle
@ 2024-02-14 13:11 ` FX Coudert
0 siblings, 0 replies; 2+ messages in thread
From: FX Coudert @ 2024-02-14 13:11 UTC (permalink / raw)
To: Jerry DeLisle; +Cc: gfortran, gcc-patches
> Regression tested on x86_64 and new test case.
> OK for trunk?
OK, and thanks!
FX
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-14 13:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13 22:55 [patch, libgfortran] PR99210 X editing for reading file with encoding='utf-8' Jerry DeLisle
2024-02-14 13:11 ` FX Coudert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).