This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: libcpp/charset: close out shift states


On Mon, Dec 10, 2007 at 04:18:14PM -0500, DJ Delorie wrote:
> 
> How about this?  I pulled some common code out into a macro, because I
> didn't know how portable it would be to call iconv with inbytesleft==0
> 
> The other option is to put an "if (inbytesleft)" before the other call
> to iconv, so that we call one iconv or the other, but use the common
> loop/grow code.  I don't know if it's possible to loop infinitely on a
> close-shift call, either.
> 
> Index: charset.c
> ===================================================================
> --- charset.c	(revision 129957)
> +++ charset.c	(working copy)
> @@ -548,6 +548,13 @@
>  /* And this one uses the system iconv primitive.  It's a little
>     different, since iconv's interface is a little different.  */
>  #if HAVE_ICONV
> +
> +#define CONVERT_ICONV_GROW_BUFFER \
> +      outbytesleft += OUTBUF_BLOCK_SIZE; \
> +      to->asize += OUTBUF_BLOCK_SIZE; \
> +      to->text = XRESIZEVEC (uchar, to->text, to->asize); \
> +      outbuf = (char *)to->text + to->asize - outbytesleft;
> +

I would probably rewrite this to use a do { ... } while (0) construct in case
somebody reorganizes the code and puts CONVERT_ICONV_GROW_BUFFER in an if then
or else clause:

> +#define CONVERT_ICONV_GROW_BUFFER \
> +      do { \
> +        outbytesleft += OUTBUF_BLOCK_SIZE; \
> +        to->asize += OUTBUF_BLOCK_SIZE; \
> +        to->text = XRESIZEVEC (uchar, to->text, to->asize); \
> +        outbuf = (char *)to->text + to->asize - outbytesleft; \
> +      while (0)
> 

-- 
Michael Meissner, AMD
90 Central Street, MS 83-29, Boxborough, MA, 01719, USA
michael.meissner@amd.com



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