From 51d667c624d68c02261a2d477b1dcbe97ae205cf Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Thu, 30 May 2019 11:26:10 +0000 Subject: [PATCH] Don't leak implementation into headers. Previously, both: embedding C/C++ application and the library had to be built using the same DEBUG define, because vec::make_data() and vec::free_data() were declared in the implementation when built with DEBUG defined, and in the headers otherwise. As a result, linking C/C++ application against library built with different DEBUG define resulted in either: failed build or broken make/free accounting and the library aborting at runtime. Signed-off-by: Piotr Sikora --- include/wasm.hh | 5 ----- src/wasm-v8.cc | 10 ++++++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/wasm.hh b/include/wasm.hh index 024f834..f5ec60b 100644 --- a/include/wasm.hh +++ b/include/wasm.hh @@ -111,13 +111,8 @@ class vec { size_t size_; std::unique_ptr data_; -#ifdef DEBUG void make_data(); void free_data(); -#else - void make_data() {} - void free_data() {} -#endif vec(size_t size) : vec(size, size ? new(std::nothrow) T[size] : nullptr) { make_data(); diff --git a/src/wasm-v8.cc b/src/wasm-v8.cc index c46ff09..84989c9 100644 --- a/src/wasm-v8.cc +++ b/src/wasm-v8.cc @@ -210,6 +210,14 @@ Stats stats; if (data_) stats.free(Stats::STAT, data_.get(), Stats::VEC); \ } +#else + +#define DEFINE_VEC(type, STAT) \ + template<> void vec::make_data() {} \ + template<> void vec::free_data() {} + +#endif // #ifdef DEBUG + DEFINE_VEC(byte_t, BYTE) DEFINE_VEC(Frame*, FRAME) DEFINE_VEC(ValType*, VALTYPE) @@ -231,8 +239,6 @@ DEFINE_VEC(Memory*, MEMORY) DEFINE_VEC(Extern*, EXTERN) DEFINE_VEC(Val, VAL) -#endif // #ifdef DEBUG - /////////////////////////////////////////////////////////////////////////////// // Runtime Environment