1#ifndef WASMTIME_HELPERS_HH
2#define WASMTIME_HELPERS_HH
6#define WASMTIME_OWN_WRAPPER(name, capi_type) \
11 using Raw = capi_type##_t; \
15 void operator()(Raw *p) const { capi_type##_delete(p); } \
18 std::unique_ptr<Raw, deleter> ptr; \
24 explicit name(Raw *raw) : ptr(raw) {} \
31 name(name &&other) = default; \
36 name &operator=(name &&other) = default; \
41 const Raw *capi() const { return ptr.get(); } \
46 Raw *capi() { return ptr.get(); } \
51 Raw *capi_release() { return ptr.release(); } \
57 static const name *from_capi(Raw *const *capi) { \
58 static_assert(sizeof(name) == sizeof(void *)); \
59 return reinterpret_cast<const name *>(capi); \
62#define WASMTIME_CLONE_WRAPPER(name, capi_type) \
63 WASMTIME_OWN_WRAPPER(name, capi_type) \
69 name(const name &other) : ptr(capi_type##_clone(other.ptr.get())) {} \
74 name &operator=(const name &other) { \
75 ptr.reset(capi_type##_clone(other.ptr.get())); \
79#define WASMTIME_CLONE_EQUAL_WRAPPER(name, capi_type) \
80 WASMTIME_CLONE_WRAPPER(name, capi_type) \
85 bool operator==(const name &other) const { \
86 return capi_type##_equal(ptr.get(), other.ptr.get()); \
92 bool operator!=(const name &other) const { return !(*this == other); }