Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 0309022

Browse files
committed
Merge remote-tracking branch 'upstream/stable' into merge_stable
# Conflicts: # src/core/internal/convert.d
2 parents 0bf7ddd + 7092709 commit 0309022

File tree

7 files changed

+45
-10
lines changed

7 files changed

+45
-10
lines changed

changelog/backtrace_debug_info_macos.dd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ When running the application it will produce an output similar to:
3232

3333
$(CONSOLE
3434
object.Exception@main.d(3): bar
35-
3635
main.d:3 void main.bar() [0x71afdfb]
3736
main.d:8 void main.foo() [0x71afe0c]
3837
main.d:13 _Dmain [0x71afd78]

src/core/internal/convert.d

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,20 +581,28 @@ const(ubyte)[] toUbyte(T)(ref T val) if (is(Unqual!T == cfloat) || is(Unqual!T =
581581
}
582582

583583
@trusted pure nothrow @nogc
584-
const(ubyte)[] toUbyte(T)(ref T val) if (is(T == enum) && is(typeof(toUbyte(cast(V)val)) == const(ubyte)[]))
584+
const(ubyte)[] toUbyte(T)(ref T val) if (is(T V == enum) && is(typeof(toUbyte(cast(V)val)) == const(ubyte)[]))
585585
{
586586
if (__ctfe)
587587
{
588588
static if (is(T V == enum)){}
589-
V e_val = val;
590-
return toUbyte(e_val);
589+
return toUbyte(cast(V) val);
591590
}
592591
else
593592
{
594593
return (cast(const(ubyte)*)&val)[0 .. T.sizeof];
595594
}
596595
}
597596

597+
nothrow pure @safe unittest
598+
{
599+
// Issue 19008 - check toUbyte works on enums.
600+
enum Month : uint { jan = 1}
601+
Month m = Month.jan;
602+
const bytes = toUbyte(m);
603+
enum ctfe_works = (() => { Month x = Month.jan; return toUbyte(x).length > 0; })();
604+
}
605+
598606
private bool isNonReference(T)()
599607
{
600608
static if (is(T == struct) || is(T == union))

src/core/internal/hash.d

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && (is(T ==
139139
{
140140
return bytesHash(toUbyte(val), seed);
141141
}
142-
else // CTFE unsupproreted for structs with reference fields
142+
else // CTFE unsupported
143143
{
144144
assert(!__ctfe, "unable to compute hash of "~T.stringof);
145-
return bytesHash(toUbyte(val), seed);
145+
const(ubyte)[] bytes = (() @trusted => (cast(const(ubyte)*)&val)[0 .. T.sizeof])();
146+
return bytesHash(bytes, seed);
146147
}
147148
}
148149
}
@@ -154,6 +155,22 @@ nothrow pure @safe unittest // issue 18925
154155
auto h = hashOf(S.init);
155156
}
156157

158+
nothrow pure @safe unittest // issue 19005
159+
{
160+
enum Month : ubyte
161+
{
162+
jan = 1
163+
}
164+
static struct Date
165+
{
166+
short _year;
167+
Month _month;
168+
ubyte _day;
169+
}
170+
Date date;
171+
auto hash = date.hashOf;
172+
}
173+
157174
//delegate hash. CTFE unsupported
158175
@trusted @nogc nothrow pure
159176
size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && is(T == delegate))

src/core/sys/darwin/mach/getsect.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ const(section)* getsectbynamefromheader(
440440
in char* sectname
441441
);
442442

443-
const(section)* getsectbynamefromheaderwithswap_64(
443+
const(section)* getsectbynamefromheaderwithswap(
444444
in mach_header* mhp,
445445
in char* segname,
446446
in char* section,

src/gc/impl/proto/gc.d

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ class ProtoGC : GC
177177
return;
178178
}
179179
}
180-
assert(false);
181180
}
182181

183182
@property RootIterator rootIter() return @nogc
@@ -211,7 +210,6 @@ class ProtoGC : GC
211210
return;
212211
}
213212
}
214-
assert(false);
215213
}
216214

217215
@property RangeIterator rangeIter() return @nogc

test/init_fini/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include ../common.mak
22

3-
TESTS:=thread_join runtime_args
3+
TESTS:=thread_join runtime_args test18996
44

55
.PHONY: all clean
66
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))

test/init_fini/src/test18996.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Issue https://issues.dlang.org/show_bug.cgi?id=18996
2+
// Array!string calls removeRange without first adding the range, but never
3+
// initializes the GC. The behavior of the default GC is to ignore removing
4+
// ranges when the range wasn't added. The ProtoGC originally would crash when
5+
// this happened.
6+
7+
import core.memory;
8+
9+
void main()
10+
{
11+
GC.removeRange(null);
12+
GC.removeRoot(null);
13+
}

0 commit comments

Comments
 (0)