Skip to content

[embind] Add pointer policies for setting val object properties. #24811

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

Merged
merged 1 commit into from
Jul 31, 2025

Conversation

brendandahl
Copy link
Collaborator

After #24175, val required a pointer policy when creating a val with a pointer. In val.set(key, value), a temporary val object is created, but there was no way to set the policy from user code. This patch allows the user to pass in allow_raw_pointers() to enable this.

After emscripten-core#24175, `val` required a pointer policy when creating a `val` with
a pointer. In `val.set(key, value)`, a temporary `val` object is created,
but there was no way to set the policy from user code. This patch allows
the user to pass in `allow_raw_pointers()` to enable this.
@brendandahl brendandahl requested review from sbc100 and RReverser July 29, 2025 23:03
@brendandahl
Copy link
Collaborator Author

an aside: @RReverser do you have any thoughts on how to add policies to to val's call and operator(). Unfortunately, they both take variadic arguments already, so I don't see a great way to add on a Policy.... I was thinking either

  1. Make a wrapper struct/tuple thing for Policy arguments
  2. Try to separate the arguments and filter the Policy arguments into a list, but this looks rather painful to do in c++11.

@RReverser
Copy link
Collaborator

RReverser commented Jul 29, 2025

@brendandahl Can't think of a good way either.

My only other ideas were

  • to ask user to provide a single WithPolicies<...> object itself, which might be easier to split out via SFINAE than a variadic list
  • create an AllowRawPointers<T> type that is a zero-cost wrapper around T* (a struct with a single field T* which is ABI-compatible with T* itself in Wasm), so user can write things like call<AllowRawPointers<Foo>>(...) or call<void>(AllowRawPointers(ptr), 42, ...)

@brendandahl brendandahl merged commit fe1d2ee into emscripten-core:main Jul 31, 2025
25 of 30 checks passed
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.

2 participants