Skip to content

Commit d4cadb5

Browse files
Fix emscripten config
Leaving the emscripten macros returning a value empty was leading to syntax errors The pointer returned by `EM_ASM_PTR` must be freed by calling `free` Add emscripten without a syntax check for now as we would need the emscripten tool chain
1 parent 09f4289 commit d4cadb5

File tree

5 files changed

+210
-12
lines changed

5 files changed

+210
-12
lines changed

Diff for: cfg/emscripten.cfg

+105-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,108 @@
11
<?xml version="1.0"?>
22
<def format="2">
3-
<define name="EM_ASM(...)" value=""/>
4-
<define name="EM_ASM_DOUBLE(...)" value=""/>
5-
<define name="EM_ASM_INT(...)" value=""/>
6-
<define name="EM_ASM_PTR(...)" value=""/>
7-
<define name="EM_JS(...)" value=""/>
8-
<define name="MAIN_THREAD_ASYNC_EM_ASM(...)" value=""/>
9-
<define name="MAIN_THREAD_EM_ASM(...)" value=""/>
10-
<define name="MAIN_THREAD_EM_ASM_DOUBLE(...)" value=""/>
11-
<define name="MAIN_THREAD_EM_ASM_INT(...)" value=""/>
12-
<define name="MAIN_THREAD_EM_ASM_PTR(...)" value=""/>
13-
<define name="EMSCRIPTEN_BINDINGS(...)" value=""/>
3+
<function name="emscripten_asm_const_int">
4+
<arg nr="1" direction="in">
5+
<not-null/>
6+
</arg>
7+
<arg nr="2" direction="in">
8+
<not-null/>
9+
</arg>
10+
<arg nr="variadic" direction="in" />
11+
<use-retval/>
12+
<returnValue type="int" unknownValues="all"/>
13+
<noreturn>false</noreturn>
14+
</function>
15+
<function name="emscripten_asm_const_double">
16+
<arg nr="1" direction="in">
17+
<not-null/>
18+
</arg>
19+
<arg nr="2" direction="in">
20+
<not-null/>
21+
</arg>
22+
<arg nr="variadic" direction="in" />
23+
<use-retval/>
24+
<returnValue type="double" unknownValues="all"/>
25+
<noreturn>false</noreturn>
26+
</function>
27+
<function name="emscripten_asm_const_ptr">
28+
<arg nr="1" direction="in">
29+
<not-null/>
30+
</arg>
31+
<arg nr="2" direction="in">
32+
<not-null/>
33+
</arg>
34+
<arg nr="variadic" direction="in" />
35+
<use-retval/>
36+
<returnValue type="void*" unknownValues="all"/>
37+
<noreturn>false</noreturn>
38+
</function>
39+
<function name="emscripten_asm_const_async_on_main_thread">
40+
<arg nr="1" direction="in">
41+
<not-null/>
42+
</arg>
43+
<arg nr="2" direction="in">
44+
<not-null/>
45+
</arg>
46+
<arg nr="variadic" direction="in" />
47+
<returnValue type="void" unknownValues="all"/>
48+
<noreturn>false</noreturn>
49+
</function>
50+
<function name="emscripten_asm_const_int_sync_on_main_thread">
51+
<arg nr="1" direction="in">
52+
<not-null/>
53+
</arg>
54+
<arg nr="2" direction="in">
55+
<not-null/>
56+
</arg>
57+
<arg nr="variadic" direction="in" />
58+
<use-retval/>
59+
<returnValue type="int" unknownValues="all"/>
60+
<noreturn>false</noreturn>
61+
</function>
62+
<function name="emscripten_asm_const_double_sync_on_main_thread">
63+
<arg nr="1" direction="in">
64+
<not-null/>
65+
</arg>
66+
<arg nr="2" direction="in">
67+
<not-null/>
68+
</arg>
69+
<arg nr="variadic" direction="in" />
70+
<use-retval/>
71+
<returnValue type="int" unknownValues="all"/>
72+
<noreturn>false</noreturn>
73+
</function>
74+
<function name="emscripten_asm_const_ptr_sync_on_main_thread">
75+
<arg nr="1" direction="in">
76+
<not-null/>
77+
</arg>
78+
<arg nr="2" direction="in">
79+
<not-null/>
80+
</arg>
81+
<arg nr="variadic" direction="in" />
82+
<use-retval/>
83+
<returnValue type="void*" unknownValues="all"/>
84+
<noreturn>false</noreturn>
85+
</function>
86+
<resource>
87+
<alloc init="true">emscripten_asm_const_ptr</alloc>
88+
<alloc init="true">emscripten_asm_const_ptr_sync_on_main_thread</alloc>
89+
<dealloc>free</dealloc>
90+
</resource>
91+
92+
<!-- macros from em_asm.h -->
93+
<define name="EM_ASM(code, ...)" value="((void)emscripten_asm_const_int(#code, __VA_ARGS__))"/>
94+
<define name="EM_ASM_DOUBLE(code, ...)" value="emscripten_asm_const_double(#code, __VA_ARGS__)"/>
95+
<define name="EM_ASM_INT(code, ...)" value="emscripten_asm_const_int(#code, __VA_ARGS__)"/>
96+
<define name="EM_ASM_PTR(code, ...)" value="emscripten_asm_const_ptr(#code, __VA_ARGS__)"/>
97+
<define name="MAIN_THREAD_ASYNC_EM_ASM(code, ...)" value="emscripten_asm_const_async_on_main_thread(#code, __VA_ARGS__)"/>
98+
<define name="MAIN_THREAD_EM_ASM(code, ...)" value="((void)emscripten_asm_const_int_sync_on_main_thread(#code, __VA_ARGS__))"/>
99+
<define name="MAIN_THREAD_EM_ASM_DOUBLE(code, ...)" value="emscripten_asm_const_double_sync_on_main_thread(#code, __VA_ARGS__)"/>
100+
<define name="MAIN_THREAD_EM_ASM_INT(code, ...)" value="emscripten_asm_const_int_sync_on_main_thread(#code, __VA_ARGS__)"/>
101+
<define name="MAIN_THREAD_EM_ASM_PTR(code, ...)" value="emscripten_asm_const_ptr_sync_on_main_thread(#code, __VA_ARGS__)"/>
102+
103+
<!-- macros from bind.h -->
104+
<define name="EMSCRIPTEN_BINDINGS(name)" value=""/>
105+
106+
<!-- macros from em_js.h -->
107+
<define name="EM_JS(return_type, function_name, arguments, code)" value="return_type function_name(arguments)"/>
14108
</def>

Diff for: test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ if (BUILD_TESTS)
138138
add_cfg(bsd.c)
139139
add_cfg(cairo.c)
140140
add_cfg(cppunit.cpp)
141+
add_cfg(emscripten.cpp)
141142
# TODO: posix needs to specified first or it has a different mmap() config
142143
# TODO: get rid of posix dependency
143144
add_cfg(gnu.c ADD_LIBRARY posix)

Diff for: test/cfg/emscripten.cpp

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
// Test library configuration for emscripten.cfg
3+
//
4+
// Usage:
5+
// $ cppcheck --check-library --library=emscripten --enable=style,information --inconclusive --error-exitcode=1 --disable=missingInclude --inline-suppr test/cfg/emscripten.cpp
6+
// =>
7+
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
8+
//
9+
10+
#include <stdio.h>
11+
#include <emscripten.h>
12+
13+
void em_asm_test()
14+
{
15+
// inline some JavaScript
16+
EM_ASM(alert('hello'););
17+
MAIN_THREAD_EM_ASM(alert('hello main thread'););
18+
19+
// pass parameters to JavaScript
20+
EM_ASM(
21+
{
22+
console.log('I received: ' + [$0, $1]);
23+
},
24+
100, 35.5);
25+
26+
// pass a string to JavaScript
27+
EM_ASM({console.log('hello ' + UTF8ToString($0))}, "world!");
28+
}
29+
30+
void em_asm_int_test()
31+
{
32+
// cppcheck-suppress unreadVariable
33+
const int x = EM_ASM_INT({
34+
return $0 + 42;
35+
}, 100);
36+
37+
// cppcheck-suppress unreadVariable
38+
const int y = MAIN_THREAD_EM_ASM_INT({return 2;});
39+
}
40+
41+
void em_asm_double_test()
42+
{
43+
// cppcheck-suppress unreadVariable
44+
const double x = EM_ASM_DOUBLE({
45+
return $0 + 1.0;
46+
}, 2.0);
47+
48+
// cppcheck-suppress unreadVariable
49+
const double y = MAIN_THREAD_EM_ASM_DOUBLE({return 1.0;});
50+
}
51+
52+
void em_asm_ptr_test()
53+
{
54+
void* ptr = EM_ASM_PTR({
55+
return stringToNewUTF8("Hello");
56+
});
57+
printf("%s", static_cast<const char*>(ptr));
58+
free(ptr);
59+
}
60+
61+
void em_asm_ptr_memleak_test()
62+
{
63+
const char *str = static_cast<char*>(EM_ASM_PTR({
64+
return stringToNewUTF8("Hello");
65+
}));
66+
printf("%s", str);
67+
68+
// cppcheck-suppress memleak
69+
}
70+
71+
void main_thread_em_asm_ptr_test()
72+
{
73+
// cppcheck-suppress leakReturnValNotUsed
74+
MAIN_THREAD_EM_ASM_PTR(
75+
return stringToNewUTF8("Hello");
76+
);
77+
}
78+
79+
EM_JS(void, two_alerts, (), {
80+
alert('hai');
81+
alert('bai');
82+
});
83+
EM_JS(void, take_args, (int x, float y), {
84+
console.log('I received: ' + [x, y]);
85+
});
86+
87+
void em_js_test()
88+
{
89+
two_alerts();
90+
take_args(100, 35.5);
91+
}

Diff for: test/cfg/runtests.sh

+11
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,13 @@ function cppunit_fn {
447447
fi
448448
}
449449

450+
# emscripten.cpp
451+
function emscripten_fn {
452+
# TODO: Syntax check via g++ does not work because it can not find a valid emscripten.h
453+
# ${CXX} "${CXX_OPT[@]}" ${DIR}emscripten.cpp
454+
true
455+
}
456+
450457
function check_file {
451458
f=$(basename "$1")
452459
lib="${f%%.*}"
@@ -467,6 +474,10 @@ function check_file {
467474
cppunit_fn
468475
"${CPPCHECK}" "${CPPCHECK_OPT[@]}" --library="$lib" "${DIR}""$f"
469476
;;
477+
emscripten.cpp)
478+
emscripten_fn
479+
"${CPPCHECK}" "${CPPCHECK_OPT[@]}" --library="$lib" "${DIR}""$f"
480+
;;
470481
gnu.c)
471482
gnu_fn
472483
# TODO: posix needs to specified first or it has a different mmap() config

Diff for: tools/donate_cpu_lib.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
1717
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
1818
# changes)
19-
CLIENT_VERSION = "1.3.59"
19+
CLIENT_VERSION = "1.3.60"
2020

2121
# Timeout for analysis with Cppcheck in seconds
2222
CPPCHECK_TIMEOUT = 30 * 60
@@ -681,6 +681,7 @@ def __init__(self):
681681
'bsd': ['<sys/queue.h>', '<sys/tree.h>', '<sys/uio.h>','<bsd/', '<fts.h>', '<db.h>', '<err.h>', '<vis.h>'],
682682
'cairo': ['<cairo.h>'],
683683
'cppunit': ['<cppunit/'],
684+
'emscripten': ['<emscripten.h>'],
684685
'icu': ['<unicode/', '"unicode/'],
685686
'ginac': ['<ginac/', '"ginac/'],
686687
'googletest': ['<gtest/gtest.h>'],

0 commit comments

Comments
 (0)