Skip to content

Commit 33c97b9

Browse files
committed
Use Nullable for max memory limit
1 parent 2bf8e3f commit 33c97b9

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

source/binary/mod.d

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import std.bitmanip : read;
1111
import std.exception : enforce;
1212
import std.range : front, popFront, popFrontExactly;
1313
import std.system : Endian;
14-
import std.typecons : Tuple, tuple;
14+
import std.typecons : Nullable, nullable, Tuple, tuple;
1515

1616
///
1717
struct Module
@@ -102,7 +102,7 @@ Tuple!(SectionCode, uint) decodeSectionHeader(ref const(ubyte)[] input)
102102
const(Memory) decodeMemorySection(ref const(ubyte)[] input)
103103
{
104104
input.leb128!uint();
105-
const limits = decodeLimits(input);
105+
const limits = input.decodeLimits();
106106
return Memory(limits: limits);
107107
}
108108

@@ -111,7 +111,7 @@ Limits decodeLimits(ref const(ubyte)[] input)
111111
{
112112
const flags = input.leb128!uint();
113113
const min = input.leb128!uint();
114-
const max = flags == 0 ? uint.max : input.leb128!uint();
114+
const max = flags == 0 ? Nullable!uint.init : nullable(input.leb128!uint());
115115
return Limits(min: min, max: max);
116116
}
117117

@@ -577,8 +577,8 @@ unittest
577577
import std.process;
578578
import std.typecons;
579579
const tests = [
580-
tuple("(module (memory 1))", Limits(min: 1, max: uint.max)),
581-
tuple("(module (memory 1 2))", Limits(min: 1, max: 2))
580+
tuple("(module (memory 1))", Limits(min: 1, max: Nullable!uint.init)),
581+
tuple("(module (memory 1 2))", Limits(min: 1, max: nullable(2u)))
582582
];
583583
foreach (test; tests)
584584
{
@@ -632,7 +632,7 @@ unittest
632632
const (ubyte)[] wasm = cast(ubyte[]) p.output;
633633
const actual = decodeModule(wasm);
634634
const Module expected = {
635-
memorySection: [Memory(limits: Limits(min: 1, max: uint.max))],
635+
memorySection: [Memory(limits: Limits(min: 1, max: Nullable!uint.init))],
636636
dataSection: test[1]
637637
};
638638
assert(actual == expected);

source/binary/types.d

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module binary.types;
33
import binary.instruction;
44

55
import std.sumtype;
6+
import std.typecons : Nullable;
67

78
///
89
struct FuncType
@@ -66,7 +67,7 @@ struct Limits
6667
///
6768
uint min;
6869
///
69-
uint max;
70+
Nullable!uint max;
7071
}
7172

7273
///

source/execution/store.d

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import std.bitmanip : write;
88
import std.exception : enforce;
99
import std.range : zip;
1010
import std.sumtype;
11+
import std.typecons : Nullable;
1112

1213
///
1314
enum uint PAGESIZE = 65_536;
@@ -68,7 +69,7 @@ struct MemoryInst
6869
///
6970
ubyte[] data;
7071
///
71-
uint max;
72+
Nullable!uint max;
7273
}
7374

7475
///

0 commit comments

Comments
 (0)