Skip to content

Commit

Permalink
Merge pull request #4845 from MartinNowak/merge_stable
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'upstream/stable' into merge_stable
  • Loading branch information
MartinNowak committed Oct 9, 2016
2 parents 47adcab + 74486fe commit df34e42
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 554 deletions.
494 changes: 2 additions & 492 deletions changelog.dd

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion posix.mak
Expand Up @@ -216,7 +216,7 @@ EXTRA_MODULES_INTERNAL := $(addprefix \
std/internal/digest/, sha_SSSE3 ) $(addprefix \
std/internal/math/, biguintcore biguintnoasm biguintx86 \
gammafunction errorfunction) $(addprefix std/internal/, \
cstring phobosinit unicode_tables scopebuffer\
cstring encodinginit processinit unicode_tables scopebuffer\
unicode_comp unicode_decomp unicode_grapheme unicode_norm) \
$(addprefix std/internal/test/, dummyrange) \
$(addprefix std/experimental/ndslice/, internal) \
Expand Down
37 changes: 20 additions & 17 deletions std/algorithm/iteration.d
Expand Up @@ -3573,6 +3573,8 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)

_separatorLength = codeLength!(ElementEncodingType!Range)(separator);
}
if (_input.empty)
_frontLength = _atEnd;
}

static if (isInfinite!Range)
Expand Down Expand Up @@ -3704,7 +3706,6 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)

debug(std_algorithm) scope(success)
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
assert(equal(splitter("", ' '), [ "" ]));
assert(equal(splitter("hello world", ' '), [ "hello", "", "world" ]));
assert(equal(splitter("žlutoučkýřkůň", 'ř'), [ "žlutoučký", "kůň" ]));
int[] a = [ 1, 2, 0, 0, 3, 0, 4, 5, 0 ];
Expand All @@ -3717,7 +3718,7 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
// }
assert(equal(splitter(a, 0), w));
a = null;
assert(equal(splitter(a, 0), [ (int[]).init ][]));
assert(equal(splitter(a, 0), (int[][]).init));
a = [ 0 ];
assert(equal(splitter(a, 0), [ (int[]).init, (int[]).init ][]));
a = [ 0, 1 ];
Expand Down Expand Up @@ -3821,17 +3822,17 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
private:
Range _input;
Separator _separator;
enum size_t _unComputed = size_t.max - 1, _atEnd = size_t.max;
// _frontLength == _atEnd means empty
size_t _frontLength = _unComputed;
// _frontLength == size_t.max means empty
size_t _frontLength = size_t.max;
static if (isBidirectionalRange!Range)
size_t _backLength = _unComputed;
size_t _backLength = size_t.max;

@property auto separatorLength() { return _separator.length; }

void ensureFrontLength()
{
if (_frontLength != _unComputed) return;
if (_frontLength != _frontLength.max) return;
assert(!_input.empty);
// compute front length
_frontLength = (_separator.empty) ? 1 :
_input.length - find!pred(_input, _separator).length;
Expand All @@ -3842,7 +3843,8 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
void ensureBackLength()
{
static if (isBidirectionalRange!Range)
if (_backLength != _unComputed) return;
if (_backLength != _backLength.max) return;
assert(!_input.empty);
// compute back length
static if (isBidirectionalRange!Range && isBidirectionalRange!Separator)
{
Expand Down Expand Up @@ -3874,7 +3876,7 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
{
@property bool empty()
{
return _frontLength == _atEnd;
return _frontLength == size_t.max && _input.empty;
}
}

Expand All @@ -3886,9 +3888,9 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
{
// done, there's no separator in sight
_input = _input[_frontLength .. _frontLength];
_frontLength = _atEnd;
_frontLength = _frontLength.max;
static if (isBidirectionalRange!Range)
_backLength = _atEnd;
_backLength = _backLength.max;
return;
}
if (_frontLength + separatorLength == _input.length)
Expand All @@ -3905,7 +3907,7 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
// reading the next item
_input = _input[_frontLength + separatorLength .. _input.length];
// mark _frontLength as uninitialized
_frontLength = _unComputed;
_frontLength = _frontLength.max;
}

static if (isForwardRange!Range)
Expand Down Expand Up @@ -3955,8 +3957,6 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)

debug(std_algorithm) scope(success)
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
assert(equal(splitter("", " "), [ "" ]));

auto s = ",abc, de, fg,hi,";
auto sp0 = splitter(s, ',');
// //foreach (e; sp0) writeln("[", e, "]");
Expand Down Expand Up @@ -4131,7 +4131,10 @@ private struct SplitterResult(alias isTerminator, Range)
static if (!fullSlicing)
_next = _input.save;

findTerminator();
if (!_input.empty)
findTerminator();
else
_end = size_t.max;
}

static if (isInfinite!Range)
Expand Down Expand Up @@ -4240,7 +4243,7 @@ private struct SplitterResult(alias isTerminator, Range)
["Mary", "", "has", "a", "little", "lamb.", "", "", ""]);
compare("Mary has a little lamb.",
["Mary", "", "has", "a", "little", "lamb."]);
compare("", [""]);
compare("", (string[]).init);
compare(" ", ["", ""]);

static assert(isForwardRange!(typeof(splitter!"a == ' '"("ABC"))));
Expand Down Expand Up @@ -4270,7 +4273,7 @@ private struct SplitterResult(alias isTerminator, Range)
int[][] result;
}
Entry[] entries = [
Entry(0, 0, [[]]),
Entry(0, 0, []),
Entry(0, 1, [[0]]),
Entry(1, 2, [[], []]),
Entry(2, 7, [[2], [4], [6]]),
Expand Down
42 changes: 38 additions & 4 deletions std/encoding.d
Expand Up @@ -55,6 +55,7 @@ module std.encoding;
import std.traits;
import std.typecons;
import std.range.primitives;
import std.internal.encodinginit;

@system unittest
{
Expand Down Expand Up @@ -2360,25 +2361,38 @@ abstract class EncodingScheme
* This function allows user-defined subclasses of EncodingScheme to
* be declared in other modules.
*
* Params:
* Klass = The subclass of EncodingScheme to register.
*
* Example:
* ----------------------------------------------
* class Amiga1251 : EncodingScheme
* {
* shared static this()
* {
* EncodingScheme.register("path.to.Amiga1251");
* EncodingScheme.register!Amiga1251;
* }
* }
* ----------------------------------------------
*/
static void register(Klass:EncodingScheme)()
{
scope scheme = new Klass();
foreach (encodingName;scheme.names())
{
supported[toLower(encodingName)] = () => new Klass();
}
}

deprecated("Please pass the EncodingScheme subclass as template argument instead.")
static void register(string className)
{
auto scheme = cast(EncodingScheme)ClassInfo.find(className).create();
if (scheme is null)
throw new EncodingException("Unable to create class "~className);
foreach (encodingName;scheme.names())
{
supported[toLower(encodingName)] = className;
supportedFactories[toLower(encodingName)] = className;
}
}

Expand All @@ -2396,7 +2410,12 @@ abstract class EncodingScheme
*/
static EncodingScheme create(string encodingName)
{
auto p = toLower(encodingName) in supported;
encodingName = toLower(encodingName);

if (auto p = encodingName in supported)
return (*p)();

auto p = encodingName in supportedFactories;
if (p is null)
throw new EncodingException("Unrecognized Encoding: "~encodingName);
string className = *p;
Expand Down Expand Up @@ -2650,7 +2669,8 @@ abstract class EncodingScheme
return t.length - s.length;
}

__gshared string[string] supported;
__gshared EncodingScheme function()[string] supported;
__gshared string[string] supportedFactories;
}

/**
Expand Down Expand Up @@ -3297,6 +3317,20 @@ class EncodingSchemeUtf32Native : EncodingScheme
assert(ub.length == 8);
}


// shared static this() called from encodinginit to break ctor cycle
extern(C) void std_encoding_shared_static_this()
{
EncodingScheme.register!EncodingSchemeASCII;
EncodingScheme.register!EncodingSchemeLatin1;
EncodingScheme.register!EncodingSchemeLatin2;
EncodingScheme.register!EncodingSchemeWindows1250;
EncodingScheme.register!EncodingSchemeWindows1252;
EncodingScheme.register!EncodingSchemeUtf8;
EncodingScheme.register!EncodingSchemeUtf16Native;
EncodingScheme.register!EncodingSchemeUtf32Native;
}

//=============================================================================


Expand Down
19 changes: 19 additions & 0 deletions std/internal/encodinginit.d
@@ -0,0 +1,19 @@
// 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: Martin Nowak, Steven Schveighoffer
Source: $(PHOBOSSRC std/internal/_encodinginit.d)
+/
module std.internal.encodinginit;

extern(C) void std_encoding_shared_static_this();

shared static this()
{
std_encoding_shared_static_this();
}
35 changes: 0 additions & 35 deletions std/internal/phobosinit.d

This file was deleted.

22 changes: 22 additions & 0 deletions std/internal/processinit.d
@@ -0,0 +1,22 @@
// 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();
}
}
4 changes: 1 addition & 3 deletions std/parallelism.d
Expand Up @@ -976,9 +976,7 @@ private final class ParallelismThread : Thread
// Kill daemon threads.
shared static ~this()
{
auto allThreads = Thread.getAll();

foreach (thread; allThreads)
foreach (ref thread; Thread)
{
auto pthread = cast(ParallelismThread) thread;
if (pthread is null) continue;
Expand Down
1 change: 1 addition & 0 deletions std/process.d
Expand Up @@ -100,6 +100,7 @@ version (Windows)

import std.range.primitives;
import std.stdio;
import std.internal.processinit;
import std.internal.cstring;


Expand Down
3 changes: 2 additions & 1 deletion win32.mak
Expand Up @@ -274,7 +274,8 @@ SRC_STD_C_FREEBSD= \

SRC_STD_INTERNAL= \
std\internal\cstring.d \
std\internal\phobosinit.d \
std\internal\encodinginit.d \
std\internal\processinit.d \
std\internal\unicode_tables.d \
std\internal\unicode_comp.d \
std\internal\unicode_decomp.d \
Expand Down
3 changes: 2 additions & 1 deletion win64.mak
Expand Up @@ -293,7 +293,8 @@ SRC_STD_C_FREEBSD= \

SRC_STD_INTERNAL= \
std\internal\cstring.d \
std\internal\phobosinit.d \
std\internal\encodinginit.d \
std\internal\processinit.d \
std\internal\unicode_tables.d \
std\internal\unicode_comp.d \
std\internal\unicode_decomp.d \
Expand Down

0 comments on commit df34e42

Please sign in to comment.