std.log version 2

Jose Armando Garcia jsancio at gmail.com
Sun Jun 5 10:24:53 PDT 2011


The problem is that std.log is using the UTC() (indirectly) in shared
static this() for the module. At that point the static ctr for UTC
didn't get to execute. I first changed std.datetime to instantiate UTC
in a shared static ctr for UTC but that still didn't work (I assume
that is a bug in dmd). So I had to move the instantiation to a share
static ctr for the module.

In my branch the follow code doesn't assert. Note that I was selfish
and only fixed UTC but std.datetime has this problem in all the
singletons.

import std.datetime;

shared static this()
{
   assert(UTC() !is null); // this is with my fix.
   assert(LocalTime() is null); // I didn't fix LocalTime!
}

Having said that what is D's idiom/recommended way of constructing
singletons? Maybe phobos should create shared/global singleton with
the following idiom:

shared(T) singleton(T)() if(is(T == class))
{
   shared static T one;
   if(one is null) cas(&one, null, new shared(T));

   return one;
}

On Sun, Jun 5, 2011 at 2:50 AM, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> On 2011-06-04 10:04, Jose Armando Garcia wrote:
>> Note: I had to make changes to std.datetime (was getting a segfault;
>> changes are in my repo) and druntime (patch attached).
>
> Why were you getting a segfault? I don't see why your change would avoid a
> segfault.
>
> - Jonathan M Davis
>


More information about the Digitalmars-d mailing list