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

Allow custom memory allocator Reallocate to fail #2315

Merged
merged 3 commits into from
Sep 16, 2024
Merged

Allow custom memory allocator Reallocate to fail #2315

merged 3 commits into from
Sep 16, 2024

Conversation

ncruces
Copy link
Collaborator

@ncruces ncruces commented Sep 14, 2024

Hey! 👋

This is just an idea, but the change was small enough that I decided to just try it.

How would we feel about allowing the custom allocator to return nil to signal it can't grow the linear memory?

In Go, a failure to allocate memory is a fatal condition, so it makes sense that we don't think about this when using append to grow the linear memory.

But custom allocators can handle this, it doesn't need to be a fatal condition. Also Wasm modules can deal with it: e.g. for wasi-lib, if sbrk fails, malloc just returns NULL, and (e.g.) SQLite can deal with that by freeing caches and trying again (if configured to do so).

cc: @anuraaga

Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
@mathetake
Copy link
Member

Sounds reasonable to me

@ncruces ncruces marked this pull request as draft September 14, 2024 23:00
@ncruces
Copy link
Collaborator Author

ncruces commented Sep 14, 2024

OK. I'll add a test and document the behavior in the interface.

Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
@ncruces ncruces marked this pull request as ready for review September 15, 2024 12:53
internal/wasm/memory.go Outdated Show resolved Hide resolved
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
@ncruces ncruces merged commit 1353ca2 into main Sep 16, 2024
44 checks passed
@ncruces ncruces deleted the growfail branch September 16, 2024 09:28
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