This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

Re: Partial fix for libgcj/9802


>>>>> "Mark" == Mark Wielaard <mark at klomp dot org> writes:

Mark> Note that the reason for the minimal 5 line patch were that we are very
Mark> close to a release. I hoped to solve the issue with UTF-8 surrogates
Mark> without impacting any other encoding issues. Otherwise I am afraid that
Mark> "the powers that be" will not accept the change for 3.3.

Yeah, it is scary to change this code.

Mark> But the natIconv.cc source code says:
Mark>   // Note that we can't check `errno' because
Mark>   // glibc 2.1.3 doesn't set it correctly.  We could check it if we
Mark>   // really needed to, but we'd have to disable support for 2.1.3.
Mark> Don't know how important supporting 2.1.3 is at this time. (Tom, I
Mark> assume you wrote this comment?)

I think 2.1.3 shipped in Red Hat Linux 6.2.  That's pretty old these
days.

I sent a patch in this area a long time ago but never checked it in.
I've appended it for your perusal.  Maybe it is time for this to go
in?  This patch basically disables our ability to work with an old
glibc.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey at redhat dot com>

	* gnu/gcj/convert/natIconv.cc (write): Handle case where
	output buffer is too small.

Index: gnu/gcj/convert/natIconv.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/convert/natIconv.cc,v
retrieving revision 1.13
diff -u -r1.13 natIconv.cc
--- gnu/gcj/convert/natIconv.cc 18 Feb 2002 02:52:44 -0000 1.13
+++ gnu/gcj/convert/natIconv.cc 16 Aug 2002 21:37:39 -0000
@@ -1,6 +1,6 @@
-// Input_iconv.java -- Java side of iconv() reader.
+// natIconv.cc -- Java side of iconv() reader.
 
-/* Copyright (C) 2000, 2001  Free Software Foundation
+/* Copyright (C) 2000, 2001, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -201,25 +201,39 @@
       inbuf = (char *) temp_buffer;
     }
 
-  // If the conversion fails on the very first character, then we
-  // assume that the character can't be represented in the output
-  // encoding.  There's nothing useful we can do here, so we simply
-  // omit that character.  Note that we can't check `errno' because
-  // glibc 2.1.3 doesn't set it correctly.  We could check it if we
-  // really needed to, but we'd have to disable support for 2.1.3.
   size_t loop_old_in = old_in;
   while (1)
     {
       size_t r = iconv_adapter (iconv, (iconv_t) handle,
 				&inbuf, &inavail,
 				&outbuf, &outavail);
-      if (r == (size_t) -1 && inavail == loop_old_in)
+      if (r == (size_t) -1)
 	{
-	  inavail -= 2;
-	  if (inavail == 0)
-	    break;
-	  loop_old_in -= 2;
-	  inbuf += 2;
+	  if (errno == EINVAL)
+	    {
+	      // Incomplete byte sequence at the end of the input
+	      // buffer.  This shouldn't be able to happen here.
+	      break;
+	    }
+	  else if (errno == E2BIG)
+	    {
+	      // Output buffer is too small.
+	      break;
+	    }
+	  else if (errno == EILSEQ || inavail == loop_old_in)
+	    {
+	      // Untranslatable sequence.  Since glibc 2.1.3 doesn't
+	      // properly set errno, we also assume that this is what
+	      // is happening if no conversions took place.  (This can
+	      // be a bogus assumption if in fact the output buffer is
+	      // too small.)  We skip the first character and try
+	      // again.
+	      inavail -= 2;
+	      if (inavail == 0)
+		break;
+	      loop_old_in -= 2;
+	      inbuf += 2;
+	    }
 	}
       else
 	break;


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