diff options
Diffstat (limited to 'ace/Log_Msg.cpp')
-rw-r--r-- | ace/Log_Msg.cpp | 167 |
1 files changed, 63 insertions, 104 deletions
diff --git a/ace/Log_Msg.cpp b/ace/Log_Msg.cpp index 771f6ab9fd2..cbb5c22b008 100644 --- a/ace/Log_Msg.cpp +++ b/ace/Log_Msg.cpp @@ -43,8 +43,6 @@ ACE_RCSID(ace, Log_Msg, "$Id$") -ACE_BEGIN_VERSIONED_NAMESPACE_DECL - ACE_ALLOC_HOOK_DEFINE(ACE_Log_Msg) // only used here... dhinton @@ -60,11 +58,11 @@ ACE_ALLOC_HOOK_DEFINE(ACE_Log_Msg) # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \ defined (ACE_HAS_TSS_EMULATION) -static ACE_thread_key_t the_log_msg_tss_key = 0; - ACE_thread_key_t *log_msg_tss_key (void) { - return &the_log_msg_tss_key; + static ACE_thread_key_t key = 0; + + return &key; } # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */ @@ -242,7 +240,7 @@ ACE_Log_Msg_Manager::close (void) # endif /* ACE_HAS_THR_C_DEST */ LOCAL_EXTERN_PREFIX void -ACE_TSS_CLEANUP_NAME (void *ptr) +ACE_TSS_cleanup (void *ptr) { #if !defined(ACE_USE_ONE_SHOT_AT_THREAD_EXIT) // Delegate to thr_desc if this not has terminated @@ -309,7 +307,7 @@ ACE_Log_Msg::instance (void) { ACE_NO_HEAP_CHECK; if (ACE_Thread::keycreate (log_msg_tss_key (), - &ACE_TSS_CLEANUP_NAME) != 0) + &ACE_TSS_cleanup) != 0) { if (1 == ACE_OS_Object_Manager::starting_up()) //This function is called before ACE_OS_Object_Manager is @@ -493,32 +491,6 @@ ACE_Log_Msg::close (void) // already deleted by ACE_TSS_Cleanup::exit (), so we // don't want to access it again. key_created_ = 0; -#ifdef ACE_HAS_BROKEN_THREAD_KEYFREE - // for some systems, e.g. LynxOS, we need to ensure that - // any registered thread destructor action for this thread - // is disabled. Otherwise in the event of a dynamic library - // unload of libACE, by a program not linked with libACE, - // ACE_TSS_cleanup will be invoked after libACE has been unloaded. - - ACE_Log_Msg *tss_log_msg = 0; - - // Get the tss_log_msg from thread-specific storage. - if ( ACE_Thread::getspecific (*(log_msg_tss_key ()), - ACE_reinterpret_cast (void **, &tss_log_msg)) != -1 - && tss_log_msg) - { - // we haven't been cleaned up - ACE_TSS_cleanup(tss_log_msg); - - if ( ACE_Thread::setspecific( (*log_msg_tss_key()), - (void *)NULL ) != 0 ) - { - ACE_DEBUG ((LM_DEBUG, - ACE_LIB_TEXT ("(%P|%t) ACE_Log_Msg::close failed to ACE_Thread::setspecific to NULL\n"))); - } - - } -#endif /* ACE_HAS_BROKEN_THREAD_KEYFREE */ } ACE_OS::thread_mutex_unlock (lock); @@ -655,7 +627,6 @@ ACE_Log_Msg::ACE_Log_Msg (void) : status_ (0), errnum_ (0), linenum_ (0), - msg_ (0), restart_ (1), // Restart by default... ostream_ (0), msg_callback_ (0), @@ -695,8 +666,6 @@ ACE_Log_Msg::ACE_Log_Msg (void) this->timestamp_ = 2; } } - - ACE_NEW_NORETURN (this->msg_, ACE_TCHAR[ACE_MAXLOGMSGLEN+1]); } ACE_Log_Msg::~ACE_Log_Msg (void) @@ -765,8 +734,6 @@ ACE_Log_Msg::~ACE_Log_Msg (void) ostream_ = 0; } #endif - - delete[] this->msg_; } // Open the sender-side of the message queue. @@ -929,8 +896,8 @@ ACE_Log_Msg::open (const ACE_TCHAR *prog_name, * 'X': print as a hex number * 'w': print a wide character * 'W': print out a wide character string. - * 'z': print an ACE_OS::WChar character - * 'Z': print an ACE_OS::WChar character string + * 'z': print an wchar_t character + * 'Z': print an wchar_t character string * '%': format a single percent sign, '%' */ ssize_t @@ -952,7 +919,6 @@ ACE_Log_Msg::log (ACE_Log_Priority log_priority, return result; } -#if defined (ACE_HAS_WCHAR) /** * Since this is the ANTI_TCHAR version, we need to convert * the format string over. @@ -968,14 +934,13 @@ ACE_Log_Msg::log (ACE_Log_Priority log_priority, va_start (argp, format_str); - ssize_t result = this->log (ACE_TEXT_ANTI_TO_TCHAR (format_str), + ssize_t result = this->log (ACE_TEXT_TO_TCHAR_IN (format_str), log_priority, argp); va_end (argp); return result; } -#endif /* ACE_HAS_WCHAR */ ssize_t ACE_Log_Msg::log (const ACE_TCHAR *format_str, @@ -1210,12 +1175,12 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, if (can_check) this_len = ACE_OS::snprintf (bp, bspace, format, this->file () ? - ACE_TEXT_CHAR_TO_TCHAR (this->file ()) + ACE_TEXT_TO_TCHAR_IN (this->file ()) : ACE_LIB_TEXT ("<unknown file>")); else this_len = ACE_OS::sprintf (bp, format, this->file () ? - ACE_TEXT_CHAR_TO_TCHAR (this->file ()) + ACE_TEXT_TO_TCHAR_IN (this->file ()) : ACE_LIB_TEXT ("<unknown file>")); ACE_UPDATE_COUNT (bspace, this_len); break; @@ -1271,11 +1236,11 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, if (can_check) this_len = ACE_OS::snprintf (bp, bspace, format, va_arg (argp, ACE_TCHAR *), - ACE_TEXT_CHAR_TO_TCHAR (msg)); + ACE_TEXT_TO_TCHAR_IN (msg)); else this_len = ACE_OS::sprintf (bp, format, va_arg (argp, ACE_TCHAR *), - ACE_TEXT_CHAR_TO_TCHAR (msg)); + ACE_TEXT_TO_TCHAR_IN (msg)); #if defined (ACE_WIN32) } else @@ -1379,10 +1344,10 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, #endif if (can_check) this_len = ACE_OS::snprintf - (bp, bspace, format, ACE_TEXT_CHAR_TO_TCHAR (msg)); + (bp, bspace, format, ACE_TEXT_TO_TCHAR_IN (msg)); else this_len = ACE_OS::sprintf - (bp, format, ACE_TEXT_CHAR_TO_TCHAR (msg)); + (bp, format, ACE_TEXT_TO_TCHAR_IN (msg)); #if defined (ACE_WIN32) } else @@ -1685,69 +1650,68 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) wchar_t *str = va_arg (argp, wchar_t *); ACE_OS::strcpy (fp, ACE_LIB_TEXT ("ls")); + if (can_check) + this_len = ACE_OS::snprintf + (bp, bspace, format, str ? str : ACE_LIB_TEXT ("(null)")); + else + this_len = ACE_OS::sprintf + (bp, format, str ? str : ACE_LIB_TEXT ("(null)")); #else /* ACE_WIN32 && ACE_USES_WCHAR */ ACE_TCHAR *str = va_arg (argp, ACE_TCHAR *); ACE_OS::strcpy (fp, ACE_LIB_TEXT ("s")); -#endif /* ACE_WIN32 && ACE_USES_WCHAR */ if (can_check) this_len = ACE_OS::snprintf (bp, bspace, format, str ? str : ACE_LIB_TEXT ("(null)")); else this_len = ACE_OS::sprintf (bp, format, str ? str : ACE_LIB_TEXT ("(null)")); +#endif /* ACE_WIN32 && ACE_USES_WCHAR */ ACE_UPDATE_COUNT (bspace, this_len); } break; case 'C': // Char string, Unicode for Win32/WCHAR - { - ACE_TCHAR *cstr = va_arg (argp, ACE_TCHAR *); #if defined (ACE_WIN32) && defined (ACE_USES_WCHAR) - ACE_OS::strcpy (fp, ACE_LIB_TEXT ("S")); + ACE_OS::strcpy (fp, ACE_LIB_TEXT ("S")); #else /* ACE_WIN32 && ACE_USES_WCHAR */ - ACE_OS::strcpy (fp, ACE_LIB_TEXT ("s")); + ACE_OS::strcpy (fp, ACE_LIB_TEXT ("s")); #endif /* ACE_WIN32 && ACE_USES_WCHAR */ - if (can_check) - this_len = ACE_OS::snprintf - (bp, bspace, format, cstr ? cstr : ACE_LIB_TEXT ("(null)")); - else - this_len = ACE_OS::sprintf - (bp, format, cstr ? cstr : ACE_LIB_TEXT ("(null)")); - ACE_UPDATE_COUNT (bspace, this_len); - } + if (can_check) + this_len = ACE_OS::snprintf + (bp, bspace, format, va_arg (argp, ACE_TCHAR *)); + else + this_len = ACE_OS::sprintf + (bp, format, va_arg (argp, ACE_TCHAR *)); + ACE_UPDATE_COUNT (bspace, this_len); break; case 'W': - { #if defined (ACE_WIN32) - ACE_TCHAR *wstr = va_arg (argp, ACE_TCHAR *); # if defined (ACE_USES_WCHAR) - ACE_OS::strcpy (fp, ACE_LIB_TEXT ("s")); + ACE_OS::strcpy (fp, ACE_LIB_TEXT ("s")); # else /* ACE_USES_WCHAR */ - ACE_OS::strcpy (fp, ACE_LIB_TEXT ("S")); + ACE_OS::strcpy (fp, ACE_LIB_TEXT ("S")); # endif /* ACE_USES_WCHAR */ - if (can_check) - this_len = ACE_OS::snprintf - (bp, bspace, format, wstr ? wstr : ACE_LIB_TEXT ("(null)")); - else - this_len = ACE_OS::sprintf - (bp, format, wstr ? wstr : ACE_LIB_TEXT ("(null)")); -#elif defined (ACE_HAS_WCHAR) - wchar_t *wchar_str = va_arg (argp, wchar_t *); + if (can_check) + this_len = ACE_OS::snprintf + (bp, bspace, format, va_arg (argp, ACE_TCHAR *)); + else + this_len = ACE_OS::sprintf + (bp, format, va_arg (argp, ACE_TCHAR *)); +#else # if defined (HPUX) - ACE_OS::strcpy (fp, ACE_LIB_TEXT ("S")); + ACE_OS::strcpy (fp, ACE_LIB_TEXT ("S")); # else - ACE_OS::strcpy (fp, ACE_LIB_TEXT ("ls")); + ACE_OS::strcpy (fp, ACE_LIB_TEXT ("ls")); # endif /* HPUX */ - if (can_check) - this_len = ACE_OS::snprintf - (bp, bspace, format, wchar_str); - else - this_len = ACE_OS::sprintf - (bp, format, wchar_str); -#endif /* ACE_WIN32 / ACE_HAS_WCHAR */ - ACE_UPDATE_COUNT (bspace, this_len); - } + if (can_check) + this_len = ACE_OS::snprintf + (bp, bspace, format, va_arg (argp, wchar_t *)); + else + this_len = ACE_OS::sprintf + (bp, format, va_arg (argp, wchar_t *)); +#endif /* ACE_WIN32 */ + ACE_UPDATE_COUNT (bspace, this_len); break; case 'w': // Wide character @@ -1787,7 +1751,7 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, ACE_UPDATE_COUNT (bspace, this_len); break; - case 'z': // ACE_OS::WChar character + case 'z': // wchar_t character { // On some platforms sizeof (wchar_t) can be 2 // on the others 4 ... @@ -1816,14 +1780,14 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, break; } - case 'Z': // ACE_OS::WChar character string + case 'Z': // wchar_t character string { - ACE_OS::WChar *wchar_str = va_arg (argp, ACE_OS::WChar*); + wchar_t *wchar_str = va_arg (argp, wchar_t*); if (wchar_str == 0) break; wchar_t *wchar_t_str = 0; - if (sizeof (ACE_OS::WChar) != sizeof (wchar_t)) + if (sizeof (wchar_t) != sizeof (wchar_t)) { size_t len = ACE_OS::wslen (wchar_str) + 1; ACE_NEW_NORETURN(wchar_t_str, wchar_t[len]); @@ -1846,19 +1810,19 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, # else /* ACE_USES_WCHAR */ ACE_OS::strcpy (fp, ACE_LIB_TEXT ("S")); # endif /* ACE_USES_WCHAR */ -#elif defined (ACE_HAS_WCHAR) +#else # if defined (HPUX) ACE_OS::strcpy (fp, ACE_LIB_TEXT ("S")); # else ACE_OS::strcpy (fp, ACE_LIB_TEXT ("ls")); # endif /* HPUX */ -#endif /* ACE_WIN32 / ACE_HAS_WCHAR */ +#endif /* ACE_WIN32 */ if (can_check) this_len = ACE_OS::snprintf (bp, bspace, format, wchar_t_str); else this_len = ACE_OS::sprintf (bp, format, wchar_t_str); - if(sizeof(ACE_OS::WChar) != sizeof(wchar_t)) + if(sizeof(wchar_t) != sizeof(wchar_t)) { delete wchar_t_str; } @@ -2004,7 +1968,7 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str, // Check that memory was not corrupted, if it corrupted we can't log anything // anymore because all our members could be corrupted. - if (bp >= (this->msg_ + ACE_MAXLOGMSGLEN+1)) + if (bp >= this->msg_ + sizeof this->msg_) { abort_prog = 1; ACE_OS::fprintf (stderr, @@ -2190,12 +2154,11 @@ ACE_Log_Msg::log_hexdump (ACE_Log_Priority log_priority, if (this->log_priority_enabled (log_priority) == 0) return 0; - ACE_TCHAR* buf = 0; - const size_t buf_sz = - ACE_Log_Record::MAXLOGMSGLEN - ACE_Log_Record::VERBOSE_LEN - 58; - ACE_NEW_RETURN (buf, ACE_TCHAR[buf_sz], -1); + ACE_TCHAR buf[ACE_Log_Record::MAXLOGMSGLEN - + ACE_Log_Record::VERBOSE_LEN - 58]; + // 58 for the HEXDUMP header; - ACE_TCHAR *msg_buf = 0; + ACE_TCHAR *msg_buf; const size_t text_sz = text ? ACE_OS::strlen(text) : 0; ACE_NEW_RETURN (msg_buf, ACE_TCHAR[text_sz + 58], @@ -2204,7 +2167,7 @@ ACE_Log_Msg::log_hexdump (ACE_Log_Priority log_priority, buf[0] = 0; // in case size = 0 const size_t len = ACE::format_hexdump - (buffer, size, buf, buf_sz / sizeof (ACE_TCHAR) - text_sz); + (buffer, size, buf, sizeof (buf) / sizeof (ACE_TCHAR) - text_sz); int sz = 0; @@ -2484,7 +2447,7 @@ void ACE_Log_Msg::msg (const ACE_TCHAR *m) { ACE_OS::strsncpy (this->msg_, m, - ((ACE_MAXLOGMSGLEN+1) / sizeof (ACE_TCHAR))); + (sizeof this->msg_ / sizeof (ACE_TCHAR))); } ACE_Log_Msg_Callback * @@ -2591,7 +2554,6 @@ ACE_Log_Msg::log_priority_enabled (ACE_Log_Priority log_priority, return this->log_priority_enabled (log_priority); } -#if defined (ACE_USES_WCHAR) int ACE_Log_Msg::log_priority_enabled (ACE_Log_Priority log_priority, const wchar_t *, @@ -2599,7 +2561,6 @@ ACE_Log_Msg::log_priority_enabled (ACE_Log_Priority log_priority, { return this->log_priority_enabled (log_priority); } -#endif /* ACE_USES_WCHAR */ // **************************************************************** @@ -2686,5 +2647,3 @@ ACE_Log_Msg::inherit_hook (ACE_OS_Thread_Descriptor *thr_desc, # endif /* ACE_PSOS */ #endif /* ! ACE_THREADS_DONT_INHERIT_LOG_MSG && ! ACE_HAS_MINIMAL_ACE_OS */ } - -ACE_END_VERSIONED_NAMESPACE_DECL |