Przeglądaj źródła

Make libc-builtin buffered printf be a common feature (#1483)

Add macros to control whether to use the libc-builtin buffered printf
and the buffer size.
Huang Qi 3 lat temu
rodzic
commit
bbea005db6

+ 18 - 3
core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c

@@ -345,9 +345,24 @@ sprintf_out(int c, struct str_context *ctx)
     return c;
 }
 
-#ifdef BH_PLATFORM_OPENRTOS
-PRIVILEGED_DATA static char print_buf[128] = { 0 };
-PRIVILEGED_DATA static int print_buf_size = 0;
+#ifndef BUILTIN_LIBC_BUFFERED_PRINTF
+#define BUILTIN_LIBC_BUFFERED_PRINTF 0
+#endif
+
+#ifndef BUILTIN_LIBC_BUFFERED_PRINT_SIZE
+#define BUILTIN_LIBC_BUFFERED_PRINT_SIZE 128
+#endif
+#ifndef BUILTIN_LIBC_BUFFERED_PRINT_PREFIX
+#define BUILTIN_LIBC_BUFFERED_PRINT_PREFIX
+#endif
+
+#if BUILTIN_LIBC_BUFFERED_PRINTF != 0
+
+BUILTIN_LIBC_BUFFERED_PRINT_PREFIX
+static char print_buf[BUILTIN_LIBC_BUFFERED_PRINT_SIZE] = { 0 };
+
+BUILTIN_LIBC_BUFFERED_PRINT_PREFIX
+static int print_buf_size = 0;
 
 static int
 printf_out(int c, struct str_context *ctx)

+ 4 - 0
core/shared/platform/nuttx/platform_internal.h

@@ -77,6 +77,10 @@ typedef sem_t korp_sem;
 #define CONFIG_HAS_ISATTY 0
 #endif
 
+#define BUILTIN_LIBC_BUFFERED_PRINTF 1
+#define BUILTIN_LIBC_BUFFERED_PRINT_SIZE 128
+#define BUILTIN_LIBC_BUFFERED_PRINT_PREFIX
+
 /*
  * NuttX doesn't have openat family.
  */