aboutsummaryrefslogtreecommitdiffstats
path: root/community/gcc6/fix-gcj-iconv-musl.patch
blob: b0015751e2b16edc1c348e027de33ecf18e6e3b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
--- gcc-4.8.2/libjava/gnu/gcj/convert/natIconv.cc.orig	2014-02-18 18:46:14.897880526 +0200
+++ gcc-4.8.2/libjava/gnu/gcj/convert/natIconv.cc	2014-02-18 18:50:08.766613550 +0200
@@ -24,6 +24,13 @@
 
 #ifdef HAVE_ICONV
 #include <iconv.h>
+#include <endian.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define UCS2_CHARSET "UCS-2BE"
+#else
+#define UCS2_CHARSET "UCS-2LE"
+#endif
 
 template<typename T>
 static inline size_t
@@ -45,7 +52,7 @@
   _Jv_GetStringUTFRegion (encoding, 0, encoding->length(), buffer);
   buffer[len] = '\0';
 
-  iconv_t h = iconv_open ("UCS-2", buffer);
+  iconv_t h = iconv_open (UCS2_CHARSET, buffer);
   if (h == (iconv_t) -1)
     throw new ::java::io::UnsupportedEncodingException (encoding);
 
@@ -99,18 +106,6 @@
 	throw new ::java::io::CharConversionException ();
     }
 
-  if (iconv_byte_swap)
-    {
-      size_t max = (old_out - outavail) / sizeof (jchar);
-      for (size_t i = 0; i < max; ++i)
-	{
-	  // Byte swap.
-	  jchar c = (((out[outpos + i] & 0xff) << 8)
-		     | ((out[outpos + i] >> 8) & 0xff));
-	  outbuf[i] = c;
-	}
-    }
-
   inpos += old_in - inavail;
   return (old_out - outavail) / sizeof (jchar);
 #else /* HAVE_ICONV */
@@ -145,7 +140,7 @@
   _Jv_GetStringUTFRegion (encoding, 0, encoding->length(), buffer);
   buffer[len] = '\0';
 
-  iconv_t h = iconv_open (buffer, "UCS-2");
+  iconv_t h = iconv_open (buffer, UCS2_CHARSET);
   if (h == (iconv_t) -1)
     throw new ::java::io::UnsupportedEncodingException (encoding);
 
@@ -187,20 +182,6 @@
   char *inbuf = (char *) &chars[inpos];
   char *outbuf = (char *) &out[count];
 
-  if (iconv_byte_swap)
-    {
-      // Ugly performance penalty -- don't use losing systems!
-      temp_buffer = (jchar *) _Jv_Malloc (inlength * sizeof (jchar));
-      for (int i = 0; i < inlength; ++i)
-	{
-	  // Byte swap.
-	  jchar c = (((chars[inpos + i] & 0xff) << 8)
-		     | ((chars[inpos + i] >> 8) & 0xff));
-	  temp_buffer[i] = c;
-	}
-      inbuf = (char *) temp_buffer;
-    }
-
   size_t loop_old_in = old_in;
   while (1)
     {
@@ -252,44 +233,7 @@
 jboolean
 gnu::gcj::convert::IOConverter::iconv_init (void)
 {
-  // Some versions of iconv() always return their UCS-2 results in
-  // big-endian order, and they also require UCS-2 inputs to be in
-  // big-endian order.  For instance, glibc 2.1.3 does this.  If the
-  // UTF-8=>UCS-2 iconv converter has this feature, then we assume
-  // that all UCS-2 converters do.  (This might not be the best
-  // heuristic, but is is all we've got.)
-  jboolean result = false;
-#ifdef HAVE_ICONV
-  iconv_t handle = iconv_open ("UCS-2", "UTF-8");
-  if (handle != (iconv_t) -1)
-    {
-      jchar c;
-      unsigned char in[4];
-      char *inp, *outp;
-      size_t inc, outc, r;
-
-      // This is the UTF-8 encoding of \ufeff.  At least Tru64 UNIX libiconv
-      // needs the trailing NUL byte, otherwise iconv fails with EINVAL.
-      in[0] = 0xef;
-      in[1] = 0xbb;
-      in[2] = 0xbf;
-      in[3] = 0x00;
-
-      inp = (char *) in;
-      inc = 4;
-      outp = (char *) &c;
-      outc = 2;
-
-      r = iconv_adapter (iconv, handle, &inp, &inc, &outp, &outc);
-      // Conversion must be complete for us to use the result.
-      if (r != (size_t) -1 && inc == 0 && outc == 0)
-	result = (c != 0xfeff);
-
-      // Release iconv handle.
-      iconv_close (handle);
-    }
-#endif /* HAVE_ICONV */
-  return result;
+  return false;
 }
 
 void