bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.12k stars 1.26k forks source link

Unable to get the string_encoding from the c/c++ API headers #6719

Closed GordonSmith closed 1 year ago

GordonSmith commented 1 year ago

Feature

I am trying to implement the "load_string_from_range" ABI function in c++:

def load_string_from_range(cx, ptr, tagged_code_units):
  match cx.opts.string_encoding:
    case 'utf8':
...
    case 'utf16':
...
    case 'latin1+utf16':
...

  return (s, cx.opts.string_encoding, tagged_code_units)

But have been unable to locate anything relating to cx.opts.string_encoding in the c/c++ headers

Benefit

Avoid potential issues dealing with strings

Implementation

Alternatives

Assume string type is "utf8"?

alexcrichton commented 1 year ago

Thanks for the report, but the component model is not supported in the C API yet. So in that sense it's expected that the string encoding isn't availble.

It's worth pointing out though that this string encoding isn't even available in the Rust API, though. This is an internal implementation detail of components which embedders shouldn't in theory need to know about (other than optimizing perhaps)

GordonSmith commented 1 year ago

Thanks for the update - also if the "tagged_code_units" is meant to represent the string length (and not the buffer length) - then the python utf8 case looks wrong to my eye (or is that a question for the spec repo)?

Ref: https://github.com/WebAssembly/component-model/blob/main/design/mvp/canonical-abi/definitions.py#L448C1-L474C57

alexcrichton commented 1 year ago

I think that's a question/issue for the spec repo

GordonSmith commented 1 year ago

Thx... closing.