From 03f215327079abb6aa0c0c8cf0cd482260c74629 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 6 May 2022 14:47:56 +0900 Subject: [PATCH] wasm_runtime_common.c: add assertion for BH_MALLOC/BH_FREE (#1139) Add assertion for BH_MALLOC/BH_FREE in wasm_runtime_common.c, when building runtime, the BH_MALLOC/BH_FREE macros should be defined as wasm_runtime_malloc/wasm_runtime_free. --- core/iwasm/common/wasm_runtime_common.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index f239b51f..bc25df1f 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -29,6 +29,28 @@ #endif #include "../common/wasm_c_api_internal.h" +/** + * For runtime build, BH_MALLOC/BH_FREE should be defined as + * wasm_runtime_malloc/wasm_runtime_free. + */ +#define CHECK(a) CHECK1(a) +#define CHECK1(a) SHOULD_BE_##a + +#define SHOULD_BE_wasm_runtime_malloc 1 +#if !CHECK(BH_MALLOC) +#error unexpected BH_MALLOC +#endif +#undef SHOULD_BE_wasm_runtime_malloc + +#define SHOULD_BE_wasm_runtime_free 1 +#if !CHECK(BH_FREE) +#error unexpected BH_FREE +#endif +#undef SHOULD_BE_wasm_runtime_free + +#undef CHECK +#undef CHECK1 + #if WASM_ENABLE_MULTI_MODULE != 0 /** * A safety insurance to prevent