Skip to content

Commit a2debca

Browse files
authored
Revert conversion of test_utf32 from cpp to c. (#22684)
This test was failing asan after the conversion in #22669. https://logs.chromium.org/logs/emscripten-releases/buildbucket/cr-buildbucket/8735090587456463425/+/u/Emscripten_testsuite__ASan_/stdout
1 parent aa5778e commit a2debca

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

test/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5680,8 +5680,8 @@ def test_utf(self):
56805680
self.do_core_test('test_utf.c')
56815681

56825682
def test_utf32(self):
5683-
self.do_runf('core/test_utf32.c', 'OK.')
5684-
self.do_runf('core/test_utf32.c', 'OK.', args=['-fshort-wchar'])
5683+
self.do_runf('utf32.cpp', 'OK.')
5684+
self.do_runf('utf32.cpp', 'OK.', args=['-fshort-wchar'])
56855685

56865686
@crossplatform
56875687
def test_utf16(self):

test/core/test_utf32.c renamed to test/utf32.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// found in the LICENSE file.
55

66
#include <stdio.h>
7-
#include <string.h>
7+
#include <string>
88
#include <emscripten.h>
9-
#include <assert.h>
9+
#include <cassert>
1010
#include <wchar.h>
1111

1212
typedef unsigned int utf32;
@@ -19,24 +19,23 @@ int main() {
1919
// U+2603 is snowman,
2020
// U+20AC is the Euro sign,
2121
// U+2007C is a Chinese Han character that looks like three raindrops.
22-
wchar_t wstr[] = L"abc\u2603\u20AC\U0002007C123 --- abc\u2603\u20AC\U0002007C123";
23-
size_t wstr_len = wcslen(wstr);
22+
std::wstring wstr = L"abc\u2603\u20AC\U0002007C123 --- abc\u2603\u20AC\U0002007C123";
2423

2524
printf("sizeof(wchar_t): %d.\n", (int)sizeof(wchar_t));
2625

2726
if (sizeof(wchar_t) == 4) {
28-
utf32 *memory = malloc(wstr_len*sizeof(utf32));
27+
utf32 *memory = new utf32[wstr.length()+1];
2928

3029
EM_ASM({
3130
var str = UTF32ToString($0);
3231
out(str);
3332
var numBytesWritten = stringToUTF32(str, $1, Number($2));
3433
if (numBytesWritten != 23*4) throw 'stringToUTF32 wrote an invalid length ' + numBytesWritten;
35-
}, wstr, memory, (wstr_len+1)*sizeof(utf32));
34+
}, wstr.c_str(), memory, (wstr.length()+1)*sizeof(utf32));
3635

3736
// Compare memory to confirm that the string is intact after taking a route
3837
// through JS side.
39-
const utf32 *srcPtr = (const utf32 *)(wstr);
38+
const utf32 *srcPtr = reinterpret_cast<const utf32 *>(wstr.c_str());
4039
for (int i = 0;; ++i) {
4140
assert(memory[i] == srcPtr[i]);
4241
if (srcPtr[i] == 0)
@@ -48,24 +47,24 @@ int main() {
4847
out(str);
4948
var numBytesWritten = stringToUTF32(str, $1, Number($2));
5049
if (numBytesWritten != 5*4) throw 'stringToUTF32 wrote an invalid length ' + numBytesWritten;
51-
}, wstr, memory, 6*sizeof(utf32));
50+
}, wstr.c_str(), memory, 6*sizeof(utf32));
5251
assert(memory[5] == 0);
5352

54-
free(memory);
53+
delete[] memory;
5554
} else {
5655
// sizeof(wchar_t) == 2, and we're building with -fshort-wchar.
57-
utf16 *memory = malloc((2*wstr_len+1) * sizeof(utf16));
56+
utf16 *memory = new utf16[2*wstr.length()+1];
5857

5958
EM_ASM({
6059
var str = UTF16ToString($0);
6160
out(str);
6261
var numBytesWritten = stringToUTF16(str, $1, $2);
6362
if (numBytesWritten != 25*2) throw 'stringToUTF16 wrote an invalid length ' + numBytesWritten;
64-
}, wstr, memory, (2*wstr_len+1)*sizeof(utf16));
63+
}, wstr.c_str(), memory, (2*wstr.length()+1)*sizeof(utf16));
6564

6665
// Compare memory to confirm that the string is intact after taking a route
6766
// through JS side.
68-
const utf16 *srcPtr = (const utf16 *)(wstr);
67+
const utf16 *srcPtr = reinterpret_cast<const utf16 *>(wstr.c_str());
6968
for (int i = 0;; ++i) {
7069
assert(memory[i] == srcPtr[i]);
7170
if (srcPtr[i] == 0)
@@ -77,10 +76,10 @@ int main() {
7776
out(str);
7877
var numBytesWritten = stringToUTF16(str, $1, $2);
7978
if (numBytesWritten != 5*2) throw 'stringToUTF16 wrote an invalid length ' + numBytesWritten;
80-
}, wstr, memory, 6*sizeof(utf16));
79+
}, wstr.c_str(), memory, 6*sizeof(utf16));
8180
assert(memory[5] == 0);
8281

83-
free(memory);
82+
delete[] memory;
8483
}
8584

8685
printf("OK.\n");

0 commit comments

Comments
 (0)