From 767df6a1b5239f22c97e50608c6c8ba4a916826d Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Thu, 13 May 1999 13:31:53 +0000 Subject: [PATCH] Still fflushing strong. p4raw-id: //depot/cfgperl@3409 --- Configure | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- config_h.SH | 14 ++++++- embed.h | 2 + global.sym | 1 + objXSUB.h | 2 + perl.h | 6 ++- proto.h | 1 + util.c | 34 +++++++++++++++ 8 files changed, 181 insertions(+), 13 deletions(-) diff --git a/Configure b/Configure index e4f5cbb..4a9ea70 100755 --- a/Configure +++ b/Configure @@ -20,7 +20,7 @@ # $Id: Head.U,v 3.0.1.9 1997/02/28 15:02:09 ram Exp $ # -# Generated on Wed May 12 14:07:09 EET DST 1999 [metaconfig 3.0 PL70] +# Generated on Thu May 13 15:54:16 EET DST 1999 [metaconfig 3.0 PL70] # (with additional metaconfig patches by perlbug@perl.com) cat >/tmp/c1$$ <&4 <try.c < +int main() { + if (&STDIO_STREAM_ARRAY[fileno(stdin)] == stdin) + printf("yes\n"); +} +EOCP + for s in _iob __iob __sF + do + set try -DSTDIO_STREAM_ARRAY=$s + if eval $compile_ok; then + case "`./try$exe_ext`" in + yes) stdio_stream_array=$s; break ;; + esac + fi + done + $rm -f try.* try$exe_ext +esac +case "$stdio_stream_array" in +'') $cat >&4 <&4 <&4 <try.c <try.c < +#$i_unistd I_UNISTD +#ifdef I_UNISTD +#include +#endif +#$d_sysconf HAS_SYSCONF int main() { FILE* p = fopen("try.out", "w"); fputc('x', p); +#ifdef TRY_FFLUSH_NULL fflush(NULL); - _exit(0); +#endif +#ifdef TRY_FFLUSH_ALL + { + long open_max = -1; +# if defined(HAS_SYSCONF) && defined(_SC_OPEN_MAX) + open_max = sysconf(_SC_OPEN_MAX); +# else +# ifdef FOPEN_MAX +# open_max = FOPEN_MAX; +# else +# ifdef OPEN_MAX +# open_max = OPEN_MAX; +# else +# ifdef _NFILE +# open_max = _NFILE; +# endif +# endif +# endif +# endif + if (open_max > 0) { + long i; + for (i = 0; i < open_max; i++) + fflush(&$stdio_stream_array[i]); + } + } +#endif + _exit(42); } EOCP - set try +: check for fflush NULL behaviour +case "$fflushNULL" in +'') set try -DTRY_FFLUSH_NULL $rm -f try.out if eval $compile_ok; then ./try$exe_ext 2>/dev/null - $rm -f core try.core core.try.* - if $test -s try.out; then + if $test -s try.out -a "X$?" = X42; then fflushNULL="`$cat try.out`" fi + $rm -f core try.core core.try.* fi case "$fflushNULL" in x) cat >&4 </dev/null + if $test -s try.out -a "X$?" = X42; then + fflushall="`$cat try.out`" + fi + $rm -f core try.core core.try.* + fi + case "$fflushall" in + x) cat >&4 <&4 <&4 <config.h -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un- * This symbol, if defined, tells that fflush(NULL) does flush * all pending stdio output. */ -#$fflushNULL FFLUSH_NULL /**/ +/* FFLUSH_ALL: + * This symbol, if defined, tells that to flush + * all pending stdio output one must loop through all + * the stdio file handles and fflush them. + */ +#$fflushNULL FFLUSH_NULL /**/ +#$fflushall FFLUSH_ALL /**/ /* DB_Prefix_t: * This symbol contains the type of the prefix structure element @@ -2457,6 +2463,12 @@ sed <config.h -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un- #$d_ftello64 HAS_FTELLO64 /**/ #$d_tmpfile64 HAS_TMPFILE64 /**/ +/* STDIO_STREAM_ARRAY: + * This symbol tells the name of the array holding the stdio stream_array, + * if any. Usual values include _iob, __iob, and __sF. + */ +#define STDIO_STREAM_ARRAY $stdio_stream_array + /* USE_64_BITS: * This symbol, if defined, indicates that 64-bit interfaces should * be used when available. If not defined, the native default interfaces diff --git a/embed.h b/embed.h index aba2f59..8c2474a 100644 --- a/embed.h +++ b/embed.h @@ -320,6 +320,7 @@ #define my_chsize Perl_my_chsize #define my_exit Perl_my_exit #define my_failure_exit Perl_my_failure_exit +#define my_fflush_all Perl_my_fflush_all #define my_htonl Perl_my_htonl #define my_lstat Perl_my_lstat #define my_memcmp Perl_my_memcmp @@ -1378,6 +1379,7 @@ #define my_exit CPerlObj::Perl_my_exit #define my_exit_jump CPerlObj::Perl_my_exit_jump #define my_failure_exit CPerlObj::Perl_my_failure_exit +#define my_fflush_all CPerlObj::Perl_my_fflush_all #define my_htonl CPerlObj::Perl_my_htonl #define my_lstat CPerlObj::Perl_my_lstat #define my_memcmp CPerlObj::Perl_my_memcmp diff --git a/global.sym b/global.sym index 1e739bc..44417d9 100644 --- a/global.sym +++ b/global.sym @@ -311,6 +311,7 @@ my_bzero my_chsize my_exit my_failure_exit +my_fflush_all my_htonl my_lstat my_memcmp diff --git a/objXSUB.h b/objXSUB.h index 0305bf0..f037d3a 100644 --- a/objXSUB.h +++ b/objXSUB.h @@ -1619,6 +1619,8 @@ #define my_exit_jump pPerl->Perl_my_exit_jump #undef my_failure_exit #define my_failure_exit pPerl->Perl_my_failure_exit +#undef my_fflush_all +#define my_fflush_all pPerl->Perl_my_fflush_all #undef my_htonl #define my_htonl pPerl->Perl_my_htonl #undef my_lstat diff --git a/perl.h b/perl.h index 4d8b45c..b6fe805 100644 --- a/perl.h +++ b/perl.h @@ -1455,8 +1455,12 @@ typedef pthread_key_t perl_key; * XXX the default needs a Configure test, as it may not work everywhere. */ #ifndef PERL_FLUSHALL_FOR_CHILD -# if (defined(USE_STDIO) && defined(FFLUSH_NULL)) || defined(USE_SFIO) +# if defined(FFLUSH_NULL) || defined(USE_SFIO) # define PERL_FLUSHALL_FOR_CHILD PerlIO_flush((PerlIO*)NULL) +# else +# ifdef FFLUSH_ALL +# define PERL_FLUSHALL_FOR_CHILD my_fflush_all() +# endif # endif #endif diff --git a/proto.h b/proto.h index f2f45a7..ea364f1 100644 --- a/proto.h +++ b/proto.h @@ -329,6 +329,7 @@ char* my_bzero _((char* loc, I32 len)); #endif VIRTUAL void my_exit _((U32 status)) __attribute__((noreturn)); VIRTUAL void my_failure_exit _((void)) __attribute__((noreturn)); +VIRTUAL I32 my_fflush_all _((void)); VIRTUAL I32 my_lstat _((ARGSproto)); #if !defined(HAS_MEMCMP) || !defined(HAS_SANE_MEMCMP) VIRTUAL I32 my_memcmp _((const char* s1, const char* s2, I32 len)); diff --git a/util.c b/util.c index 9ea0851..79b9f49 100644 --- a/util.c +++ b/util.c @@ -3195,3 +3195,37 @@ get_vtbl(int vtbl_id) return result; } +I32 +my_fflush_all(void) +{ +#ifdef FFLUSH_NULL + return fflush(NULL); +#else + long open_max = -1; +# if defined(FFLUSH_ALL) && defined(STDIO_STREAM_ARRAY) +# if defined(HAS_SYSCONF) && defined(_SC_OPEN_MAX) + open_max = sysconf(_SC_OPEN_MAX); +# else +# ifdef FOPEN_MAX +# open_max = FOPEN_MAX; +# else +# ifdef OPEN_MAX +# open_max = OPEN_MAX; +# else +# ifdef _NFILE +# open_max = _NFILE; +# endif +# endif +# endif +# endif + if (open_max > 0) { + long i; + for (i = 0; i < open_max; i++) + fflush(&STDIO_STREAM_ARRAY[i]); + return 0; + } +# endif + SETERRNO(EBADF,RMS$_IFI); + return EOF; +#endif +} -- 2.7.4