Skip to content

[embind] Add pointer policies for creating val objects. #24175

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

brendandahl
Copy link
Collaborator

Using pointers with val worked inconsistently before where:

  Foo f;
  Foo* p = &f;
  val v1(p); // works fine
  val v2(&f); // fails

The pointer working above was probably a mistake[1] and was caused by TypeID normalizing the types differently than how BindingType does. This patch picks up the work done previously[2] to enforce that types are normalized consistently.

In the above example both will now require a pointer policy e.g. (val v(p, allow_raw_pointers()).

[1]#7292 (comment) [2]https://github.com/yeputons/emscripten/tree/fix-7292-embind-type-normalize

Using pointers with val worked inconsistently before where:

```
  Foo f;
  Foo* p = &f;
  val v1(p); // works fine
  val v2(&f); // fails
```

The pointer working above was probably a mistake[1] and was caused by
TypeID normalizing the types differently than how BindingType does. This
patch picks up the work done previously[2] to enforce that types are
normalized consistently.

In the above example both will now require a pointer policy e.g.
`(val v(p, allow_raw_pointers())`.

[1]emscripten-core#7292 (comment)
[2]https://github.com/yeputons/emscripten/tree/fix-7292-embind-type-normalize
@brendandahl brendandahl requested a review from sbc100 April 23, 2025 17:47
})
def test_embind_no_raw_pointers(self, filename):
stderr = self.expect_fail([EMCC, '-lembind', test_file(filename)])
self.assertContained('Implicitly binding raw pointers is illegal.', stderr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm almost tempted to say you should just write 3 separate tests here (since each one is only two lines), but I'm not sure it makes any difference really.

@brendandahl
Copy link
Collaborator Author

Running some tests in g3 before I land this...

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