changeset 11511:d604b921ed8d

Simplify calling convention of u*_conv_from_encoding.
author Bruno Haible <bruno@clisp.org>
date Sun, 26 Apr 2009 16:43:25 +0200
parents 192bb1b6ecf2
children 447a9ef7674a
files 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
diffstat 15 files changed, 237 insertions(+), 204 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+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.
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,12 @@
 
 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
--- a/lib/unicase/ulc-casecmp.c
+++ b/lib/unicase/ulc-casecmp.c
@@ -39,10 +39,11 @@
   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;
 
--- a/lib/unicase/ulc-casexfrm.c
+++ b/lib/unicase/ulc-casexfrm.c
@@ -36,10 +36,11 @@
   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;
 
--- a/lib/uniconv.h
+++ b/lib/uniconv.h
@@ -51,28 +51,30 @@
    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.
--- a/lib/uniconv/u-conv-from-enc.h
+++ b/lib/uniconv/u-conv-from-enc.h
@@ -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
@@ -14,19 +14,20 @@
    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 @@
   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 @@
 	  }
     }
   free (utf8_string);
-  *resultp = result;
-  return 0;
+  return result;
 #endif
 }
--- a/lib/uniconv/u-strconv-from-enc.h
+++ b/lib/uniconv/u-strconv-from-enc.h
@@ -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 @@
       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
--- a/lib/uniconv/u8-conv-from-enc.c
+++ b/lib/uniconv/u8-conv-from-enc.c
@@ -29,12 +29,12 @@
 #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 @@
       if (u8_check ((const uint8_t *) src, srclen))
 	{
 	  errno = EILSEQ;
-	  return -1;
+	  return NULL;
 	}
 
       if (offsets != NULL)
@@ -65,24 +65,41 @@
 	}
 
       /* 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;
+    }
 }
--- a/lib/unilbrk/ulc-possible-linebreaks.c
+++ b/lib/unilbrk/ulc-possible-linebreaks.c
@@ -56,11 +56,12 @@
 
 	  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);
 
--- a/lib/unilbrk/ulc-width-linebreaks.c
+++ b/lib/unilbrk/ulc-width-linebreaks.c
@@ -58,11 +58,12 @@
 
 	  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);
--- a/lib/uniwbrk/ulc-wordbreaks.c
+++ b/lib/uniwbrk/ulc-wordbreaks.c
@@ -58,11 +58,12 @@
 
 	  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);
 
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -2493,14 +2493,13 @@
 		  }
 
 		  /* 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 @@
 # 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))
--- a/tests/uniconv/test-u16-conv-from-enc.c
+++ b/tests/uniconv/test-u16-conv-from-enc.c
@@ -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 @@
       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 @@
       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 @@
       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 @@
       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 @@
       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++)
--- a/tests/uniconv/test-u32-conv-from-enc.c
+++ b/tests/uniconv/test-u32-conv-from-enc.c
@@ -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 @@
       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 @@
       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 @@
       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 @@
       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 @@
       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++)
--- a/tests/uniconv/test-u8-conv-from-enc.c
+++ b/tests/uniconv/test-u8-conv-from-enc.c
@@ -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 @@
       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 @@
       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 @@
       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 @@
       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 @@
       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++)