{
BOOL tmp;
DWORD written;
+# if (defined(THREADS) && defined(GC_ASSERTIONS)) \
+ || !defined(GC_PRINT_VERBOSE_STATS)
+ static GC_bool inside_write = FALSE;
+ /* to prevent infinite recursion at abort. */
+ if (inside_write)
+ return -1;
+# endif
+
if (len == 0)
return 0;
IF_NEED_TO_LOCK(EnterCriticalSection(&GC_write_cs));
-# ifdef THREADS
- GC_ASSERT(!GC_write_disabled);
+# if defined(THREADS) && defined(GC_ASSERTIONS)
+ if (GC_write_disabled) {
+ inside_write = TRUE;
+ ABORT("Assertion failure: GC_write called with write_disabled");
+ }
# endif
if (GC_log == INVALID_HANDLE_VALUE) {
IF_NEED_TO_LOCK(LeaveCriticalSection(&GC_write_cs));
/* Ignore open log failure if the collector is built with */
/* print_stats always set on. */
# ifndef GC_PRINT_VERBOSE_STATS
- if (GC_log == INVALID_HANDLE_VALUE)
+ if (GC_log == INVALID_HANDLE_VALUE) {
+ inside_write = TRUE;
ABORT("Open of log file failed");
+ }
# endif
}
tmp = WriteFile(GC_log, buf, (DWORD)len, &written, NULL);
/* Avoid calling GC_err_printf() here, as GC_on_abort() could be */
/* called from it. Note 1: this is not an atomic output. */
/* Note 2: possible write errors are ignored. */
- if (WRITE(GC_stderr, (void *)msg, strlen(msg)) >= 0)
- (void)WRITE(GC_stderr, (void *)("\n"), 1);
+
+# if defined(THREADS) && defined(GC_ASSERTIONS) \
+ && (defined(MSWIN32) || defined(MSWINCE))
+ if (!GC_write_disabled)
+# endif
+ {
+ if (WRITE(GC_stderr, (void *)msg, strlen(msg)) >= 0)
+ (void)WRITE(GC_stderr, (void *)("\n"), 1);
+ }
}
# ifndef NO_DEBUGGING