Skip to content

Commit b8ed4a9

Browse files
authored
Add versions of emscripten_out/err/dbg that take an explicit string length (#19492)
1 parent f655c30 commit b8ed4a9

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

src/library.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,15 +3391,24 @@ mergeInto(LibraryManager.library, {
33913391
emscripten_out: function(str) {
33923392
out(UTF8ToString(str));
33933393
},
3394+
emscripten_outn: function(str, len) {
3395+
out(UTF8ToString(str, len));
3396+
},
33943397

33953398
emscripten_err: function(str) {
33963399
err(UTF8ToString(str));
33973400
},
3401+
emscripten_errn: function(str, len) {
3402+
err(UTF8ToString(str, len));
3403+
},
33983404

33993405
#if ASSERTIONS || RUNTIME_DEBUG
34003406
emscripten_dbg: function(str) {
34013407
dbg(UTF8ToString(str));
34023408
},
3409+
emscripten_dbgn: function(str, len) {
3410+
dbg(UTF8ToString(str, len));
3411+
},
34033412
#endif
34043413

34053414
// Use program_invocation_short_name and program_invocation_name in compiled

src/library_sigs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,15 @@ sigs = {
588588
emscripten_current_thread_is_wasm_worker__sig: 'i',
589589
emscripten_date_now__sig: 'd',
590590
emscripten_dbg__sig: 'vp',
591+
emscripten_dbgn__sig: 'vpp',
591592
emscripten_debugger__sig: 'v',
592593
emscripten_destroy_audio_context__sig: 'vi',
593594
emscripten_destroy_web_audio_node__sig: 'vi',
594595
emscripten_destroy_worker__sig: 'vi',
595596
emscripten_dlopen__sig: 'vpippp',
596597
emscripten_enter_soft_fullscreen__sig: 'ipp',
597598
emscripten_err__sig: 'vp',
599+
emscripten_errn__sig: 'vpp',
598600
emscripten_exit_fullscreen__sig: 'i',
599601
emscripten_exit_pointerlock__sig: 'i',
600602
emscripten_exit_soft_fullscreen__sig: 'i',
@@ -677,6 +679,7 @@ sigs = {
677679
emscripten_notify_memory_growth__sig: 'vp',
678680
emscripten_num_logical_cores__sig: 'i',
679681
emscripten_out__sig: 'vp',
682+
emscripten_outn__sig: 'vpp',
680683
emscripten_pause_main_loop__sig: 'v',
681684
emscripten_pc_get_column__sig: 'ip',
682685
emscripten_pc_get_file__sig: 'pp',

system/include/emscripten/console.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* found in the LICENSE file.
66
*/
77

8+
#include <stddef.h> // for size_t
9+
810
#ifdef __cplusplus
911
extern "C" {
1012
#endif
@@ -26,6 +28,12 @@ void emscripten_out(const char *utf8String __attribute__((nonnull)));
2628
void emscripten_err(const char *utf8String __attribute__((nonnull)));
2729
void emscripten_dbg(const char *utf8String __attribute__((nonnull)));
2830

31+
// Same as above but only with the legnth of string specified by the second
32+
// argument. This allows for non-NULL-terminated strings to be passed.
33+
void emscripten_outn(const char *utf8String __attribute__((nonnull)), size_t len);
34+
void emscripten_errn(const char *utf8String __attribute__((nonnull)), size_t len);
35+
void emscripten_dbgn(const char *utf8String __attribute__((nonnull)), size_t len);
36+
2937
// Legacy/internal names for the above
3038
#define _emscripten_out(x) emscripten_out(x)
3139
#define _emscripten_err(x) emscripten_err(x)

test/other/test_dbg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ int main() {
1313
#ifndef NDEBUG
1414
// This symbol is only available in debug builds (i.e. -sASSERTIONS)
1515
emscripten_dbg("native dbg message");
16+
emscripten_dbgn("hello world!", 5);
1617
emscripten_dbgf("formatted: %d", 42);
1718
#endif
1819
return 0;

test/test_other.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13158,6 +13158,7 @@ def test_dbg(self):
1315813158
w:0,t:0x[0-9a-fA-F]+: done init
1315913159
hello, world!
1316013160
w:0,t:0x[0-9a-fA-F]+: native dbg message
13161+
w:0,t:0x[0-9a-fA-F]+: hello
1316113162
w:0,t:0x[0-9a-fA-F]+: formatted: 42
1316213163
'''
1316313164
self.emcc_args.append('--pre-js=pre.js')

0 commit comments

Comments
 (0)