Simplify calling convention of u*_conv_from_encoding.
authorBruno Haible <bruno@clisp.org>
Sun, 26 Apr 2009 14:43:25 +0000 (16:43 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 26 Apr 2009 14:43:25 +0000 (16:43 +0200)
15 files changed:
ChangeLog
NEWS
lib/unicase/ulc-casecmp.c
lib/unicase/ulc-casexfrm.c
lib/uniconv.h
lib/uniconv/u-conv-from-enc.h
lib/uniconv/u-strconv-from-enc.h
lib/uniconv/u8-conv-from-enc.c
lib/unilbrk/ulc-possible-linebreaks.c
lib/unilbrk/ulc-width-linebreaks.c
lib/uniwbrk/ulc-wordbreaks.c
lib/vasnprintf.c
tests/uniconv/test-u16-conv-from-enc.c
tests/uniconv/test-u32-conv-from-enc.c
tests/uniconv/test-u8-conv-from-enc.c

index d1a4044..41b018e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
 2009-04-26  Bruno Haible  <bruno@clisp.org>
 
+       Simplify calling convention of u*_conv_from_encoding.
+       * lib/uniconv.h (u8_conv_from_encoding, u16_conv_from_encoding,
+       u32_conv_from_encoding): Expect a resultbuf argument and return the
+       result directly as a pointer.
+       * lib/uniconv/u8-conv-from-enc.c (u8_conv_from_encoding): Likewise.
+       * lib/uniconv/u-conv-from-enc.h (FUNC): Likewise.
+       * lib/uniconv/u-strconv-from-enc.h (FUNC): Update.
+       * lib/unicase/ulc-casecmp.c (ulc_u8_casefold): Update.
+       * lib/unicase/ulc-casexfrm.c (ulc_casexfrm): Update.
+       * lib/unilbrk/ulc-possible-linebreaks.c (ulc_possible_linebreaks):
+       Update.
+       * lib/unilbrk/ulc-width-linebreaks.c (ulc_width_linebreaks): Update.
+       * lib/uniwbrk/ulc-wordbreaks.c (ulc_wordbreaks): Update.
+       * lib/vasnprintf.c (VASNPRINTF): Update.
+       * tests/uniconv/test-u8-conv-from-enc.c (main): Update.
+       * tests/uniconv/test-u16-conv-from-enc.c (main): Update.
+       * tests/uniconv/test-u32-conv-from-enc.c (main): Update.
+       * NEWS: Mention the change.
+
+2009-04-26  Bruno Haible  <bruno@clisp.org>
+
        Simplify calling convention of u*_conv_to_encoding.
        * lib/uniconv.h (u8_conv_to_encoding, u16_conv_to_encoding,
        u32_conv_to_encoding): Expect a resultbuf argument and return the
diff --git a/NEWS b/NEWS
index 9e51a03..005fa7e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,12 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2009-04-26  modules/uniconv/u8-conv-from-enc
+            modules/uniconv/u16-conv-from-enc
+            modules/uniconv/u32-conv-from-enc
+                            The calling convention of the functions
+                            u*_conv_from_encoding is changed.
+
 2009-04-26  modules/uniconv/u8-conv-to-enc
             modules/uniconv/u16-conv-to-enc
             modules/uniconv/u32-conv-to-enc
index c061b24..e071021 100644 (file)
@@ -39,10 +39,11 @@ ulc_u8_casefold (const char *s, size_t n, const char *iso639_language,
   uint8_t *result;
 
   /* Convert the string to UTF-8.  */
-  conv = convbuf;
   conv_length = sizeof (convbuf) / sizeof (uint8_t);
-  if (u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL,
-                            &conv, &conv_length) < 0)
+  conv =
+    u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL,
+                          convbuf, &conv_length);
+  if (conv == NULL)
     /* errno is set here.  */
     return NULL;
 
index 00009f8..aded556 100644 (file)
@@ -36,10 +36,11 @@ ulc_casexfrm (const char *s, size_t n, const char *iso639_language,
   char *result;
 
   /* Convert the string to UTF-8.  */
-  conv = convbuf;
   conv_length = sizeof (convbuf) / sizeof (uint8_t);
-  if (u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL,
-                            &conv, &conv_length) < 0)
+  conv =
+    u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL,
+                          convbuf, &conv_length);
+  if (conv == NULL)
     /* errno is set here.  */
     return NULL;
 
index d364202..74eaee5 100644 (file)
@@ -51,28 +51,30 @@ extern "C" {
    or *RESULTP can initially be NULL.
    May erase the contents of the memory at *RESULTP.
    Return value: 0 if successful, otherwise -1 and errno set.
-   If successful: The resulting string is stored in *RESULTP and its length
-   in *LENGTHP.  *RESULTP is set to a freshly allocated memory block, or is
-   unchanged if no dynamic memory allocation was necessary.
-   Particular errno values: EINVAL, EILSEQ, ENOMEM.  */
-extern int
+   If successful: The resulting Unicode string (non-NULL) is returned and its
+   length stored in *LENGTHP.  The resulting string is RESULTBUF if no dynamic
+   memory allocation was necessary, or a freshly allocated memory block
+   otherwise.
+   In case of error: NULL is returned and errno is set.  Particular errno
+   values: EINVAL, EILSEQ, ENOMEM.  */
+extern uint8_t *
        u8_conv_from_encoding (const char *fromcode,
                              enum iconv_ilseq_handler handler,
                              const char *src, size_t srclen,
                              size_t *offsets,
-                             uint8_t **resultp, size_t *lengthp);
-extern int
+                             uint8_t *resultbuf, size_t *lengthp);
+extern uint16_t *
        u16_conv_from_encoding (const char *fromcode,
                               enum iconv_ilseq_handler handler,
                               const char *src, size_t srclen,
                               size_t *offsets,
-                              uint16_t **resultp, size_t *lengthp);
-extern int
+                              uint16_t *resultbuf, size_t *lengthp);
+extern uint32_t *
        u32_conv_from_encoding (const char *fromcode,
                               enum iconv_ilseq_handler handler,
                               const char *src, size_t srclen,
                               size_t *offsets,
-                              uint32_t **resultp, size_t *lengthp);
+                              uint32_t *resultbuf, size_t *lengthp);
 
 /* Converts an entire Unicode string, possibly including NUL units, from a
    Unicode encoding to a given encoding.
index 4fc566d..fa0f0d3 100644 (file)
@@ -1,5 +1,5 @@
 /* Conversion to UTF-16/UTF-32 from legacy encodings.
-   Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2006-2007, 2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as published
    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-int
+UNIT *
 FUNC (const char *fromcode,
       enum iconv_ilseq_handler handler,
       const char *src, size_t srclen,
       size_t *offsets,
-      UNIT **resultp, size_t *lengthp)
+      UNIT *resultbuf, size_t *lengthp)
 {
 #if HAVE_UTF_NAME
-  size_t length;
+  char *result = (char *) resultbuf;
+  size_t length = *lengthp * sizeof (UNIT);
 
   if (mem_iconveha (src, srclen, fromcode, UTF_NAME, true, handler,
-                   offsets, (char **) resultp, &length) < 0)
-    return -1;
+                   offsets, &result, &length) < 0)
+    return NULL;
   if (offsets != NULL)
     {
       /* Convert 'char *' offsets to 'UNIT *' offsets.  */
@@ -40,27 +41,24 @@ FUNC (const char *fromcode,
   if ((length % sizeof (UNIT)) != 0)
     abort ();
   *lengthp = length / sizeof (UNIT);
-  return 0;
+  return (UNIT *) result;
 #else
-  uint8_t *utf8_string = NULL;
-  size_t utf8_length = 0;
+  uint8_t *utf8_string;
+  size_t utf8_length;
   UNIT *result;
 
-  if (u8_conv_from_encoding (fromcode, handler, src, srclen, offsets,
-                            &utf8_string, &utf8_length) < 0)
-    return -1;
+  utf8_string =
+    u8_conv_from_encoding (fromcode, handler, src, srclen, offsets,
+                          NULL, &utf8_length);
   if (utf8_string == NULL)
-    {
-      *lengthp = 0;
-      return 0;
-    }
-  result = U8_TO_U (utf8_string, utf8_length, *resultp, lengthp);
+    return NULL;
+  result = U8_TO_U (utf8_string, utf8_length, resultbuf, lengthp);
   if (result == NULL)
     {
       int saved_errno = errno;
       free (utf8_string);
       errno = saved_errno;
-      return -1;
+      return NULL;
     }
   if (offsets != NULL)
     {
@@ -88,7 +86,6 @@ FUNC (const char *fromcode,
          }
     }
   free (utf8_string);
-  *resultp = result;
-  return 0;
+  return result;
 #endif
 }
index 19d8b3e..25813c7 100644 (file)
@@ -1,5 +1,5 @@
 /* Conversion to UTF-8/UTF-16/UTF-32 from legacy encodings.
-   Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2006-2007, 2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as published
@@ -19,12 +19,14 @@ FUNC (const char *string,
       const char *fromcode,
       enum iconv_ilseq_handler handler)
 {
-  UNIT *result = NULL;
-  size_t length = 0;
+  UNIT *result;
+  size_t length;
 
-  if (U_CONV_FROM_ENCODING (fromcode, handler,
-                           string, strlen (string) + 1, NULL,
-                           &result, &length) < 0)
+  result =
+    U_CONV_FROM_ENCODING (fromcode, handler,
+                         string, strlen (string) + 1, NULL,
+                         NULL, &length);
+  if (result == NULL)
     return NULL;
   /* Verify the result has exactly one NUL unit, at the end.  */
   if (!(length > 0 && result[length-1] == 0
index 09eba1e..7605e63 100644 (file)
 #include "striconveha.h"
 #include "unistr.h"
 
-int
+uint8_t *
 u8_conv_from_encoding (const char *fromcode,
                       enum iconv_ilseq_handler handler,
                       const char *src, size_t srclen,
                       size_t *offsets,
-                      uint8_t **resultp, size_t *lengthp)
+                      uint8_t *resultbuf, size_t *lengthp)
 {
   if (STRCASEEQ (fromcode, "UTF-8", 'U','T','F','-','8',0,0,0,0))
     {
@@ -44,7 +44,7 @@ u8_conv_from_encoding (const char *fromcode,
       if (u8_check ((const uint8_t *) src, srclen))
        {
          errno = EILSEQ;
-         return -1;
+         return NULL;
        }
 
       if (offsets != NULL)
@@ -65,24 +65,41 @@ u8_conv_from_encoding (const char *fromcode,
        }
 
       /* Memory allocation.  */
-      if ((*resultp != NULL && *lengthp >= srclen) || srclen == 0)
-       result = *resultp;
+      if (resultbuf != NULL && *lengthp >= srclen)
+       result = resultbuf;
       else
        {
-         result = (uint8_t *) malloc (srclen);
+         result = (uint8_t *) malloc (srclen > 0 ? srclen : 1);
          if (result == NULL)
            {
              errno = ENOMEM;
-             return -1;
+             return NULL;
            }
        }
 
       memcpy ((char *) result, src, srclen);
-      *resultp = result;
       *lengthp = srclen;
-      return 0;
+      return result;
     }
   else
-    return mem_iconveha (src, srclen, fromcode, "UTF-8", true, handler,
-                        offsets, (char **) resultp, lengthp);
+    {
+      char *result = (char *) resultbuf;
+      size_t length = *lengthp;
+
+      if (mem_iconveha (src, srclen, fromcode, "UTF-8", true, handler,
+                       offsets, &result, &length) < 0)
+       return NULL;
+
+      if (result == NULL) /* when (resultbuf == NULL && length == 0)  */
+       {
+         result = (char *) malloc (1);
+         if (result == NULL)
+           {
+             errno = ENOMEM;
+             return NULL;
+           }
+       }
+      *lengthp = length;
+      return (uint8_t *) result;
+    }
 }
index 2032154..cb95241 100644 (file)
@@ -56,11 +56,12 @@ ulc_possible_linebreaks (const char *s, size_t n, const char *encoding,
 
          if (offsets != NULL)
            {
-             uint8_t *t = NULL;
+             uint8_t *t;
              size_t m;
-             if (u8_conv_from_encoding (encoding, iconveh_question_mark,
-                                        s, n, offsets, &t, &m)
-                 == 0)
+
+             t = u8_conv_from_encoding (encoding, iconveh_question_mark,
+                                        s, n, offsets, NULL, &m);
+             if (t != NULL)
                {
                  char *q = (char *) (m > 0 ? malloc (m) : NULL);
 
index 71354ae..3b091bf 100644 (file)
@@ -58,11 +58,12 @@ ulc_width_linebreaks (const char *s, size_t n,
 
          if (offsets != NULL)
            {
-             uint8_t *t = NULL;
+             uint8_t *t;
              size_t m;
-             if (u8_conv_from_encoding (encoding, iconveh_question_mark,
-                                        s, n, offsets, &t, &m)
-                 == 0)
+
+             t = u8_conv_from_encoding (encoding, iconveh_question_mark,
+                                        s, n, offsets, NULL, &m);
+             if (t != NULL)
                {
                  char *memory =
                    (char *) (m > 0 ? malloc (m + (o != NULL ? m : 0)) : NULL);
index b97b13d..cb6e131 100644 (file)
@@ -58,11 +58,12 @@ ulc_wordbreaks (const char *s, size_t n, char *p)
 
          if (offsets != NULL)
            {
-             uint8_t *t = NULL;
+             uint8_t *t;
              size_t m;
-             if (u8_conv_from_encoding (encoding, iconveh_question_mark,
-                                        s, n, offsets, &t, &m)
-                 == 0)
+
+             t = u8_conv_from_encoding (encoding, iconveh_question_mark,
+                                        s, n, offsets, NULL, &m);
+             if (t != NULL)
                {
                  char *q = (char *) (m > 0 ? malloc (m) : NULL);
 
index 51375eb..a5b07d9 100644 (file)
@@ -2493,14 +2493,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                  }
 
                  /* Convert from TCHAR_T[] to DCHAR_T[].  */
-                 tmpdst = NULL;
-                 tmpdst_len = 0;
-                 if (DCHAR_CONV_FROM_ENCODING (locale_charset (),
-                                               iconveh_question_mark,
-                                               tmpsrc, characters,
-                                               NULL,
-                                               &tmpdst, &tmpdst_len)
-                     < 0)
+                 tmpdst =
+                   DCHAR_CONV_FROM_ENCODING (locale_charset (),
+                                             iconveh_question_mark,
+                                             tmpsrc, characters,
+                                             NULL,
+                                             NULL, &tmpdst_len);
+                 if (tmpdst == NULL)
                    {
                      int saved_errno = errno;
                      free (tmpsrc);
@@ -5216,14 +5215,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 # else
                        tmpsrc = tmp;
 # endif
-                       tmpdst = NULL;
-                       tmpdst_len = 0;
-                       if (DCHAR_CONV_FROM_ENCODING (locale_charset (),
-                                                     iconveh_question_mark,
-                                                     tmpsrc, count,
-                                                     NULL,
-                                                     &tmpdst, &tmpdst_len)
-                           < 0)
+                       tmpdst =
+                         DCHAR_CONV_FROM_ENCODING (locale_charset (),
+                                                   iconveh_question_mark,
+                                                   tmpsrc, count,
+                                                   NULL,
+                                                   NULL, &tmpdst_len);
+                       if (tmpdst == NULL)
                          {
                            int saved_errno = errno;
                            if (!(result == resultbuf || result == NULL))
index 69467e0..ac7617b 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of conversion to UTF-16 from legacy encodings.
-   Copyright (C) 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2007-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -77,15 +77,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint16_t *result = NULL;
-         size_t length = 0;
-         int retval = u16_conv_from_encoding ("ISO-8859-1", handler,
-                                              input, strlen (input),
-                                              offsets,
-                                              &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint16_t *result = u16_conv_from_encoding ("ISO-8859-1", handler,
+                                                    input, strlen (input),
+                                                    offsets,
+                                                    NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == SIZEOF (expected));
-         ASSERT (result != NULL && u16_cmp (result, expected, SIZEOF (expected)) == 0);
+         ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 37; i++)
@@ -110,15 +109,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint16_t *result = NULL;
-         size_t length = 0;
-         int retval = u16_conv_from_encoding ("ISO-8859-2", handler,
-                                              input, strlen (input),
-                                              offsets,
-                                              &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint16_t *result = u16_conv_from_encoding ("ISO-8859-2", handler,
+                                                    input, strlen (input),
+                                                    offsets,
+                                                    NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == SIZEOF (expected));
-         ASSERT (result != NULL && u16_cmp (result, expected, SIZEOF (expected)) == 0);
+         ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 16; i++)
@@ -144,15 +142,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint16_t *result = NULL;
-         size_t length = 0;
-         int retval = u16_conv_from_encoding ("autodetect_jp", handler,
-                                              input, strlen (input),
-                                              offsets,
-                                              &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler,
+                                                    input, strlen (input),
+                                                    offsets,
+                                                    NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == SIZEOF (expected));
-         ASSERT (result != NULL && u16_cmp (result, expected, SIZEOF (expected)) == 0);
+         ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 10; i++)
@@ -174,15 +171,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint16_t *result = NULL;
-         size_t length = 0;
-         int retval = u16_conv_from_encoding ("autodetect_jp", handler,
-                                              input, strlen (input),
-                                              offsets,
-                                              &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler,
+                                                    input, strlen (input),
+                                                    offsets,
+                                                    NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == SIZEOF (expected));
-         ASSERT (result != NULL && u16_cmp (result, expected, SIZEOF (expected)) == 0);
+         ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 10; i++)
@@ -204,15 +200,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint16_t *result = NULL;
-         size_t length = 0;
-         int retval = u16_conv_from_encoding ("autodetect_jp", handler,
-                                              input, strlen (input),
-                                              offsets,
-                                              &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler,
+                                                    input, strlen (input),
+                                                    offsets,
+                                                    NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == SIZEOF (expected));
-         ASSERT (result != NULL && u16_cmp (result, expected, SIZEOF (expected)) == 0);
+         ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 16; i++)
index b6534f8..8f709f1 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of conversion to UTF-32 from legacy encodings.
-   Copyright (C) 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2007-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -77,15 +77,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint32_t *result = NULL;
-         size_t length = 0;
-         int retval = u32_conv_from_encoding ("ISO-8859-1", handler,
-                                              input, strlen (input),
-                                              offsets,
-                                              &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint32_t *result = u32_conv_from_encoding ("ISO-8859-1", handler,
+                                                    input, strlen (input),
+                                                    offsets,
+                                                    NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == SIZEOF (expected));
-         ASSERT (result != NULL && u32_cmp (result, expected, SIZEOF (expected)) == 0);
+         ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 37; i++)
@@ -110,15 +109,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint32_t *result = NULL;
-         size_t length = 0;
-         int retval = u32_conv_from_encoding ("ISO-8859-2", handler,
-                                              input, strlen (input),
-                                              offsets,
-                                              &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint32_t *result = u32_conv_from_encoding ("ISO-8859-2", handler,
+                                                    input, strlen (input),
+                                                    offsets,
+                                                    NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == SIZEOF (expected));
-         ASSERT (result != NULL && u32_cmp (result, expected, SIZEOF (expected)) == 0);
+         ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 16; i++)
@@ -144,15 +142,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint32_t *result = NULL;
-         size_t length = 0;
-         int retval = u32_conv_from_encoding ("autodetect_jp", handler,
-                                              input, strlen (input),
-                                              offsets,
-                                              &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler,
+                                                    input, strlen (input),
+                                                    offsets,
+                                                    NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == SIZEOF (expected));
-         ASSERT (result != NULL && u32_cmp (result, expected, SIZEOF (expected)) == 0);
+         ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 10; i++)
@@ -174,15 +171,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint32_t *result = NULL;
-         size_t length = 0;
-         int retval = u32_conv_from_encoding ("autodetect_jp", handler,
-                                              input, strlen (input),
-                                              offsets,
-                                              &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler,
+                                                    input, strlen (input),
+                                                    offsets,
+                                                    NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == SIZEOF (expected));
-         ASSERT (result != NULL && u32_cmp (result, expected, SIZEOF (expected)) == 0);
+         ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 10; i++)
@@ -204,15 +200,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint32_t *result = NULL;
-         size_t length = 0;
-         int retval = u32_conv_from_encoding ("autodetect_jp", handler,
-                                              input, strlen (input),
-                                              offsets,
-                                              &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler,
+                                                    input, strlen (input),
+                                                    offsets,
+                                                    NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == SIZEOF (expected));
-         ASSERT (result != NULL && u32_cmp (result, expected, SIZEOF (expected)) == 0);
+         ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 16; i++)
index fb0327c..0768be6 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of conversion to UTF-8 from legacy encodings.
-   Copyright (C) 2007-2008 Free Software Foundation, Inc.
+   Copyright (C) 2007-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -72,15 +72,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint8_t *result = NULL;
-         size_t length = 0;
-         int retval = u8_conv_from_encoding ("ISO-8859-1", handler,
-                                             input, strlen (input),
-                                             offsets,
-                                             &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint8_t *result = u8_conv_from_encoding ("ISO-8859-1", handler,
+                                                  input, strlen (input),
+                                                  offsets,
+                                                  NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == u8_strlen (expected));
-         ASSERT (result != NULL && u8_cmp (result, expected, u8_strlen (expected)) == 0);
+         ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 37; i++)
@@ -104,15 +103,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint8_t *result = NULL;
-         size_t length = 0;
-         int retval = u8_conv_from_encoding ("ISO-8859-2", handler,
-                                             input, strlen (input),
-                                             offsets,
-                                             &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint8_t *result = u8_conv_from_encoding ("ISO-8859-2", handler,
+                                                  input, strlen (input),
+                                                  offsets,
+                                                  NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == u8_strlen (expected));
-         ASSERT (result != NULL && u8_cmp (result, expected, u8_strlen (expected)) == 0);
+         ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 16; i++)
@@ -136,15 +134,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint8_t *result = NULL;
-         size_t length = 0;
-         int retval = u8_conv_from_encoding ("autodetect_jp", handler,
-                                             input, strlen (input),
-                                             offsets,
-                                             &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler,
+                                                  input, strlen (input),
+                                                  offsets,
+                                                  NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == u8_strlen (expected));
-         ASSERT (result != NULL && u8_cmp (result, expected, u8_strlen (expected)) == 0);
+         ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 10; i++)
@@ -163,15 +160,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint8_t *result = NULL;
-         size_t length = 0;
-         int retval = u8_conv_from_encoding ("autodetect_jp", handler,
-                                             input, strlen (input),
-                                             offsets,
-                                             &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler,
+                                                  input, strlen (input),
+                                                  offsets,
+                                                  NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == u8_strlen (expected));
-         ASSERT (result != NULL && u8_cmp (result, expected, u8_strlen (expected)) == 0);
+         ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 10; i++)
@@ -190,15 +186,14 @@ main ()
       for (o = 0; o < 2; o++)
        {
          size_t *offsets = (o ? new_offsets (strlen (input)) : NULL);
-         uint8_t *result = NULL;
-         size_t length = 0;
-         int retval = u8_conv_from_encoding ("autodetect_jp", handler,
-                                             input, strlen (input),
-                                             offsets,
-                                             &result, &length);
-         ASSERT (retval == 0);
+         size_t length;
+         uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler,
+                                                  input, strlen (input),
+                                                  offsets,
+                                                  NULL, &length);
+         ASSERT (result != NULL);
          ASSERT (length == u8_strlen (expected));
-         ASSERT (result != NULL && u8_cmp (result, expected, u8_strlen (expected)) == 0);
+         ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0);
          if (o)
            {
              for (i = 0; i < 16; i++)