From 2f16ae7cb7ccebe631a7c51b563f6a5a377ea7da Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sun, 11 Jun 2017 13:38:57 -0400 Subject: [PATCH 1/3] Eliminate shared this from std/process.d --- posix.mak | 2 +- std/internal/processinit.d | 22 ---------------------- std/process.d | 22 ++++++++++++++-------- win32.mak | 1 - win64.mak | 1 - 5 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 std/internal/processinit.d diff --git a/posix.mak b/posix.mak index c0107ed2c0f..93398d77258 100644 --- a/posix.mak +++ b/posix.mak @@ -224,7 +224,7 @@ EXTRA_MODULES_INTERNAL := $(addprefix std/, \ cstring digest/sha_SSSE3 \ $(addprefix math/, biguintcore biguintnoasm biguintx86 \ errorfunction gammafunction ) \ - processinit scopebuffer test/dummyrange \ + scopebuffer test/dummyrange \ $(addprefix unicode_, comp decomp grapheme norm tables) \ ) \ ) 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 0569e9dca51..d431add4a49 100644 --- a/std/process.d +++ b/std/process.d @@ -99,7 +99,6 @@ version (Windows) } import std.internal.cstring; -import std.internal.processinit; import std.range.primitives; import std.stdio; @@ -133,20 +132,25 @@ version (Posix) { version (OSX) { - extern(C) char*** _NSGetEnviron() nothrow; - private __gshared const(char**)* environPtr; - extern(C) void std_process_shared_static_this() { environPtr = _NSGetEnviron(); } - const(char**) environ() @property @trusted nothrow { return *environPtr; } + private extern(C) char*** _NSGetEnviron() nothrow; + private const(char**) getEnvironPtr() @property @trusted + { + return *_NSGetEnviron; + } } else { // Made available by the C runtime: - extern(C) extern __gshared const char** environ; + private extern(C) extern __gshared const char** environ; + private const(char**) getEnvironPtr() @property @trusted + { + return environ; + } } @system unittest { - new Thread({assert(environ !is null);}).start(); + new Thread({assert(getEnvironPtr !is null);}).start(); } } @@ -703,6 +707,7 @@ private const(char*)* createEnv(const string[string] childEnv, { // Determine the number of strings in the parent's environment. int parentEnvLength = 0; + auto environ = getEnvironPtr; if (mergeWithParentEnv) { if (childEnv.length == 0) return environ; @@ -737,6 +742,7 @@ version (Posix) @system unittest auto e2 = createEnv(null, true); assert(e2 != null); int i = 0; + auto environ = getEnvironPtr; for (; environ[i] != null; ++i) { assert(e2[i] != null); @@ -3333,6 +3339,7 @@ static: string[string] aa; version (Posix) { + auto environ = getEnvironPtr; for (int i=0; environ[i] != null; ++i) { import std.string : indexOf; @@ -3902,4 +3909,3 @@ else version (Posix) } else static assert(0, "os not supported"); - diff --git a/win32.mak b/win32.mak index 854ed9a6a6d..db2108b3f3b 100644 --- a/win32.mak +++ b/win32.mak @@ -270,7 +270,6 @@ SRC_STD_C_FREEBSD= \ SRC_STD_INTERNAL= \ std\internal\cstring.d \ - std\internal\processinit.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 9e59883561d..dc5ec92a9c2 100644 --- a/win64.mak +++ b/win64.mak @@ -295,7 +295,6 @@ SRC_STD_C_FREEBSD= \ SRC_STD_INTERNAL= \ std\internal\cstring.d \ - std\internal\processinit.d \ std\internal\unicode_tables.d \ std\internal\unicode_comp.d \ std\internal\unicode_decomp.d \ From 442a94ab44c0588e94c46774bafc32937d155fd8 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sun, 11 Jun 2017 20:51:28 +0000 Subject: [PATCH 2/3] std.process: Correct indentation of private block --- std/process.d | 58 +++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/std/process.d b/std/process.d index d431add4a49..e280718f31f 100644 --- a/std/process.d +++ b/std/process.d @@ -112,47 +112,47 @@ version (Win32) version (CRuntime_DigitalMars) version = DMC_RUNTIME; private { -// Microsoft Visual C Runtime (MSVCRT) declarations. -version (Windows) -{ - version (DMC_RUNTIME) { } else + // Microsoft Visual C Runtime (MSVCRT) declarations. + version (Windows) { - import core.stdc.stdint; - enum + version (DMC_RUNTIME) { } else { - STDIN_FILENO = 0, - STDOUT_FILENO = 1, - STDERR_FILENO = 2, + import core.stdc.stdint; + enum + { + STDIN_FILENO = 0, + STDOUT_FILENO = 1, + STDERR_FILENO = 2, + } } } -} -// POSIX API declarations. -version (Posix) -{ - version (OSX) + // POSIX API declarations. + version (Posix) { - private extern(C) char*** _NSGetEnviron() nothrow; - private const(char**) getEnvironPtr() @property @trusted + version (OSX) { - return *_NSGetEnviron; + private extern(C) char*** _NSGetEnviron() nothrow; + private const(char**) getEnvironPtr() @property @trusted + { + return *_NSGetEnviron; + } } - } - else - { - // Made available by the C runtime: - private extern(C) extern __gshared const char** environ; - private const(char**) getEnvironPtr() @property @trusted + else { - return environ; + // Made available by the C runtime: + private extern(C) extern __gshared const char** environ; + private const(char**) getEnvironPtr() @property @trusted + { + return environ; + } } - } - @system unittest - { - new Thread({assert(getEnvironPtr !is null);}).start(); + @system unittest + { + new Thread({assert(getEnvironPtr !is null);}).start(); + } } -} } // private From 3b3cd774958c4e721cd1517274b94b4cb8b4a87a Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sun, 11 Jun 2017 13:52:39 -0400 Subject: [PATCH 3/3] Adjust private --- std/process.d | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/std/process.d b/std/process.d index e280718f31f..93627da1e13 100644 --- a/std/process.d +++ b/std/process.d @@ -111,7 +111,6 @@ version (Win32) version (CRuntime_DigitalMars) version = DMC_RUNTIME; // Some of the following should be moved to druntime. private { - // Microsoft Visual C Runtime (MSVCRT) declarations. version (Windows) { @@ -132,8 +131,8 @@ private { version (OSX) { - private extern(C) char*** _NSGetEnviron() nothrow; - private const(char**) getEnvironPtr() @property @trusted + extern(C) char*** _NSGetEnviron() nothrow; + const(char**) getEnvironPtr() @trusted { return *_NSGetEnviron; } @@ -141,8 +140,8 @@ private else { // Made available by the C runtime: - private extern(C) extern __gshared const char** environ; - private const(char**) getEnvironPtr() @property @trusted + extern(C) extern __gshared const char** environ; + const(char**) getEnvironPtr() @trusted { return environ; } @@ -153,8 +152,6 @@ private new Thread({assert(getEnvironPtr !is null);}).start(); } } - - } // private