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

wasmer-c-api-changes: making wasmer_byte_array fields public #589

Merged
merged 3 commits into from
Aug 1, 2019

Conversation

YaronWittenstein
Copy link
Contributor

@YaronWittenstein YaronWittenstein commented Jul 29, 2019

I've added this PR since I've tests that need access to wasmer_byte_array field.
Here is an example:
https://github.com/spacemeshos/svm/blob/52f04b52cc9a5227030f3dd3499e04c6cbe143d9/crates/svm-wasmer-c-api/tests/c_api.rs#L96

unsafe fn cast_wasmer_byte_array_to_string(wasmer_bytes: &wasmer_byte_array) -> String {
    let slice: &[u8] =
        std::slice::from_raw_parts(wasmer_bytes.bytes, wasmer_bytes.bytes_len as usize);

    if let Ok(s) = std::str::from_utf8(slice) {
        s.to_string()
    } else {
        panic!("error converting `wasmer_byte_array` to string")
    }
}

@syrusakbary @bjfish @Hywan

YaronWittenstein added a commit to spacemeshos/wasmer that referenced this pull request Jul 29, 2019
@bjfish
Copy link
Contributor

bjfish commented Aug 1, 2019

This looks good to me.
bors r+

bors bot added a commit that referenced this pull request Aug 1, 2019
589: wasmer-c-api-changes: making `wasmer_byte_array` fields `public` r=bjfish a=YaronWittenstein

I've added this PR since I've tests that need access to `wasmer_byte_array` field.
Here is an example:
https://github.com/spacemeshos/svm/blob/52f04b52cc9a5227030f3dd3499e04c6cbe143d9/crates/svm-wasmer-c-api/tests/c_api.rs#L96

```rust
unsafe fn cast_wasmer_byte_array_to_string(wasmer_bytes: &wasmer_byte_array) -> String {
    let slice: &[u8] =
        std::slice::from_raw_parts(wasmer_bytes.bytes, wasmer_bytes.bytes_len as usize);

    if let Ok(s) = std::str::from_utf8(slice) {
        s.to_string()
    } else {
        panic!("error converting `wasmer_byte_array` to string")
    }
}
```

@syrusakbary @bjfish @Hywan 

Co-authored-by: Yaron Wittenstein <yaron.wittenstein@gmail.com>
Co-authored-by: Brandon Fish <bjfish@users.noreply.github.com>
@bors bors bot merged commit d9e1609 into wasmerio:master Aug 1, 2019
@YaronWittenstein YaronWittenstein deleted the wasmer-c-api-changes branch August 1, 2019 12:37
@Hywan Hywan added 📦 lib-c-api About wasmer-c-api 🎉 enhancement New feature! labels Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature! 📦 lib-c-api About wasmer-c-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants