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

Implemented Store.SetLimits #243

Merged
merged 4 commits into from
May 11, 2023

Conversation

martindevans
Copy link
Contributor

Implemented Store.SetLimits using the new wasmtime_store_limiter function.

@martindevans
Copy link
Contributor Author

I wasn't completely sure how to expose this method, due to the way limits are handled. Opinions?

Use -1 for default

This is what the C API expects, but it's a bit ugly.

Use nullable values and null for default

This I think fits C# better, but now leaves us accepting both -1 and null for defaults.

Hardcode default values

The documentation does specify exactly what the defaults are (unlimited or 10000). So we could hardcode those as the default values in the method signature. They're already effectively "hardcoded" in the documentation as is.

@kpreisser
Copy link
Contributor

Thanks for creating this PR! I also thought about implementing this, but didn't find time to do so.

Opinions?

I would favor option 2 (use nullable values), at least for the parameters that can specify an unlimited value according to the documentation (memory_size and table_elements). This would match e.g. the Memory.Maximum API which is also a nullable long?, where null means the memory doesn't have a maximum.

Regarding accepting both negative values and null, we could throw an ArgumentOutOfRangeException if a negative value is specified, so that null is the only way to specify that the default value should be used.

What do you think?
Thanks!

@martindevans
Copy link
Contributor Author

Thanks for the feedback, I went back and made some changes.

memorySize, instances, tables and memories now all throw if a negative value is passed.

I noticed in the implementation that table_elements is handled differently (https://github.com/bytecodealliance/wasmtime/blob/ec6755512f7607c92a5dfd28bc8af782ee973ed6/crates/c-api/src/store.rs#L115) - it's cast down to a u32 internally. So I'm handling that differently (as uint?), which eliminates the need for a runtime check of that value (and also prevents passing values that are too large).

@peterhuene peterhuene self-requested a review May 11, 2023 19:45
Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just the incredibly minor nit!

src/Store.cs Show resolved Hide resolved
@peterhuene peterhuene merged commit 2c462c0 into bytecodealliance:main May 11, 2023
@peterhuene
Copy link
Member

Thanks for implementing this!

@martindevans martindevans deleted the new_store_limiter branch May 11, 2023 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants