Skip to content

Commit 8493ffa

Browse files
authored
Add vprintf override for android and esp-idf (#3174)
And update document.
1 parent 0fa0beb commit 8493ffa

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

core/shared/platform/android/platform_init.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ bh_platform_destroy()
2424
int
2525
os_printf(const char *fmt, ...)
2626
{
27-
int ret;
27+
int ret = 0;
2828
va_list ap;
2929

3030
va_start(ap, fmt);
31-
ret = __android_log_vprint(ANDROID_LOG_INFO, "wasm_runtime::", fmt, ap);
31+
#ifndef BH_VPRINTF
32+
ret += __android_log_vprint(ANDROID_LOG_INFO, "wasm_runtime::", fmt, ap);
33+
#else
34+
ret += BH_VPRINTF(fmt, ap);
35+
#endif
3236
va_end(ap);
3337

3438
return ret;
@@ -37,7 +41,11 @@ os_printf(const char *fmt, ...)
3741
int
3842
os_vprintf(const char *fmt, va_list ap)
3943
{
44+
#ifndef BH_VPRINTF
4045
return __android_log_vprint(ANDROID_LOG_INFO, "wasm_runtime::", fmt, ap);
46+
#else
47+
return BH_VPRINTF(fmt, ap);
48+
#endif
4149
}
4250

4351
#if __ANDROID_API__ < 19

core/shared/platform/esp-idf/espidf_platform.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ os_printf(const char *format, ...)
2323
va_list ap;
2424

2525
va_start(ap, format);
26+
#ifndef BH_VPRINTF
2627
ret += vprintf(format, ap);
28+
#else
29+
ret += BH_VPRINTF(format, ap);
30+
#endif
2731
va_end(ap);
2832

2933
return ret;
@@ -32,7 +36,11 @@ os_printf(const char *format, ...)
3236
int
3337
os_vprintf(const char *format, va_list ap)
3438
{
39+
#ifndef BH_VPRINTF
3540
return vprintf(format, ap);
41+
#else
42+
return BH_VPRINTF(format, ap);
43+
#endif
3644
}
3745

3846
uint64

doc/build_wamr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Currently we only profile the memory consumption of module, module_instance and
176176
177177
#### **Set vprintf callback**
178178
- **WAMR_BH_VPRINTF**=<vprintf_callback>, default to disable if not set
179-
> Note: if the vprintf_callback function is provided by developer, the os_printf() and os_vprintf() in Linux, Darwin, Windows and VxWorks platforms, besides WASI Libc output will call the callback function instead of libc vprintf() function to redirect the stdout output. For example, developer can define the callback function like below outside runtime lib:
179+
> Note: if the vprintf_callback function is provided by developer, the os_printf() and os_vprintf() in Linux, Darwin, Windows, VxWorks, Android and esp-idf platforms, besides WASI Libc output will call the callback function instead of libc vprintf() function to redirect the stdout output. For example, developer can define the callback function like below outside runtime lib:
180180
>
181181
> ```C
182182
> int my_vprintf(const char *format, va_list ap)

0 commit comments

Comments
 (0)