go-modules: weird value printed when using function returning

Hello again,

I am trying to use wasm-tools-go to generate bindings for the following wit:

interface variables {
    /// Get an application variable value for the current component.
    ///
    /// The name must match one defined in in the component manifest.
    get: func(name: string) -> result<string, error>;

    /// The set of errors which may be raised by functions in this interface.
    variant error {
        /// The provided variable name is invalid.
        invalid-name(string),
        /// The provided variable is undefined.
        undefined(string),
        /// A variables provider specific error has occurred.
        provider(string),
        /// Some implementation-specific error has occurred.
        other(string),
    }
}

when using the bindings generated, I see weird value printed:

key: password, val is "\x00\x00\x00\x00\x00\x00"

pseudo code:

func Get(key string) (string, error) {
	result := variables.Get(key)
	if result.IsErr() {
		return "", errorVariantToError(*result.Err())
	}

	stdout.GetStdout().Write(cm.ToList([]byte(fmt.Sprintf("key: %s, val is %q \n", key, *result.OK()))))

	return *result.OK(), nil
}

I printed the value on host component implementation side, and it seems to be printing and returning the correct value.

any pointers what could be wrong here? thank you so much for all the help so far.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 27 (15 by maintainers)

Commits related to this issue

Most upvoted comments

No lifting occurs in this case. The component calls the imported function with an outparam pointer to the result.

It works fine to that point (you can edit and log the OK value inside the Get function.

I believe I may have made an incorrect assumption about how Go passes structs on the stack, and may need to revise the shape type for results and variants.

Thanks for the reproduction repos, they’ve been a ton of help.

I’ve verified that the host successfully passes the string in the result<string, error>. The issue seems to be when the generated function returns ErrResult[string, Error] by value on the stack.

It seems to be mangled. If I make it store the data field as a byte slice, it works.

More work tomorrow.