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

Remove basic_string<unsigned char> from embind #23070

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

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Dec 4, 2024

Only char, wchar, char8, char16, and char32 are valid specializations for std::basic_string:
https://en.cppreference.com/w/cpp/string/basic_string

But libc++ had a base template for basic_string that allowed any type to be passed for a long time. It looks there have been several attempts to remove this after which they restored it due to complaints, in chronological order:
llvm/llvm-project@aeecef0 llvm/llvm-project@08a0faf llvm/llvm-project@e30a148 llvm/llvm-project#66153
llvm/llvm-project#72694

The last one, llvm/llvm-project#72694, eventually removed it. So std::basic_string<unsigned char> is not allowed anymore. This removes all uses of std::basic_string<unsigned char> from embind.

This needs to be done to update libc++ to LLVM 19 (#22994). I'm uploading this as a separate PR because this removes a functionality from embind.

Only `char`, `wchar`, `char8`, `char16`, and `char32` are valid
specialization for `std::basic_string`:
https://en.cppreference.com/w/cpp/string/basic_string

But libc++ had a base template for `basic_string` that allowed any type
to be passed for a long time. It looks there have been several attempts
to remove this after which they restored it due to complaints, in
chronological order:
llvm/llvm-project@aeecef0
llvm/llvm-project@08a0faf
llvm/llvm-project@e30a148
llvm/llvm-project#66153
llvm/llvm-project#72694

The last one, llvm/llvm-project#72694,
eventually removed it. So `std::basic_string<unsigned_char>` is not
allowed anymore. This removes all uses of
`std::basic_string<unsigned_char>` from embind.

This needs to be done to update libc++ to LLVM 19 (emscripten-core#22994). I'm
uploading this as a separate PR because this removes a functionality
from embind.
@aheejin aheejin changed the title Remove basic_string<unsigned_char> from embind Remove basic_string<unsigned char> from embind Dec 4, 2024
@brendandahl
Copy link
Collaborator

I suppose this could break some people, though I'm not aware of any active users of it. For c++20, we could change it to register char8_t, however I lean towards removing it and bringing it back if needed.

If we do remove it, we should also update the code here. The condition (name === "std::string") will always be true then, so we can use the preprocessor macro to only emit the code in the corresponding branches of the if (stdStringIsUTF8).

test("can pass Uint8Array to std::basic_string<unsigned char>", function() {
var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char(new Uint8Array([65, 66, 67, 68]));
assert.equal('ABCD', e);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we change the test such that it tests that this does not work?

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