Skip to content

Commit 15117dc

Browse files
authored
Changing Fatal() to assert() (#4982)
Replacing Fatal() call sites in src/shell-interface.h & src/tools/wasm-ctor-eval.cpp that were added in the Multi-Memories PR with assert()
1 parent 1e8eb59 commit 15117dc

File tree

2 files changed

+15
-45
lines changed

2 files changed

+15
-45
lines changed

src/shell-interface.h

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -197,116 +197,88 @@ struct ShellExternalInterface : ModuleRunner::ExternalInterface {
197197

198198
int8_t load8s(Address addr, Name memoryName) override {
199199
auto it = memories.find(memoryName);
200-
if (it == memories.end()) {
201-
trap("load8s on non-existing memory");
202-
}
200+
assert(it != memories.end());
203201
auto& memory = it->second;
204202
return memory.get<int8_t>(addr);
205203
}
206204
uint8_t load8u(Address addr, Name memoryName) override {
207205
auto it = memories.find(memoryName);
208-
if (it == memories.end()) {
209-
trap("load8u on non-existing memory");
210-
}
206+
assert(it != memories.end());
211207
auto& memory = it->second;
212208
return memory.get<uint8_t>(addr);
213209
}
214210
int16_t load16s(Address addr, Name memoryName) override {
215211
auto it = memories.find(memoryName);
216-
if (it == memories.end()) {
217-
trap("load16s on non-existing memory");
218-
}
212+
assert(it != memories.end());
219213
auto& memory = it->second;
220214
return memory.get<int16_t>(addr);
221215
}
222216
uint16_t load16u(Address addr, Name memoryName) override {
223217
auto it = memories.find(memoryName);
224-
if (it == memories.end()) {
225-
trap("load16u on non-existing memory");
226-
}
218+
assert(it != memories.end());
227219
auto& memory = it->second;
228220
return memory.get<uint16_t>(addr);
229221
}
230222
int32_t load32s(Address addr, Name memoryName) override {
231223
auto it = memories.find(memoryName);
232-
if (it == memories.end()) {
233-
trap("load32s on non-existing memory");
234-
}
224+
assert(it != memories.end());
235225
auto& memory = it->second;
236226
return memory.get<int32_t>(addr);
237227
}
238228
uint32_t load32u(Address addr, Name memoryName) override {
239229
auto it = memories.find(memoryName);
240-
if (it == memories.end()) {
241-
trap("load32u on non-existing memory");
242-
}
230+
assert(it != memories.end());
243231
auto& memory = it->second;
244232
return memory.get<uint32_t>(addr);
245233
}
246234
int64_t load64s(Address addr, Name memoryName) override {
247235
auto it = memories.find(memoryName);
248-
if (it == memories.end()) {
249-
trap("load64s on non-existing memory");
250-
}
236+
assert(it != memories.end());
251237
auto& memory = it->second;
252238
return memory.get<int64_t>(addr);
253239
}
254240
uint64_t load64u(Address addr, Name memoryName) override {
255241
auto it = memories.find(memoryName);
256-
if (it == memories.end()) {
257-
trap("load64u on non-existing memory");
258-
}
242+
assert(it != memories.end());
259243
auto& memory = it->second;
260244
return memory.get<uint64_t>(addr);
261245
}
262246
std::array<uint8_t, 16> load128(Address addr, Name memoryName) override {
263247
auto it = memories.find(memoryName);
264-
if (it == memories.end()) {
265-
trap("load128 on non-existing memory");
266-
}
248+
assert(it != memories.end());
267249
auto& memory = it->second;
268250
return memory.get<std::array<uint8_t, 16>>(addr);
269251
}
270252

271253
void store8(Address addr, int8_t value, Name memoryName) override {
272254
auto it = memories.find(memoryName);
273-
if (it == memories.end()) {
274-
trap("store8 on non-existing memory");
275-
}
255+
assert(it != memories.end());
276256
auto& memory = it->second;
277257
memory.set<int8_t>(addr, value);
278258
}
279259
void store16(Address addr, int16_t value, Name memoryName) override {
280260
auto it = memories.find(memoryName);
281-
if (it == memories.end()) {
282-
trap("store16 on non-existing memory");
283-
}
261+
assert(it != memories.end());
284262
auto& memory = it->second;
285263
memory.set<int16_t>(addr, value);
286264
}
287265
void store32(Address addr, int32_t value, Name memoryName) override {
288266
auto it = memories.find(memoryName);
289-
if (it == memories.end()) {
290-
trap("store32 on non-existing memory");
291-
}
267+
assert(it != memories.end());
292268
auto& memory = it->second;
293269
memory.set<int32_t>(addr, value);
294270
}
295271
void store64(Address addr, int64_t value, Name memoryName) override {
296272
auto it = memories.find(memoryName);
297-
if (it == memories.end()) {
298-
trap("store64 on non-existing memory");
299-
}
273+
assert(it != memories.end());
300274
auto& memory = it->second;
301275
memory.set<int64_t>(addr, value);
302276
}
303277
void store128(Address addr,
304278
const std::array<uint8_t, 16>& value,
305279
Name memoryName) override {
306280
auto it = memories.find(memoryName);
307-
if (it == memories.end()) {
308-
trap("store128 on non-existing memory");
309-
}
281+
assert(it != memories.end());
310282
auto& memory = it->second;
311283
memory.set<std::array<uint8_t, 16>>(addr, value);
312284
}

src/tools/wasm-ctor-eval.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,7 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
408408
// TODO: handle unaligned too, see shell-interface
409409
template<typename T> T* getMemory(Address address, Name memoryName) {
410410
auto it = memories.find(memoryName);
411-
if (it == memories.end()) {
412-
Fatal() << "memory not found: " << memoryName;
413-
}
411+
assert(it != memories.end());
414412
auto& memory = it->second;
415413
// resize the memory buffer as needed.
416414
auto max = address + sizeof(T);

0 commit comments

Comments
 (0)