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

capi: Random minor simplifications #699

Merged
merged 2 commits into from
Jan 27, 2021
Merged
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
16 changes: 7 additions & 9 deletions lib/fizzy/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,18 @@ inline fizzy::ValType unwrap(FizzyValueType value_type) noexcept
return static_cast<fizzy::ValType>(value_type);
}

inline FizzyFunctionType wrap(const fizzy::FuncType& type) noexcept
{
return {(type.outputs.empty() ? FizzyValueTypeVoid : wrap(type.outputs[0])),
(type.inputs.empty() ? nullptr : wrap(&type.inputs[0])), type.inputs.size()};
}

inline FizzyFunctionType wrap(fizzy::span<const fizzy::ValType> input_types,
fizzy::span<const fizzy::ValType> output_types) noexcept
{
return {(output_types.empty() ? FizzyValueTypeVoid : wrap(output_types[0])),
(input_types.empty() ? nullptr : wrap(&input_types[0])), input_types.size()};
}

inline FizzyFunctionType wrap(const fizzy::FuncType& type) noexcept
{
return wrap(type.inputs, type.outputs);
}

inline FizzyValue wrap(fizzy::Value value) noexcept
{
return fizzy::bit_cast<FizzyValue>(value);
Expand Down Expand Up @@ -162,9 +161,8 @@ inline std::vector<fizzy::ExternalFunction> unwrap(
inline fizzy::ImportedFunction unwrap(const FizzyImportedFunction& c_imported_func)
{
fizzy::ImportedFunction imported_func;
imported_func.module =
c_imported_func.module ? std::string{c_imported_func.module} : std::string{};
imported_func.name = c_imported_func.name ? std::string{c_imported_func.name} : std::string{};
imported_func.module = c_imported_func.module;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://stackoverflow.com/a/10771938

But we require module and name to be non-null, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's why it was unnecessary check.

imported_func.name = c_imported_func.name;

const auto& c_type = c_imported_func.external_function.type;
imported_func.inputs.resize(c_type.inputs_size);
Expand Down