-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
Avoid null terminated strings in the interface for cgo #192
Comments
For passing in strings, we might want adapter functions in the If we do define a wrapper string struct, then we probably want to define it with the same memory layout as |
I'd like to help solve this to make sure the base64 polyfill from kuoruan/v8go-polyfills works correctly on 'binary strings'. |
Here is a script that demonstrates the problem
which prints
"before"
but it should print"before\x00after"
likefmt.Printf("%#v\n", "before\x00after")
does.Similarly, you can try using null characters in JS and you will see that the null character is preserved.
Instead, v8go.h functions should return strings as a character pointer and length (could be wrapped in a struct) so they can be converted to Go strings with
C.GoStringN
and avoid usingC.GoString
for JS strings. That way these null characters can be preserved.There also is an opportunity to avoid extra data copying by returning pointers directly to the V8's string data, when we know that data will be copied to a Go string anyways. Right now, the V8 string data is copied to a null terminated string, which is then copied to a Go string.
The text was updated successfully, but these errors were encountered: