Skip to content

Commit df34e42

Browse files
authored
Merge pull request dlang#4845 from MartinNowak/merge_stable
Merge remote-tracking branch 'upstream/stable' into merge_stable
2 parents 47adcab + 74486fe commit df34e42

11 files changed

+108
-554
lines changed

changelog.dd

+2-492
Large diffs are not rendered by default.

posix.mak

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ EXTRA_MODULES_INTERNAL := $(addprefix \
216216
std/internal/digest/, sha_SSSE3 ) $(addprefix \
217217
std/internal/math/, biguintcore biguintnoasm biguintx86 \
218218
gammafunction errorfunction) $(addprefix std/internal/, \
219-
cstring phobosinit unicode_tables scopebuffer\
219+
cstring encodinginit processinit unicode_tables scopebuffer\
220220
unicode_comp unicode_decomp unicode_grapheme unicode_norm) \
221221
$(addprefix std/internal/test/, dummyrange) \
222222
$(addprefix std/experimental/ndslice/, internal) \

std/algorithm/iteration.d

+20-17
Original file line numberDiff line numberDiff line change
@@ -3573,6 +3573,8 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
35733573

35743574
_separatorLength = codeLength!(ElementEncodingType!Range)(separator);
35753575
}
3576+
if (_input.empty)
3577+
_frontLength = _atEnd;
35763578
}
35773579

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

37053707
debug(std_algorithm) scope(success)
37063708
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
3707-
assert(equal(splitter("", ' '), [ "" ]));
37083709
assert(equal(splitter("hello world", ' '), [ "hello", "", "world" ]));
37093710
assert(equal(splitter("žlutoučkýřkůň", 'ř'), [ "žlutoučký", "kůň" ]));
37103711
int[] a = [ 1, 2, 0, 0, 3, 0, 4, 5, 0 ];
@@ -3717,7 +3718,7 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
37173718
// }
37183719
assert(equal(splitter(a, 0), w));
37193720
a = null;
3720-
assert(equal(splitter(a, 0), [ (int[]).init ][]));
3721+
assert(equal(splitter(a, 0), (int[][]).init));
37213722
a = [ 0 ];
37223723
assert(equal(splitter(a, 0), [ (int[]).init, (int[]).init ][]));
37233724
a = [ 0, 1 ];
@@ -3821,17 +3822,17 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
38213822
private:
38223823
Range _input;
38233824
Separator _separator;
3824-
enum size_t _unComputed = size_t.max - 1, _atEnd = size_t.max;
3825-
// _frontLength == _atEnd means empty
3826-
size_t _frontLength = _unComputed;
3825+
// _frontLength == size_t.max means empty
3826+
size_t _frontLength = size_t.max;
38273827
static if (isBidirectionalRange!Range)
3828-
size_t _backLength = _unComputed;
3828+
size_t _backLength = size_t.max;
38293829

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

38323832
void ensureFrontLength()
38333833
{
3834-
if (_frontLength != _unComputed) return;
3834+
if (_frontLength != _frontLength.max) return;
3835+
assert(!_input.empty);
38353836
// compute front length
38363837
_frontLength = (_separator.empty) ? 1 :
38373838
_input.length - find!pred(_input, _separator).length;
@@ -3842,7 +3843,8 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
38423843
void ensureBackLength()
38433844
{
38443845
static if (isBidirectionalRange!Range)
3845-
if (_backLength != _unComputed) return;
3846+
if (_backLength != _backLength.max) return;
3847+
assert(!_input.empty);
38463848
// compute back length
38473849
static if (isBidirectionalRange!Range && isBidirectionalRange!Separator)
38483850
{
@@ -3874,7 +3876,7 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
38743876
{
38753877
@property bool empty()
38763878
{
3877-
return _frontLength == _atEnd;
3879+
return _frontLength == size_t.max && _input.empty;
38783880
}
38793881
}
38803882

@@ -3886,9 +3888,9 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
38863888
{
38873889
// done, there's no separator in sight
38883890
_input = _input[_frontLength .. _frontLength];
3889-
_frontLength = _atEnd;
3891+
_frontLength = _frontLength.max;
38903892
static if (isBidirectionalRange!Range)
3891-
_backLength = _atEnd;
3893+
_backLength = _backLength.max;
38923894
return;
38933895
}
38943896
if (_frontLength + separatorLength == _input.length)
@@ -3905,7 +3907,7 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
39053907
// reading the next item
39063908
_input = _input[_frontLength + separatorLength .. _input.length];
39073909
// mark _frontLength as uninitialized
3908-
_frontLength = _unComputed;
3910+
_frontLength = _frontLength.max;
39093911
}
39103912

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

39563958
debug(std_algorithm) scope(success)
39573959
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
3958-
assert(equal(splitter("", " "), [ "" ]));
3959-
39603960
auto s = ",abc, de, fg,hi,";
39613961
auto sp0 = splitter(s, ',');
39623962
// //foreach (e; sp0) writeln("[", e, "]");
@@ -4131,7 +4131,10 @@ private struct SplitterResult(alias isTerminator, Range)
41314131
static if (!fullSlicing)
41324132
_next = _input.save;
41334133

4134-
findTerminator();
4134+
if (!_input.empty)
4135+
findTerminator();
4136+
else
4137+
_end = size_t.max;
41354138
}
41364139

41374140
static if (isInfinite!Range)
@@ -4240,7 +4243,7 @@ private struct SplitterResult(alias isTerminator, Range)
42404243
["Mary", "", "has", "a", "little", "lamb.", "", "", ""]);
42414244
compare("Mary has a little lamb.",
42424245
["Mary", "", "has", "a", "little", "lamb."]);
4243-
compare("", [""]);
4246+
compare("", (string[]).init);
42444247
compare(" ", ["", ""]);
42454248

42464249
static assert(isForwardRange!(typeof(splitter!"a == ' '"("ABC"))));
@@ -4270,7 +4273,7 @@ private struct SplitterResult(alias isTerminator, Range)
42704273
int[][] result;
42714274
}
42724275
Entry[] entries = [
4273-
Entry(0, 0, [[]]),
4276+
Entry(0, 0, []),
42744277
Entry(0, 1, [[0]]),
42754278
Entry(1, 2, [[], []]),
42764279
Entry(2, 7, [[2], [4], [6]]),

std/encoding.d

+38-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module std.encoding;
5555
import std.traits;
5656
import std.typecons;
5757
import std.range.primitives;
58+
import std.internal.encodinginit;
5859

5960
@system unittest
6061
{
@@ -2360,25 +2361,38 @@ abstract class EncodingScheme
23602361
* This function allows user-defined subclasses of EncodingScheme to
23612362
* be declared in other modules.
23622363
*
2364+
* Params:
2365+
* Klass = The subclass of EncodingScheme to register.
2366+
*
23632367
* Example:
23642368
* ----------------------------------------------
23652369
* class Amiga1251 : EncodingScheme
23662370
* {
23672371
* shared static this()
23682372
* {
2369-
* EncodingScheme.register("path.to.Amiga1251");
2373+
* EncodingScheme.register!Amiga1251;
23702374
* }
23712375
* }
23722376
* ----------------------------------------------
23732377
*/
2378+
static void register(Klass:EncodingScheme)()
2379+
{
2380+
scope scheme = new Klass();
2381+
foreach (encodingName;scheme.names())
2382+
{
2383+
supported[toLower(encodingName)] = () => new Klass();
2384+
}
2385+
}
2386+
2387+
deprecated("Please pass the EncodingScheme subclass as template argument instead.")
23742388
static void register(string className)
23752389
{
23762390
auto scheme = cast(EncodingScheme)ClassInfo.find(className).create();
23772391
if (scheme is null)
23782392
throw new EncodingException("Unable to create class "~className);
23792393
foreach (encodingName;scheme.names())
23802394
{
2381-
supported[toLower(encodingName)] = className;
2395+
supportedFactories[toLower(encodingName)] = className;
23822396
}
23832397
}
23842398

@@ -2396,7 +2410,12 @@ abstract class EncodingScheme
23962410
*/
23972411
static EncodingScheme create(string encodingName)
23982412
{
2399-
auto p = toLower(encodingName) in supported;
2413+
encodingName = toLower(encodingName);
2414+
2415+
if (auto p = encodingName in supported)
2416+
return (*p)();
2417+
2418+
auto p = encodingName in supportedFactories;
24002419
if (p is null)
24012420
throw new EncodingException("Unrecognized Encoding: "~encodingName);
24022421
string className = *p;
@@ -2650,7 +2669,8 @@ abstract class EncodingScheme
26502669
return t.length - s.length;
26512670
}
26522671

2653-
__gshared string[string] supported;
2672+
__gshared EncodingScheme function()[string] supported;
2673+
__gshared string[string] supportedFactories;
26542674
}
26552675

26562676
/**
@@ -3297,6 +3317,20 @@ class EncodingSchemeUtf32Native : EncodingScheme
32973317
assert(ub.length == 8);
32983318
}
32993319

3320+
3321+
// shared static this() called from encodinginit to break ctor cycle
3322+
extern(C) void std_encoding_shared_static_this()
3323+
{
3324+
EncodingScheme.register!EncodingSchemeASCII;
3325+
EncodingScheme.register!EncodingSchemeLatin1;
3326+
EncodingScheme.register!EncodingSchemeLatin2;
3327+
EncodingScheme.register!EncodingSchemeWindows1250;
3328+
EncodingScheme.register!EncodingSchemeWindows1252;
3329+
EncodingScheme.register!EncodingSchemeUtf8;
3330+
EncodingScheme.register!EncodingSchemeUtf16Native;
3331+
EncodingScheme.register!EncodingSchemeUtf32Native;
3332+
}
3333+
33003334
//=============================================================================
33013335

33023336

std/internal/encodinginit.d

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Written in the D programming language.
2+
3+
/++
4+
The purpose of this module is to perform static construction away from the
5+
normal modules to eliminate cyclic construction errors.
6+
7+
Copyright: Copyright 2011 - 2016
8+
License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
9+
Authors: Martin Nowak, Steven Schveighoffer
10+
Source: $(PHOBOSSRC std/internal/_encodinginit.d)
11+
+/
12+
module std.internal.encodinginit;
13+
14+
extern(C) void std_encoding_shared_static_this();
15+
16+
shared static this()
17+
{
18+
std_encoding_shared_static_this();
19+
}

std/internal/phobosinit.d

-35
This file was deleted.

std/internal/processinit.d

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Written in the D programming language.
2+
3+
/++
4+
The only purpose of this module is to do the static construction for
5+
std.process in order to eliminate cyclic construction errors.
6+
7+
Copyright: Copyright 2011 -
8+
License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
9+
Authors: Jonathan M Davis and Kato Shoichi
10+
Source: $(PHOBOSSRC std/internal/_processinit.d)
11+
+/
12+
module std.internal.processinit;
13+
14+
version(OSX)
15+
{
16+
extern(C) void std_process_shared_static_this();
17+
18+
shared static this()
19+
{
20+
std_process_shared_static_this();
21+
}
22+
}

std/parallelism.d

+1-3
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,7 @@ private final class ParallelismThread : Thread
976976
// Kill daemon threads.
977977
shared static ~this()
978978
{
979-
auto allThreads = Thread.getAll();
980-
981-
foreach (thread; allThreads)
979+
foreach (ref thread; Thread)
982980
{
983981
auto pthread = cast(ParallelismThread) thread;
984982
if (pthread is null) continue;

std/process.d

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ version (Windows)
100100

101101
import std.range.primitives;
102102
import std.stdio;
103+
import std.internal.processinit;
103104
import std.internal.cstring;
104105

105106

win32.mak

+2-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ SRC_STD_C_FREEBSD= \
274274

275275
SRC_STD_INTERNAL= \
276276
std\internal\cstring.d \
277-
std\internal\phobosinit.d \
277+
std\internal\encodinginit.d \
278+
std\internal\processinit.d \
278279
std\internal\unicode_tables.d \
279280
std\internal\unicode_comp.d \
280281
std\internal\unicode_decomp.d \

win64.mak

+2-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ SRC_STD_C_FREEBSD= \
293293

294294
SRC_STD_INTERNAL= \
295295
std\internal\cstring.d \
296-
std\internal\phobosinit.d \
296+
std\internal\encodinginit.d \
297+
std\internal\processinit.d \
297298
std\internal\unicode_tables.d \
298299
std\internal\unicode_comp.d \
299300
std\internal\unicode_decomp.d \

0 commit comments

Comments
 (0)