]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - iconvdata/iso646.c
Use glibc_likely instead __builtin_expect.
[thirdparty/glibc.git] / iconvdata / iso646.c
index 99dc0251b09019fa7933e5609d0f000cb3bbb7bf..b450fcc9622171a92a98768468924efefe49e9d9 100644 (file)
@@ -1,22 +1,21 @@
 /* Conversion to and from the various ISO 646 CCS.
-   Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1998-2014 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 /* The implementation of the conversion which can be performed by this
    module are not very sophisticated and not tuned at all.  There are
@@ -62,7 +61,6 @@ enum direction
 enum variant
 {
   illegal_var,
-  US,          /* ANSI_X3.4-1968 */
   GB,          /* BS_4730 */
   CA,          /* CSA_Z243.4-1985-1 */
   CA2,         /* CSA_Z243.4-1985-2 */
@@ -90,7 +88,6 @@ enum variant
 
 static const char *names[] =
 {
-  [US] = "ANSI_X3.4-1968//",
   [GB] = "BS_4730//",
   [CA] = "CSA_Z243.4-1985-1//",
   [CA2] = "CSA_Z243.4-1985-2//",
@@ -124,6 +121,7 @@ struct iso646_data
 };
 
 
+extern int gconv_init (struct __gconv_step *step);
 int
 gconv_init (struct __gconv_step *step)
 {
@@ -157,7 +155,7 @@ gconv_init (struct __gconv_step *step)
          new_data->var = var;
          step->__data = new_data;
 
-         if (var == from_iso646)
+         if (dir == from_iso646)
            {
              step->__min_needed_from = MIN_NEEDED_FROM;
              step->__max_needed_from = MIN_NEEDED_FROM;
@@ -182,6 +180,7 @@ gconv_init (struct __gconv_step *step)
 }
 
 
+extern void gconv_end (struct __gconv_step *data);
 void
 gconv_end (struct __gconv_step *data)
 {
@@ -407,14 +406,7 @@ gconv_end (struct __gconv_step *data)
        when we reach the default case in the `switch' statement.  */         \
     if (__builtin_expect (failure, __GCONV_OK) == __GCONV_ILLEGAL_INPUT)      \
       {                                                                              \
-       if (! ignore_errors_p ())                                             \
-         {                                                                   \
-           /* Exit the loop with an error.  */                               \
-           result = __GCONV_ILLEGAL_INPUT;                                   \
-           break;                                                            \
-         }                                                                   \
-                                                                             \
-       ++*irreversible;                                                      \
+       STANDARD_FROM_LOOP_ERR_HANDLER (1);                                   \
       }                                                                              \
     else                                                                     \
       {                                                                              \
@@ -434,11 +426,11 @@ gconv_end (struct __gconv_step *data)
 #define LOOPFCT                        TO_LOOP
 #define BODY \
   {                                                                          \
-    unsigned char ch;                                                        \
+    unsigned int ch;                                                         \
     int failure = __GCONV_OK;                                                \
                                                                              \
     ch = get32 (inptr);                                                              \
-    switch (*((uint32_t *) inptr))                                           \
+    switch (ch)                                                                      \
       {                                                                              \
       case 0x23:                                                             \
        if (var == GB || var == ES || var == IT || var == FR || var == FR1    \
@@ -878,14 +870,17 @@ gconv_end (struct __gconv_step *data)
        ch = 0x5d;                                                            \
        break;                                                                \
       default:                                                               \
-       if (*((uint32_t *) inptr) > 0x7f)                                     \
-         failure = __GCONV_ILLEGAL_INPUT;                                    \
+       if (__glibc_unlikely (ch > 0x7f))                                     \
+         {                                                                   \
+           UNICODE_TAG_HANDLER (ch, 4);                                      \
+           failure = __GCONV_ILLEGAL_INPUT;                                  \
+         }                                                                   \
        break;                                                                \
       }                                                                              \
                                                                              \
     if (__builtin_expect (failure, __GCONV_OK) == __GCONV_ILLEGAL_INPUT)      \
       {                                                                              \
-       STANDARD_ERR_HANDLER (4);                                             \
+       STANDARD_TO_LOOP_ERR_HANDLER (4);                                     \
       }                                                                              \
                                                                              \
     *outptr++ = (unsigned char) ch;                                          \