Bug 1652 - Storage of the log name in LogComponent
Storage of the log name in LogComponent
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: core
ns-3-dev
All All
: P5 normal
Assigned To: Mathieu Lacage
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-04-26 18:18 EDT by Alex Afanasyev
Modified: 2014-09-12 22:02 EDT (History)
2 users (show)

See Also:


Attachments
Patch (686 bytes, application/octet-stream)
2013-04-26 18:18 EDT, Alex Afanasyev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Afanasyev 2013-04-26 18:18:24 EDT
Created attachment 1573 [details]
Patch

LogComponent stores the log name as const char* pointer, which is perfectly fine in most of the cases, where LogComponent is statically initialized using macros.  In more complex scenarios (I have a template-based hierarchical log initialization procedure), this breaks miserably.

The attached patch simply changes storage to std::string, which solves all the problems.
Comment 1 Mathieu Lacage 2013-04-30 09:23:39 EDT
(In reply to comment #0)
> Created attachment 1573 [details]
> Patch
> 
> LogComponent stores the log name as const char* pointer, which is perfectly
> fine in most of the cases, where LogComponent is statically initialized using
> macros.  In more complex scenarios (I have a template-based hierarchical log
> initialization procedure), this breaks miserably.
> 
> The attached patch simply changes storage to std::string, which solves all the
> problems.

the patch looks ok, but, really, I am curious: how come changing the type of a _private_ member changes the outcome for you ?
Comment 2 Alex Afanasyev 2013-04-30 13:50:11 EDT
I have a non-static initialization of the logger, so when LogComponent internally stored only a const pointer, there were no guarantees that this pointer will be pointing to anything useful for such types of initialization.  With std::string, there is additional memory allocated, which is kind of "wasteful" with static initialization, but gives guarantee in a general case.
Comment 3 Tom Henderson 2014-09-12 22:01:23 EDT
This was already fixed in:

changeset:   10228:8244f0b3ff1b
user:        Peter D. Barnes, Jr. <barnes26@llnl.gov>
date:        Mon Oct 28 14:50:08 2013 -0700
summary:     [bug 1552] Storing log name inside LogComponent class (NS_LOG) as std::string

(wrong bug number in the commit string)
Comment 4 Tom Henderson 2014-09-12 22:02:20 EDT
actually, not a wrong bug number, it was a duplicate of 1552