From 2f9f31a6feb731f07aecebbb31c592f7eb7e35f5 Mon Sep 17 00:00:00 2001 From: ivmai Date: Sun, 3 Apr 2011 19:29:08 +0000 Subject: [PATCH] 2011-04-03 Ivan Maidanski * misc.c (GC_stdout, GC_stderr): Move the definition to the place where GC_log is defined (Unix only). * misc.c (GC_init): Recognize "GC_ONLY_LOG_TO_FILE" environment variable and the similar macro; redirect GC_stdout and GC_stderr to GC_log if "GC_LOG_FILE" environment variable is set unless prohibited by GC_ONLY_LOG_TO_FILE (Unix only). * doc/README.environment (GC_ONLY_LOG_TO_FILE): Document. * doc/README.macros (GC_ONLY_LOG_TO_FILE): Ditto. --- ChangeLog | 11 +++++++++++ doc/README.environment | 4 ++++ doc/README.macros | 4 ++++ misc.c | 23 +++++++++++++++++++---- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 642646b..c349fc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-04-03 Ivan Maidanski + * misc.c (GC_stdout, GC_stderr): Move the definition to the place + where GC_log is defined (Unix only). + * misc.c (GC_init): Recognize "GC_ONLY_LOG_TO_FILE" environment + variable and the similar macro; redirect GC_stdout and GC_stderr + to GC_log if "GC_LOG_FILE" environment variable is set unless + prohibited by GC_ONLY_LOG_TO_FILE (Unix only). + * doc/README.environment (GC_ONLY_LOG_TO_FILE): Document. + * doc/README.macros (GC_ONLY_LOG_TO_FILE): Ditto. + +2011-04-03 Ivan Maidanski + * misc.c (GC_stdout, GC_write): Rename GC_stdout to GC_log (Win32 only). * misc.c (GC_write): Add for MacOS (and OS/2); change WRITE() diff --git a/doc/README.environment b/doc/README.environment index 07a4ebf..ef7c7cb 100644 --- a/doc/README.environment +++ b/doc/README.environment @@ -20,6 +20,10 @@ GC_PRINT_STATS - Turn on GC logging. Not functional with SMALL_CONFIG. GC_LOG_FILE - The name of the log file. Stderr by default. Not functional with SMALL_CONFIG. +GC_ONLY_LOG_TO_FILE - Turns off redirection of GC stdout and stderr to the log + file specified by GC_LOG_FILE. Has no effect unless + GC_LOG_FILE is set. Not functional with SMALL_CONFIG. + GC_PRINT_VERBOSE_STATS - Turn on even more logging. Not functional with SMALL_CONFIG. diff --git a/doc/README.macros b/doc/README.macros index ac78897..50eab28 100644 --- a/doc/README.macros +++ b/doc/README.macros @@ -502,6 +502,10 @@ GC_IGNORE_GCJ_INFO Disable GCJ-style type information (useful for GC_PRINT_VERBOSE_STATS Permanently turn on verbose logging (useful for debugging and profiling on WinCE). +GC_ONLY_LOG_TO_FILE Don't redirect GC stdout and stderr to the log file + specified by GC_LOG_FILE environment variable. Has effect only when the + variable is set (to anything other than "0"). + GC_DONT_EXPAND Don't expand the heap unless explicitly requested or forced to. GC_USE_ENTIRE_HEAP Causes the non-incremental collector to use the diff --git a/misc.c b/misc.c index 22f2ba0..a27d9aa 100644 --- a/misc.c +++ b/misc.c @@ -627,7 +627,9 @@ STATIC void GC_exit_check(void) #endif #if !defined(OS2) && !defined(MACOS) && !defined(MSWIN32) && !defined(MSWINCE) - STATIC int GC_log = 2; + STATIC int GC_stdout = 1; + STATIC int GC_stderr = 2; + STATIC int GC_log = 2; /* stderr */ #endif GC_INNER void GC_initialize_offsets(void); /* defined in obj_map.c */ @@ -713,7 +715,23 @@ GC_API void GC_CALL GC_init(void) if (log_d < 0) { GC_err_printf("Failed to open %s as log file\n", file_name); } else { + char *str; GC_log = log_d; + str = GETENV("GC_ONLY_LOG_TO_FILE"); +# ifdef GC_ONLY_LOG_TO_FILE + /* The similar environment variable set to "0" */ + /* overrides the effect of the macro defined. */ + if (str != NULL && *str == '0' && *(str + 1) == '\0') +# else + /* Otherwise setting the environment variable */ + /* to anything other than "0" will prevent from */ + /* redirecting stdout/err to the log file. */ + if (str == NULL || (*str == '0' && *(str + 1) == '\0')) +# endif + { + GC_stdout = log_d; + GC_stderr = log_d; + } } } } @@ -1192,9 +1210,6 @@ GC_API void GC_CALL GC_enable_incremental(void) # define WRITE(f, buf, len) (GC_set_files(), GC_write(f, buf, len)) #else - STATIC int GC_stdout = 1; - STATIC int GC_stderr = 2; - /* GC_log is defined above. */ # if !defined(AMIGA) # include # endif -- 2.7.4