Skip to content

Commit

Permalink
libdeng2: Fixed LOG_AS_STRING
Browse files Browse the repository at this point in the history
The section name string pointer must exist for the entire scope
in question. Calling toAscii() returns a byte array that exists
only during the execution of the statement -- for the remainder
of the scope the pointer is invalid.
  • Loading branch information
skyjake committed Jul 24, 2012
1 parent d775172 commit c932145
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions doomsday/libdeng2/include/de/core/log.h
Expand Up @@ -36,12 +36,19 @@
/// a new log section.
#define LOG_AS(sectionName) \
de::Log::Section __logSection = de::Log::Section(sectionName);

/// Macro for accessing the local log of the current thread and entering
/// a new log section with a std::string variable based name.

/**
* Macro for accessing the local log of the current thread and entering
* a new log section with a std::string variable based name.
*
* @note Log::Section doesn't own the strings passed in; we have to
* ensure that the string exists in memory as long as the section (scope)
* is valid.
*/
#define LOG_AS_STRING(str) \
de::String __logSectionName = str; \
LOG_AS(__logSectionName.toAscii().constData());
de::Block __logSectionUtf8 = __logSectionName.toUtf8(); \
LOG_AS(__logSectionUtf8.constData());

#define LOG_TRACE(str) LOG().enter(de::Log::TRACE, str)
#define LOG_DEBUG(str) LOG().enter(de::Log::DEBUG, str)
Expand Down

0 comments on commit c932145

Please sign in to comment.