libcpp/charset: close out shift states
Michael Meissner
michael.meissner@amd.com
Mon Dec 10 22:08:00 GMT 2007
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
More information about the Gcc-patches
mailing list