Skip to content

Commit 2bd2dfd

Browse files
committed
fix
Signed-off-by: mathetake <[email protected]>
1 parent f22f900 commit 2bd2dfd

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

src/common/types.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2016-2019 Envoy Project Authors
2+
// Copyright 2020 Google LLC
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
#pragma once
17+
18+
#include <memory>
19+
20+
namespace proxy_wasm {
21+
namespace common {
22+
23+
template <typename T, void (*deleter)(T *)>
24+
class CSmartPtr : public std::unique_ptr<T, void (*)(T *)> {
25+
public:
26+
CSmartPtr() : std::unique_ptr<T, void (*)(T *)>(nullptr, deleter) {}
27+
CSmartPtr(T *object) : std::unique_ptr<T, void (*)(T *)>(object, deleter) {}
28+
};
29+
30+
template <typename T, void (*deleter)(T *)> class DeleterType {
31+
public:
32+
~DeleterType() { deleter(&item); }
33+
T *get() { return &item; }
34+
35+
private:
36+
T item;
37+
};
38+
39+
} // namespace common
40+
} // namespace proxy_wasm

src/wasmtime/types.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
// Copyright 2016-2019 Envoy Project Authors
3+
// Copyright 2020 Google LLC
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#include "src/common/types.h"
18+
#include "wasmtime/include/wasm.h"
19+
#include "wasmtime/include/wasmtime.h"
20+
21+
namespace proxy_wasm {
22+
namespace wasmtime {
23+
24+
using WasmEnginePtr = common::CSmartPtr<wasm_engine_t, wasm_engine_delete>;
25+
using WasmFuncPtr = common::CSmartPtr<wasm_func_t, wasm_func_delete>;
26+
using WasmStorePtr = common::CSmartPtr<wasm_store_t, wasm_store_delete>;
27+
using WasmModulePtr = common::CSmartPtr<wasm_module_t, wasm_module_delete>;
28+
using WasmSharedModulePtr = common::CSmartPtr<wasm_shared_module_t, wasm_shared_module_delete>;
29+
using WasmMemoryPtr = common::CSmartPtr<wasm_memory_t, wasm_memory_delete>;
30+
using WasmTablePtr = common::CSmartPtr<wasm_table_t, wasm_table_delete>;
31+
using WasmInstancePtr = common::CSmartPtr<wasm_instance_t, wasm_instance_delete>;
32+
using WasmFunctypePtr = common::CSmartPtr<wasm_functype_t, wasm_functype_delete>;
33+
using WasmTrapPtr = common::CSmartPtr<wasm_trap_t, wasm_trap_delete>;
34+
using WasmExternPtr = common::CSmartPtr<wasm_extern_t, wasm_extern_delete>;
35+
36+
using WasmByteVec = common::DeleterType<wasm_byte_vec_t, wasm_byte_vec_delete>;
37+
using WasmImporttypeVec = common::DeleterType<wasm_importtype_vec_t, wasm_importtype_vec_delete>;
38+
using WasmExportTypeVec = common::DeleterType<wasm_exporttype_vec_t, wasm_exporttype_vec_delete>;
39+
using WasmExternVec = common::DeleterType<wasm_extern_vec_t, wasm_extern_vec_delete>;
40+
using WasmValtypeVec = common::DeleterType<wasm_valtype_vec_t, wasm_valtype_vec_delete>;
41+
42+
class WasmExternPtrVector {
43+
public:
44+
~WasmExternPtrVector() {
45+
// TODO: come back later
46+
for (auto it = vector.begin(); it < vector.end(); it++) {
47+
// wasm_extern_delete(*it);
48+
}
49+
}
50+
51+
wasm_extern_t **data() { return vector.data(); }
52+
void push_back(wasm_extern_t *item) { vector.push_back(item); }
53+
size_t size() { return vector.size(); }
54+
55+
private:
56+
std::vector<wasm_extern_t *> vector;
57+
};
58+
59+
} // namespace wasmtime
60+
61+
} // namespace proxy_wasm

0 commit comments

Comments
 (0)