From 7aff19a9824b64fdcd8e6db6fbd1bb11f0c64b22 Mon Sep 17 00:00:00 2001 From: ike709 Date: Sat, 28 Dec 2024 23:09:35 -0600 Subject: [PATCH 1/3] Convert some ProcJson classes to structs (#2135) Co-authored-by: ike709 --- DMCompiler/Json/DreamProcJson.cs | 56 +++++++++++++++++--------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/DMCompiler/Json/DreamProcJson.cs b/DMCompiler/Json/DreamProcJson.cs index c7f896a301..070adb86c9 100644 --- a/DMCompiler/Json/DreamProcJson.cs +++ b/DMCompiler/Json/DreamProcJson.cs @@ -3,39 +3,39 @@ namespace DMCompiler.Json; public sealed class ProcDefinitionJson { - public int OwningTypeId { get; set; } - public required string Name { get; set; } - public ProcAttributes Attributes { get; set; } - - public int MaxStackSize { get; set; } - public List? Arguments { get; set; } - public List? Locals { get; set; } - public required List SourceInfo { get; set; } - public byte[]? Bytecode { get; set; } - - public bool IsVerb { get; set; } - public VerbSrc? VerbSrc { get; set; } - public string? VerbName { get; set; } - public string? VerbCategory { get; set; } - public string? VerbDesc { get; set; } - public sbyte Invisibility { get; set; } + public int OwningTypeId { get; init; } + public required string Name { get; init; } + public ProcAttributes Attributes { get; init; } + + public int MaxStackSize { get; init; } + public List? Arguments { get; init; } + public List? Locals { get; init; } + public required List SourceInfo { get; init; } + public byte[]? Bytecode { get; init; } + + public bool IsVerb { get; init; } + public VerbSrc? VerbSrc { get; init; } + public string? VerbName { get; init; } + public string? VerbCategory { get; init; } + public string? VerbDesc { get; init; } + public sbyte Invisibility { get; init; } } -public sealed class ProcArgumentJson { - public required string Name { get; set; } - public DMValueType Type { get; set; } +public struct ProcArgumentJson { + public required string Name { get; init; } + public DMValueType Type { get; init; } } -public sealed class LocalVariableJson { - public int Offset { get; set; } - public int? Remove { get; set; } - public string? Add { get; set; } +public struct LocalVariableJson { + public int Offset { get; init; } + public int? Remove { get; init; } + public string? Add { get; init; } } -public sealed class SourceInfoJson { - public int Offset { get; set; } +public struct SourceInfoJson { + public int Offset { get; init; } public int? File { get; set; } - public int Line { get; set; } + public int Line { get; init; } } public class LineComparer : IEqualityComparer { @@ -43,6 +43,10 @@ public bool Equals(SourceInfoJson? x, SourceInfoJson? y) { return x?.Line == y?.Line; } + public bool Equals(SourceInfoJson x, SourceInfoJson y) { + return x.Line == y.Line; + } + public int GetHashCode(SourceInfoJson obj) { return obj.Line.GetHashCode(); } From f7b6d436f81ef5f9266add3f764fbdca2698c27b Mon Sep 17 00:00:00 2001 From: Amy <3855802+amylizzle@users.noreply.github.com> Date: Sun, 29 Dec 2024 21:34:24 +0000 Subject: [PATCH 2/3] Fix null derefernce when enumerating deleted objects (#2128) Co-authored-by: wixoa --- OpenDreamRuntime/Objects/DreamObject.cs | 2 ++ OpenDreamRuntime/Procs/DreamEnumerators.cs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/OpenDreamRuntime/Objects/DreamObject.cs b/OpenDreamRuntime/Objects/DreamObject.cs index cfa73be66b..646a14e50c 100644 --- a/OpenDreamRuntime/Objects/DreamObject.cs +++ b/OpenDreamRuntime/Objects/DreamObject.cs @@ -145,6 +145,8 @@ public void Delete(bool possiblyThreaded = false) { } public bool IsSubtypeOf(TreeEntry ancestor) { + if(Deleted) //null deref protection, deleted objects don't have ObjectDefinition anymore + return false; return ObjectDefinition.IsSubtypeOf(ancestor); } diff --git a/OpenDreamRuntime/Procs/DreamEnumerators.cs b/OpenDreamRuntime/Procs/DreamEnumerators.cs index b954ea507b..6cd5583e31 100644 --- a/OpenDreamRuntime/Procs/DreamEnumerators.cs +++ b/OpenDreamRuntime/Procs/DreamEnumerators.cs @@ -47,8 +47,12 @@ public DreamObjectEnumerator(IEnumerable dreamObjects, TreeEntry? f public bool Enumerate(DMProcState state, DreamReference? reference) { bool success = _dreamObjectEnumerator.MoveNext(); + + while(success && _dreamObjectEnumerator.Current.Deleted) //skip over deleted + success = _dreamObjectEnumerator.MoveNext(); + if (_filterType != null) { - while (success && !_dreamObjectEnumerator.Current.IsSubtypeOf(_filterType)) { + while (success && (_dreamObjectEnumerator.Current.Deleted || !_dreamObjectEnumerator.Current.IsSubtypeOf(_filterType))) { success = _dreamObjectEnumerator.MoveNext(); } } From aab2f493182a5e1712d654eac1f2fdce823afb47 Mon Sep 17 00:00:00 2001 From: ike709 Date: Mon, 30 Dec 2024 16:12:54 -0600 Subject: [PATCH 3/3] Division unit test fixes (#2150) Co-authored-by: ike709 --- .../DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero1.dm | 2 +- .../DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero3.dm | 2 +- .../DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero4.dm | 2 +- .../DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero6.dm | 2 +- .../{Broken Tests => Tests}/Tree/Const/Div_Zero/div_zero2.dm | 0 .../{Broken Tests => Tests}/Tree/Const/Div_Zero/div_zero5.dm | 0 Content.Tests/DMTests.cs | 5 ++--- 7 files changed, 6 insertions(+), 7 deletions(-) rename Content.Tests/DMProject/{Broken Tests => Tests}/Tree/Const/Div_Zero/div_zero2.dm (100%) rename Content.Tests/DMProject/{Broken Tests => Tests}/Tree/Const/Div_Zero/div_zero5.dm (100%) diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero1.dm b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero1.dm index bf3227ba91..6fed176183 100644 --- a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero1.dm +++ b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero1.dm @@ -1,4 +1,4 @@ -// COMPILE ERROR +// COMPILE ERROR OD0011 var/a = 1 / 0 diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero3.dm b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero3.dm index c3b8f68e03..95f4fef712 100644 --- a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero3.dm +++ b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero3.dm @@ -1,4 +1,4 @@ -// COMPILE ERROR +// COMPILE ERROR OD0011 var/static/a = 1 / 0 diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero4.dm b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero4.dm index 227b380ca5..73064bbe1d 100644 --- a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero4.dm +++ b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero4.dm @@ -1,4 +1,4 @@ -// COMPILE ERROR +// COMPILE ERROR OD0011 /proc/one() return 1 diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero6.dm b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero6.dm index 7cb5c6ccc5..b637530b11 100644 --- a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero6.dm +++ b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero6.dm @@ -1,4 +1,4 @@ -// COMPILE ERROR +// COMPILE ERROR OD0011 var/const/a = 0 var/b = 1 / a diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero2.dm b/Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero2.dm similarity index 100% rename from Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero2.dm rename to Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero2.dm diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero5.dm b/Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero5.dm similarity index 100% rename from Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero5.dm rename to Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero5.dm diff --git a/Content.Tests/DMTests.cs b/Content.Tests/DMTests.cs index 684534e7e2..7cff12fd0a 100644 --- a/Content.Tests/DMTests.cs +++ b/Content.Tests/DMTests.cs @@ -79,6 +79,7 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags, int errorCode) { Assert.That(compiledFile is not null && File.Exists(compiledFile), "Failed to compile DM source file"); Assert.That(_dreamMan.LoadJson(compiledFile), $"Failed to load {compiledFile}"); + _dreamMan.LastDMException = null; // Nuke any exception from a prior test _dreamMan.StartWorld(); (bool successfulRun, DreamValue? returned, Exception? exception) = RunTest(); @@ -114,8 +115,6 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags, int errorCode) { } private (bool Success, DreamValue? Returned, Exception? except) RunTest() { - var prev = _dreamMan.LastDMException; - DreamValue? retValue = null; Task callTask = null!; @@ -143,7 +142,7 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags, int errorCode) { } } - bool retSuccess = _dreamMan.LastDMException == prev; // Works because "null == null" is true in this language. + bool retSuccess = _dreamMan.LastDMException == null; // Works because "null == null" is true in this language. return (retSuccess, retValue, _dreamMan.LastDMException); }