Davlet Panech <dp1978x_lists <at> yahoo.ca> writes: > > Good day, > > I believe there's a problem with the use of static local variables > w/non-trivial constructors within log4cxx code > [...]
I have a patch (attached to JIRA bug LOGCXX-159, http://issues.apache.org/jira/browse/LOGCXX-159 ) that solves some of these problems: it calls most, but not all, functions w/static locals from a constructor of a static object ("helpers::StaticInitializer") that is forced into each (user) translation unit via #include <log4cxx/log4cxx.h>. This "initialization" is protected with a reference count and happens only on the first call. This solves my immediate problems, but some issues still remain: (1) Most classes implement reflection (??? I think), via #define IMPLEMENT_LOG4CXX_OBJECT, that macro contains function(s) with static locals. The patch I submitted doesn't do anything about those -- one would have to explicitely "initialize" each and every class. (2) There are still a few instances of global statics (Level:ALL() etc), that I think are prone to the order of initialization problem. (3) Each instance of a static local should really be isolated into a simple function that doesn't do much beyond returning a reference to that static. Otherwise initialization is unnecessarily expensieve since it has to execute unreleated code in order for control to pass through a static local declaration. (4) Perhaps a better solution would be to convert all statics to *global* (pointers to) variables, and allocate/deallocate them in the initialization/cleanup functions. Fixing these problems will require making lots of (mostly trivial) changes, I could do it, but I'd really appreciate some feedback (and commit access to SVN!) from full-time devs. Thank you, D.
