Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish name constructors for zt strings #151

Merged
merged 1 commit into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ own wasm_trap_t* fail_callback(
) {
printf("Calling back...\n");
own wasm_name_t message;
wasm_name_new_from_string(&message, "callback abort");
wasm_name_new_from_string_nt(&message, "callback abort");
own wasm_trap_t* trap = wasm_trap_new((wasm_store_t*)env, &message);
wasm_name_delete(&message);
return trap;
Expand Down
2 changes: 1 addition & 1 deletion example/trap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ auto fail_callback(
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
auto store = reinterpret_cast<wasm::Store*>(env);
auto message = wasm::Name::make(std::string("callback abort"));
auto message = wasm::Name::make_nt(std::string("callback abort"));
return wasm::Trap::make(store, message);
}

Expand Down
6 changes: 6 additions & 0 deletions include/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ typedef wasm_byte_vec_t wasm_name_t;

static inline void wasm_name_new_from_string(
own wasm_name_t* out, const char* s
) {
wasm_name_new(out, strlen(s), s);
}

static inline void wasm_name_new_from_string_nt(
own wasm_name_t* out, const char* s
) {
wasm_name_new(out, strlen(s) + 1, s);
}
Expand Down
6 changes: 6 additions & 0 deletions include/wasm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ public:
}

static auto make(std::string s) -> vec<char> {
auto v = vec(s.length());
if (v) std::strncpy(v.get(), s.data(), s.length());
return v;
}

static auto make_nt(std::string s) -> vec<char> {
auto v = vec(s.length() + 1);
if (v) std::strcpy(v.get(), s.data());
return v;
Expand Down