-
Notifications
You must be signed in to change notification settings - Fork 42
Public C API (validation only) #530
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
11ff29d
Add public C header fizzy.h
chfast 8eb338a
test: Add C compilation tests
gumb0 48dbba6
Add fizzy_validate() C API function
chfast 4353154
cmake: Restrict some warning options to C++ only
chfast 8f5317f
cmake: Install fizzy library and public headers
chfast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Fizzy: A fast WebAssembly interpreter | ||
| // Copyright 2020 The Fizzy Authors. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
|
|
||
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| bool fizzy_validate(const uint8_t* wasm_binary, size_t wasm_binary_size); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Fizzy: A fast WebAssembly interpreter | ||
| // Copyright 2020 The Fizzy Authors. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include "parser.hpp" | ||
| #include <fizzy/fizzy.h> | ||
|
|
||
| extern "C" { | ||
| bool fizzy_validate(const uint8_t* wasm_binary, size_t wasm_binary_size) | ||
| { | ||
| try | ||
| { | ||
| fizzy::parse({wasm_binary, wasm_binary_size}); | ||
| return true; | ||
| } | ||
| catch (...) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # EVMC: Ethereum Client-VM Connector API. | ||
| # Copyright 2018-2020 The EVMC Authors. | ||
| # Licensed under the Apache License, Version 2.0. | ||
|
|
||
| # This CMake script creates multiple additional targets to test the compilation of public headers | ||
| # with different C standards. | ||
|
|
||
| set(STANDARDS c_std_99 c_std_11) | ||
|
chfast marked this conversation as resolved.
|
||
|
|
||
| foreach(STANDARD 99 11) | ||
| set(target test-compile-c${STANDARD}) | ||
| add_library(${target} OBJECT compilation_test.c) | ||
| target_link_libraries(${target} PRIVATE fizzy::fizzy) | ||
| set_target_properties(${target} PROPERTIES C_STANDARD ${STANDARD} C_EXTENSIONS OFF C_STANDARD_REQUIRED TRUE) | ||
| endforeach() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Fizzy: A fast WebAssembly interpreter | ||
| // Copyright 2020 The Fizzy Authors. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include <fizzy/fizzy.h> | ||
|
|
||
| bool dummy(void); | ||
|
|
||
| bool dummy() | ||
|
gumb0 marked this conversation as resolved.
|
||
| { | ||
| return fizzy_validate(NULL, 0); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Fizzy: A fast WebAssembly interpreter | ||
| // Copyright 2020 The Fizzy Authors. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include <fizzy/fizzy.h> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| TEST(capi, validate) | ||
| { | ||
| uint8_t wasm_prefix[]{0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00}; | ||
| EXPECT_TRUE(fizzy_validate(wasm_prefix, sizeof(wasm_prefix))); | ||
| wasm_prefix[7] = 1; | ||
| EXPECT_FALSE(fizzy_validate(wasm_prefix, sizeof(wasm_prefix))); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.