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

Add method for reading C-style strings from WasmPtr #1086

Closed
MarkMcCaskey opened this issue Dec 19, 2019 · 1 comment · Fixed by #1092
Closed

Add method for reading C-style strings from WasmPtr #1086

MarkMcCaskey opened this issue Dec 19, 2019 · 1 comment · Fixed by #1092
Labels
🎉 enhancement New feature! 📦 lib-deprecated About the deprecated crates

Comments

@MarkMcCaskey
Copy link
Contributor

Suggested on spectrum .

This is a very good idea, we should support getting a slice from a null-terminated array and probably have a function that just returns a &str too. Edge cases to watch out for are null bytes in UTF-8 may be valid if in code point. If that is the case, then we'll want to have a helper method specifically for reading UTF-8 from a WasmPtr with a null terminator. ASCII can probably go through CStr

@MarkMcCaskey MarkMcCaskey added 🎉 enhancement New feature! 📦 lib-deprecated About the deprecated crates labels Dec 19, 2019
@srenatus
Copy link
Contributor

Edge cases to watch out for are null bytes in UTF-8 may be valid if in code point.

From searching the internet, I've come to believe that the only valid code point containing null is null. If that is correct, I don't see how we should differentiate the terminating null from a "non terminating" one. The only way to get an utf8 string from wasm memory that may contain null is the existing one, knowing offset and length.

Am I missing something?

Happy to take a stab at this, but can't make promises wrt. time ;)

srenatus added a commit to srenatus/wasmer that referenced this issue Dec 20, 2019
srenatus added a commit to srenatus/wasmer that referenced this issue Dec 20, 2019
srenatus added a commit to srenatus/wasmer that referenced this issue Dec 20, 2019
srenatus added a commit to srenatus/wasmer that referenced this issue Dec 20, 2019
srenatus added a commit to srenatus/wasmer that referenced this issue Dec 20, 2019
srenatus added a commit to srenatus/wasmer that referenced this issue Dec 20, 2019
srenatus added a commit to srenatus/wasmer that referenced this issue Dec 20, 2019
bors bot added a commit that referenced this issue Dec 20, 2019
1092: Add function to get nul-terminated strings from memory r=MarkMcCaskey a=srenatus

## Description

This is meant to fix #1086.

❓ I'm a bit new to this -- is this how you'd do it? Happy to take directions! 😃 

I've added a note regarding the special case in the comment.

Are there existing tests to expand?

## Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Stephan Renatus <[email protected]>
@bors bors bot closed this as completed in 782be5b Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature! 📦 lib-deprecated About the deprecated crates
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants