From df168487fc290dbe56119dceab6a2022a77fb52f Mon Sep 17 00:00:00 2001 From: Steven Schveighoffer Date: Tue, 28 Jun 2016 15:00:01 -0400 Subject: [PATCH] Fix cycles in Phobos --- posix.mak | 2 +- std/encoding.d | 24 ++++++++----- .../allocator/building_blocks/region.d | 15 -------- std/internal/phobosinit.d | 35 +++++++++++++++++++ std/internal/processinit.d | 22 ------------ std/process.d | 1 - win32.mak | 2 +- win64.mak | 2 +- 8 files changed, 54 insertions(+), 49 deletions(-) create mode 100644 std/internal/phobosinit.d delete mode 100644 std/internal/processinit.d diff --git a/posix.mak b/posix.mak index 4675b022986..034e4484592 100644 --- a/posix.mak +++ b/posix.mak @@ -212,7 +212,7 @@ EXTRA_MODULES_INTERNAL := $(addprefix \ std/internal/digest/, sha_SSSE3 ) $(addprefix \ std/internal/math/, biguintcore biguintnoasm biguintx86 \ gammafunction errorfunction) $(addprefix std/internal/, \ - cstring processinit unicode_tables scopebuffer\ + cstring phobosinit unicode_tables scopebuffer\ unicode_comp unicode_decomp unicode_grapheme unicode_norm) \ $(addprefix std/internal/test/, dummyrange) \ $(addprefix std/experimental/ndslice/, internal) \ diff --git a/std/encoding.d b/std/encoding.d index 9551451112a..be6cb918735 100644 --- a/std/encoding.d +++ b/std/encoding.d @@ -2635,10 +2635,11 @@ abstract class EncodingScheme */ class EncodingSchemeASCII : EncodingScheme { + /* // moved to std.internal.phobosinit shared static this() { EncodingScheme.register("std.encoding.EncodingSchemeASCII"); - } + }*/ const { @@ -2720,10 +2721,11 @@ class EncodingSchemeASCII : EncodingScheme */ class EncodingSchemeLatin1 : EncodingScheme { + /* // moved to std.internal.phobosinit shared static this() { EncodingScheme.register("std.encoding.EncodingSchemeLatin1"); - } + }*/ const { @@ -2799,10 +2801,11 @@ class EncodingSchemeLatin1 : EncodingScheme */ class EncodingSchemeLatin2 : EncodingScheme { + /* // moved to std.internal.phobosinit shared static this() { EncodingScheme.register("std.encoding.EncodingSchemeLatin2"); - } + }*/ const { @@ -2870,10 +2873,11 @@ class EncodingSchemeLatin2 : EncodingScheme */ class EncodingSchemeWindows1250 : EncodingScheme { + /* // moved to std.internal.phobosinit shared static this() { EncodingScheme.register("std.encoding.EncodingSchemeWindows1250"); - } + }*/ const { @@ -2937,10 +2941,11 @@ class EncodingSchemeWindows1250 : EncodingScheme */ class EncodingSchemeWindows1252 : EncodingScheme { + /* // moved to std.internal.phobosinit shared static this() { EncodingScheme.register("std.encoding.EncodingSchemeWindows1252"); - } + }*/ const { @@ -3004,10 +3009,11 @@ class EncodingSchemeWindows1252 : EncodingScheme */ class EncodingSchemeUtf8 : EncodingScheme { + /* // moved to std.internal.phobosinit shared static this() { EncodingScheme.register("std.encoding.EncodingSchemeUtf8"); - } + }*/ const { @@ -3072,10 +3078,11 @@ class EncodingSchemeUtf8 : EncodingScheme */ class EncodingSchemeUtf16Native : EncodingScheme { + /* // moved to std.internal.phobosinit shared static this() { EncodingScheme.register("std.encoding.EncodingSchemeUtf16Native"); - } + }*/ const { @@ -3167,10 +3174,11 @@ unittest */ class EncodingSchemeUtf32Native : EncodingScheme { + /* // moved to std.internal.phobosinit shared static this() { EncodingScheme.register("std.encoding.EncodingSchemeUtf32Native"); - } + }*/ const { diff --git a/std/experimental/allocator/building_blocks/region.d b/std/experimental/allocator/building_blocks/region.d index 67be71e79cb..be6a459dbff 100644 --- a/std/experimental/allocator/building_blocks/region.d +++ b/std/experimental/allocator/building_blocks/region.d @@ -596,21 +596,6 @@ version(Posix) struct SbrkRegion(uint minAlign = platformAlignment) private static shared pthread_mutex_t sbrkMutex = PTHREAD_MUTEX_INITIALIZER; import std.typecons : Ternary; - // workaround for https://issues.dlang.org/show_bug.cgi?id=14617 - version(OSX) - { - shared static this() - { - pthread_mutex_init(cast(pthread_mutex_t*) &sbrkMutex, null) == 0 - || assert(0); - } - shared static ~this() - { - pthread_mutex_destroy(cast(pthread_mutex_t*) &sbrkMutex) == 0 - || assert(0); - } - } - static assert(minAlign.isGoodStaticAlignment); static assert(size_t.sizeof == (void*).sizeof); private shared void* _brkInitial, _brkCurrent; diff --git a/std/internal/phobosinit.d b/std/internal/phobosinit.d new file mode 100644 index 00000000000..47cb0cd6b3c --- /dev/null +++ b/std/internal/phobosinit.d @@ -0,0 +1,35 @@ +// Written in the D programming language. + +/++ + The purpose of this module is to perform static construction away from the + normal modules to eliminate cyclic construction errors. + + Copyright: Copyright 2011 - 2016 + License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). + Authors: Jonathan M Davis, Kato Shoichi, Steven Schveighoffer + Source: $(PHOBOSSRC std/internal/_phobosinit.d) + +/ +module std.internal.phobosinit; + +version(OSX) +{ + extern(C) void std_process_shared_static_this(); + + shared static this() + { + std_process_shared_static_this(); + } +} + +shared static this() +{ + import std.encoding; + EncodingScheme.register("std.encoding.EncodingSchemeASCII"); + EncodingScheme.register("std.encoding.EncodingSchemeLatin1"); + EncodingScheme.register("std.encoding.EncodingSchemeLatin2"); + EncodingScheme.register("std.encoding.EncodingSchemeWindows1250"); + EncodingScheme.register("std.encoding.EncodingSchemeWindows1252"); + EncodingScheme.register("std.encoding.EncodingSchemeUtf8"); + EncodingScheme.register("std.encoding.EncodingSchemeUtf16Native"); + EncodingScheme.register("std.encoding.EncodingSchemeUtf32Native"); +} diff --git a/std/internal/processinit.d b/std/internal/processinit.d deleted file mode 100644 index df241089aa0..00000000000 --- a/std/internal/processinit.d +++ /dev/null @@ -1,22 +0,0 @@ -// Written in the D programming language. - -/++ - The only purpose of this module is to do the static construction for - std.process in order to eliminate cyclic construction errors. - - Copyright: Copyright 2011 - - License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - Authors: Jonathan M Davis and Kato Shoichi - Source: $(PHOBOSSRC std/internal/_processinit.d) - +/ -module std.internal.processinit; - -version(OSX) -{ - extern(C) void std_process_shared_static_this(); - - shared static this() - { - std_process_shared_static_this(); - } -} diff --git a/std/process.d b/std/process.d index 304f21694fc..1f38c48d84f 100644 --- a/std/process.d +++ b/std/process.d @@ -106,7 +106,6 @@ import std.conv; import std.exception; import std.path; import std.stdio; -import std.internal.processinit; import std.internal.cstring; diff --git a/win32.mak b/win32.mak index d17bf6fbc69..bc08d6d5202 100644 --- a/win32.mak +++ b/win32.mak @@ -270,7 +270,7 @@ SRC_STD_C_FREEBSD= \ SRC_STD_INTERNAL= \ std\internal\cstring.d \ - std\internal\processinit.d \ + std\internal\phobosinit.d \ std\internal\unicode_tables.d \ std\internal\unicode_comp.d \ std\internal\unicode_decomp.d \ diff --git a/win64.mak b/win64.mak index e76f3a98271..bff24428733 100644 --- a/win64.mak +++ b/win64.mak @@ -292,7 +292,7 @@ SRC_STD_C_FREEBSD= \ SRC_STD_INTERNAL= \ std\internal\cstring.d \ - std\internal\processinit.d \ + std\internal\phobosinit.d \ std\internal\unicode_tables.d \ std\internal\unicode_comp.d \ std\internal\unicode_decomp.d \