Skip to content

Commit 0bd899b

Browse files
aheejinhedwigz
authored andcommitted
Remove basic_string<unsigned char> from embind (emscripten-core#23070)
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 (emscripten-core#22994). I'm uploading this as a separate PR because this removes a functionality from embind.
1 parent 4fb76c0 commit 0bd899b

File tree

7 files changed

+17
-48
lines changed

7 files changed

+17
-48
lines changed

ChangeLog.md

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ See docs/process.md for more on how version tagging works.
2626
- Emscripten-generated code will now use async/await internally when loading
2727
the Wasm module. This will be lowered away by babel when targeting older
2828
browsers. (#23068)
29+
- Due to the discontinued support for invalid specializations of
30+
- `std::basic_string` (https://github.com/llvm/llvm-project/pull/72694), the
31+
support for `std::basic_string<unsigned char>` was removed from embind.
32+
(#23070)
2933

3034
3.1.73 - 11/28/24
3135
-----------------

src/embind/embind.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,7 @@ var LibraryEmbind = {
496496
name = readLatin1String(name);
497497
var stdStringIsUTF8
498498
#if EMBIND_STD_STRING_IS_UTF8
499-
//process only std::string bindings with UTF8 support, in contrast to e.g. std::basic_string<unsigned char>
500-
= (name === "std::string");
499+
= true;
501500
#else
502501
= false;
503502
#endif

system/lib/embind/bind.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ EMSCRIPTEN_BINDINGS(builtin) {
149149
register_float<double>("double");
150150

151151
_embind_register_std_string(TypeID<std::string>::get(), "std::string");
152-
_embind_register_std_string(
153-
TypeID<std::basic_string<unsigned char>>::get(), "std::basic_string<unsigned char>");
154152
_embind_register_std_wstring(TypeID<std::wstring>::get(), sizeof(wchar_t), "std::wstring");
155153
_embind_register_std_wstring(TypeID<std::u16string>::get(), sizeof(char16_t), "std::u16string");
156154
_embind_register_std_wstring(TypeID<std::u32string>::get(), sizeof(char32_t), "std::u32string");

test/code_size/embind_hello_wasm.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 552,
33
"a.html.gz": 380,
4-
"a.js": 9718,
5-
"a.js.gz": 4291,
6-
"a.wasm": 7728,
7-
"a.wasm.gz": 3502,
8-
"total": 17998,
9-
"total_gz": 8173
4+
"a.js": 9593,
5+
"a.js.gz": 4230,
6+
"a.wasm": 7615,
7+
"a.wasm.gz": 3471,
8+
"total": 17760,
9+
"total_gz": 8081
1010
}

test/code_size/embind_val_wasm.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 552,
33
"a.html.gz": 380,
4-
"a.js": 6849,
5-
"a.js.gz": 2947,
6-
"a.wasm": 9568,
7-
"a.wasm.gz": 4911,
8-
"total": 16969,
9-
"total_gz": 8238
4+
"a.js": 6724,
5+
"a.js.gz": 2900,
6+
"a.wasm": 9528,
7+
"a.wasm.gz": 4896,
8+
"total": 16804,
9+
"total_gz": 8176
1010
}

test/embind/embind.test.js

-27
Original file line numberDiff line numberDiff line change
@@ -449,33 +449,6 @@ module({
449449
assert.equal('ABCD', e);
450450
});
451451

452-
test("can pass Uint8Array to std::basic_string<unsigned char>", function() {
453-
var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char(new Uint8Array([65, 66, 67, 68]));
454-
assert.equal('ABCD', e);
455-
});
456-
457-
test("can pass long string to std::basic_string<unsigned char>", function() {
458-
var s = 'this string is long enough to exceed the short string optimization';
459-
var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char(s);
460-
assert.equal(s, e);
461-
});
462-
463-
test("can pass Uint8ClampedArray to std::basic_string<unsigned char>", function() {
464-
var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char(new Uint8ClampedArray([65, 66, 67, 68]));
465-
assert.equal('ABCD', e);
466-
});
467-
468-
469-
test("can pass Int8Array to std::basic_string<unsigned char>", function() {
470-
var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char(new Int8Array([65, 66, 67, 68]));
471-
assert.equal('ABCD', e);
472-
});
473-
474-
test("can pass ArrayBuffer to std::basic_string<unsigned char>", function() {
475-
var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char((new Int8Array([65, 66, 67, 68])).buffer);
476-
assert.equal('ABCD', e);
477-
});
478-
479452
test("can pass string to std::string", function() {
480453
var string = stdStringIsUTF8?"aeiáéíαειЖЛФ從獅子€":"ABCD";
481454

test/embind/embind_test.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,6 @@ std::string emval_test_take_and_return_std_string_const_ref(const std::string& s
246246
return str;
247247
}
248248

249-
std::basic_string<unsigned char> emval_test_take_and_return_std_basic_string_unsigned_char(std::basic_string<unsigned char> str) {
250-
return str;
251-
}
252-
253249
std::wstring take_and_return_std_wstring(std::wstring str) {
254250
return str;
255251
}
@@ -1914,7 +1910,6 @@ EMSCRIPTEN_BINDINGS(tests) {
19141910
//function("emval_test_take_and_return_const_char_star", &emval_test_take_and_return_const_char_star);
19151911
function("emval_test_take_and_return_std_string", &emval_test_take_and_return_std_string);
19161912
function("emval_test_take_and_return_std_string_const_ref", &emval_test_take_and_return_std_string_const_ref);
1917-
function("emval_test_take_and_return_std_basic_string_unsigned_char", &emval_test_take_and_return_std_basic_string_unsigned_char);
19181913
function("take_and_return_std_wstring", &take_and_return_std_wstring);
19191914
function("take_and_return_std_u16string", &take_and_return_std_u16string);
19201915
function("take_and_return_std_u32string", &take_and_return_std_u32string);

0 commit comments

Comments
 (0)