Skip to content

Commit b647c98

Browse files
authored
Fix getValue/setValue of pointer types (#17028)
This issue was introduced in #16874 but went unnoticed due to lack of testing.
1 parent 3cc24a6 commit b647c98

8 files changed

+36
-27
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.12
2222
------
23+
- Fix crash, introduced in 3.1.11, which occurred when using pointer types
24+
(types ending in `*`) with getValue/setValue library functions. (#17028)
2325

2426
3.1.11 - 05/21/2022
2527
-------------------

src/library_getvalue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var LibraryMemOps = {
1111
@param {string} type
1212
@param {number|boolean=} noSafe */`,
1313
$setValue: function(ptr, value, type = 'i8', noSafe) {
14-
if (type.endsWith('*')) type = '{{{ POINTER_TYPE }}}';
14+
if (type.endsWith('*')) type = '{{{ POINTER_WASM_TYPE }}}';
1515
#if SAFE_HEAP
1616
if (noSafe) {
1717
switch (type) {
@@ -44,7 +44,7 @@ var LibraryMemOps = {
4444
@param {string} type
4545
@param {number|boolean=} noSafe */`,
4646
$getValue: function(ptr, type = 'i8', noSafe) {
47-
if (type.endsWith('*')) type = '{{{ POINTER_TYPE }}}';
47+
if (type.endsWith('*')) type = '{{{ POINTER_WASM_TYPE }}}';
4848
#if SAFE_HEAP
4949
if (noSafe) {
5050
switch (type) {

tests/core/getValue_setValue.cpp

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/core/getValue_setValue.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/core/test_getValue_setValue.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Emscripten Authors. All rights reserved.
2+
// Emscripten is available under two separate licenses, the MIT license and the
3+
// University of Illinois/NCSA Open Source License. Both these licenses can be
4+
// found in the LICENSE file.
5+
6+
#include<emscripten.h>
7+
8+
int main() {
9+
char buffer_char[8] = { 'x' };
10+
void* buffer_ptr[] = { (void*)0x12345678 };
11+
#ifdef DIRECT
12+
EM_ASM({
13+
out('i32: ' + getValue($0, 'i32'));
14+
setValue($0, 1234, 'i32');
15+
out('i32: ' + getValue($0, 'i32'));
16+
out('ptr: 0x' + getValue($1, '*').toString(16));
17+
}, buffer_char, buffer_ptr);
18+
#else
19+
EM_ASM({
20+
out('i32: ' + getValue($0, 'i32'));
21+
Module['setValue']($0, 1234, 'i32');
22+
out('i32: ' + Module['getValue']($0, 'i32'));
23+
out('ptr: 0x' + Module['getValue']($1, 'i32').toString(16));
24+
}, buffer_char, buffer_ptr);
25+
#endif
26+
}
27+

tests/core/test_getValue_setValue.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
i32: 120
2+
i32: 1234
3+
ptr: 0x12345678

tests/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7006,8 +7006,8 @@ def test_dyncall_specific(self, *args):
70067006
def test_getValue_setValue(self):
70077007
# these used to be exported, but no longer are by default
70087008
def test(output_prefix='', args=[], assert_returncode=0):
7009-
src = test_file('core/getValue_setValue.cpp')
7010-
expected = test_file('core/getValue_setValue' + output_prefix + '.out')
7009+
src = test_file('core/test_getValue_setValue.cpp')
7010+
expected = test_file('core/test_getValue_setValue' + output_prefix + '.out')
70117011
self.do_run_from_file(src, expected, assert_returncode=assert_returncode, emcc_args=args)
70127012

70137013
# see that direct usage (not on module) works. we don't export, but the use

0 commit comments

Comments
 (0)