From 8d5b75b879693bfd19d5a4cc5d7d91493934bd5d Mon Sep 17 00:00:00 2001 From: ZombineDev Date: Fri, 4 Nov 2016 02:17:52 +0200 Subject: [PATCH] Fix compilation with DMD 2.072.0 The following DMD PRs added more rigorous safety checks directly affecting this project: * dlang/dmd#5852 (fix Issue 15399 - unaligned pointers are not `@safe`) - triggered at line: https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/emitter.d#L1011 * dlang/dmd#5940 (Unions may break immutability / unions with pointers are un-`@safe` ) - triggered at line: https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/event.d#L230 * dlang/dmd#5876 (Casting from `void[]` to `T[]` is erroneously considered `@safe`) - triggered at line: https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/loader.d#L186 * dlang/dmd#5860 (array.ptr in @safe code may point past end of array) - triggered at line: https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/zerostring.d#L35 --- source/dyaml/emitter.d | 2 +- source/dyaml/event.d | 8 ++++++-- source/dyaml/loader.d | 2 +- source/dyaml/zerostring.d | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/dyaml/emitter.d b/source/dyaml/emitter.d index 9f8e991..fe5d997 100644 --- a/source/dyaml/emitter.d +++ b/source/dyaml/emitter.d @@ -54,7 +54,7 @@ class EmitterException : YAMLException private alias EmitterException Error; //Stores results of analysis of a scalar, determining e.g. what scalar style to use. -align(4) struct ScalarAnalysis +struct ScalarAnalysis { //Scalar itself. string scalar; diff --git a/source/dyaml/event.d b/source/dyaml/event.d index 22c5903..40afe2f 100644 --- a/source/dyaml/event.d +++ b/source/dyaml/event.d @@ -227,8 +227,12 @@ Event scalarEvent(const Mark start, const Mark end, const Anchor anchor, const T result.value = value; result.startMark = start; result.endMark = end; - result.anchor = anchor; - result.tag = tag; + + () @trusted { + result.anchor = anchor; + result.tag = tag; + }(); + result.id = EventID.Scalar; result.scalarStyle = style; result.implicit = implicit[0]; diff --git a/source/dyaml/loader.d b/source/dyaml/loader.d index 1839c82..6d0b811 100644 --- a/source/dyaml/loader.d +++ b/source/dyaml/loader.d @@ -179,7 +179,7 @@ struct Loader * * Throws: YAMLException if yamlData contains data illegal in YAML. */ - this(void[] yamlData) @safe + this(void[] yamlData) @trusted { try { diff --git a/source/dyaml/zerostring.d b/source/dyaml/zerostring.d index 841a097..55f2a32 100644 --- a/source/dyaml/zerostring.d +++ b/source/dyaml/zerostring.d @@ -24,7 +24,7 @@ struct ZeroString(string TypeName) @disable int opCmp(ref ZeroString); ///Construct a string. - this(const string str) pure nothrow @safe + this(const string str) pure nothrow @trusted { if(str is null || str == "") {