[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 3/2] open_memstream: port to more systems
From: |
Bruno Haible |
Subject: |
Re: [PATCH 3/2] open_memstream: port to more systems |
Date: |
Sat, 1 May 2010 09:59:03 +0200 |
User-agent: |
KMail/1.9.9 |
Eric Blake wrote:
> --- a/lib/stdio.in.h
> +++ b/lib/stdio.in.h
> @@ -602,6 +602,11 @@ _GL_CXXALIASWARN (obstack_vprintf);
> the current stream size. After closing the stream, call
> free(*BUF). */
> # if address@hidden@
> +# if GNULIB_OPEN_MEMSTREAM_HOOK
> +/* Internal functions only used by gnulib. */
> +extern int gnulib_open_memstream_hook_flush (FILE *);
> +extern void gnulib_open_memstream_hook_close (FILE *);
> +# endif
> _GL_FUNCDECL_SYS (open_memstream, FILE *, (char **, size_t *));
> # endif
> _GL_CXXALIAS_SYS (open_memstream, FILE *, (char **, size_t *));
> diff --git a/lib/fflush.c b/lib/fflush.c
> index ead4875..c2e822b 100644
> --- a/lib/fflush.c
> +++ b/lib/fflush.c
> @@ -136,7 +136,19 @@ rpl_fflush (FILE *stream)
> what we need to know is whether the stream holds a "read buffer", and on
> mingw this is indicated by _IOREAD, regardless of _IOWRT. */
> if (stream == NULL || ! freading (stream))
> - return fflush (stream);
> + {
> + int result = fflush (stream);
> +#if GNULIB_OPEN_MEMSTREAM_HOOK
> + if (gnulib_open_memstream_hook_flush (stream))
> + result = EOF;
> +#endif
> + return result;
> + }
> +
> +#if GNULIB_OPEN_MEMSTREAM_HOOK
> + if (gnulib_open_memstream_hook_flush (stream))
> + return EOF;
> +#endif
>
> #if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS,
> Haiku, Linux libc5 */
This way of hooking into fflush will lead to link errors in some situations
supported by gnulib. Namely, if a user uses "gnulib-tool --import", and
has 'fflush' among the main modules (i.e. compiled in lib/) and 'open_memstream'
among the tests-related modules (i.e. compiled in tests/), then
- GNULIB_OPEN_MEMSTREAM_HOOK will be defined to 1 in config.h,
- lib/fflush.o will contain a call to gnulib_open_memstream_hook_flush,
- but lib/gnulib.a will not contain a definition of
gnulib_open_memstream_hook_flush, leading to a link error.
This situation already occurred in [1], and the fix was to make the connection
between the "extension point" and the "extension" (to use the terms of Eclipse)
at run-time, by introducing the 'close-hook' module.
So, you need to introduce a module 'fflush-hook', that will manage a list of
hooks to be called in the 'fflush' function. Both 'fflush' and 'open_memstream'
will depend on 'fflush-hook' - just the same way 'close-hook' is done.
For 'fclose', you don't need a special hook. Just register a 'close' hook.
Recall that the module 'fclose' depends on 'close', precisely so that it runs
the 'close' hooks.
Bruno
[1] http://lists.gnu.org/archive/html/bug-gnulib/2009-03/msg00192.html
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [PATCH 3/2] open_memstream: port to more systems,
Bruno Haible <=