Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Get error when compiling passing-data.c example #43

Closed
caesar3x opened this issue Mar 16, 2020 · 1 comment · Fixed by wasmerio/wasmer#1335
Closed

Get error when compiling passing-data.c example #43

caesar3x opened this issue Mar 16, 2020 · 1 comment · Fixed by wasmerio/wasmer#1335

Comments

@caesar3x
Copy link

Hi,
I got this error when compiling passing-data.c example:

passing-data.c: In function ‘get_length_of_memory’: passing-data.c:132:36: warning: passing argument 1 of ‘wasmer_memory_data_length’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 132 | return wasmer_memory_data_length(memory); | ^~~~~~ In file included from passing-data.c:2: /home/osboxes/wasmer-c-api/include/wasmer.h:1174:53: note: expected ‘wasmer_memory_t *’ {aka ‘struct <anonymous> *’} but argument is of type ‘const wasmer_memory_t *’ {aka ‘const struct <anonymous> *’} 1174 | uint32_t wasmer_memory_data_length(wasmer_memory_t *memory);

Could anyone please help? I am using this api:
https://github.com/wasmerio/wasmer/releases/download/0.16.2/wasmer-c-api-linux-amd64.tar.gz

Thanks.

@MarkMcCaskey
Copy link
Contributor

Thanks for the bug report!

This looks like an issue with the wasmer c API. I tested this locally and it was a warning, not an error (on OSX with clang). Allowing that warning in the mean-time will help, I'll file an issue on wasmerio/wasmer about this!

bors bot referenced this issue in wasmerio/wasmer Mar 27, 2020
1335:  fix(runtime-c-api) Change mutability of `memory` for `const` in `wasmer_memory_data_length` r=Hywan a=Hywan

This PR changes mutability of `memory` for `const` in `wasmer_memory_data_length` to be more consistent regarding the returned value of `wasmer_instance_context_memory`.

Fixes #1314. 
Fixes wasmerio/docs.wasmer.io#43.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
Co-authored-by: Ivan Enderlin <ivan.enderlin@wanadoo.fr>
bors bot referenced this issue in wasmerio/wasmer Mar 28, 2020
1335:  fix(runtime-c-api) Change mutability of `memory` to`const` in `wasmer_memory_data_length` r=Hywan a=Hywan

This PR changes mutability of `memory` for `const` in `wasmer_memory_data_length` to be more consistent regarding the returned value of `wasmer_instance_context_memory`.

Fixes #1314. 
Fixes wasmerio/docs.wasmer.io#43.

1337: feat(interface-types) Better handling of i32 to usize casts r=Hywan a=Hywan

Fix #1334 

This PR introduces a new `NegativeValue` error.
This PR fixes some `usize` and `u32` types for indexes (small changes).
Finally, this PR casts `i32` to `usize` by using the `TryFrom` implementation. That way:

```rust
let pointer = to_native::<i32>(&inputs[0], instruction)? as usize;
```

becomes:

```rust
let pointer: usize = to_native::<i32>(&inputs[0], instruction)?.try_into().map_err(|_| {
    InstructionError::new(
        instruction,
        InstructionErrorKind::NegativeValue { subject: "pointer" },
    )
})?;
```

It's more verbose, but it handles the casting correctly.

Note: Maybe we should implement `From<TryFromIntError>` for `InstructionErrorKind`? What do you think?

Edit: With `From<TryFromIntError>`, it looks like this:

```rust
let pointer: usize = to_native::<i32>(&inputs[0], instruction)? // convert from WIT to native `i32`
    .try_into() // convert to `usize`
    .map_err(|e| (e, "pointer").into()) // convert the `TryFromIntError` to `InstructionErrorKind::NegativeValue`
    .map_err(|k| InstructionError::new(instruction, k))?; // convert to an `InstructionError`
```

It is indeed simpler. Keeping things like this.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
Co-authored-by: Ivan Enderlin <ivan.enderlin@wanadoo.fr>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants