From adcc4d1f7ba68fbb8b9c8ded9f87d5d382b1b326 Mon Sep 17 00:00:00 2001 From: "tree-sitter-ci-bot[bot]" <180118140+tree-sitter-ci-bot[bot]@users.noreply.github.com> Date: Tue, 6 Jan 2026 12:27:26 +0100 Subject: [PATCH] fix(wasm): add common definitions to stdlib (#5199) (#5208) Also expose `strlen` through `string.h` instead of `stdio.h`. (cherry picked from commit f4ca3d95ca45f71116820a499ea3c199dfe981ea) Co-authored-by: Trim21 --- crates/language/wasm/include/stdint.h | 8 +++++++- crates/language/wasm/include/string.h | 2 ++ crates/language/wasm/src/stdio.c | 7 +------ crates/language/wasm/src/string.c | 6 ++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/language/wasm/include/stdint.h b/crates/language/wasm/include/stdint.h index 5f7cb264..10cc35dc 100644 --- a/crates/language/wasm/include/stdint.h +++ b/crates/language/wasm/include/stdint.h @@ -23,9 +23,15 @@ typedef long unsigned int size_t; typedef long unsigned int uintptr_t; -#define UINT16_MAX 65535 +#define INT8_MAX 127 +#define INT16_MAX 32767 +#define INT32_MAX 2147483647L +#define INT64_MAX 9223372036854775807LL +#define UINT8_MAX 255 +#define UINT16_MAX 65535 #define UINT32_MAX 4294967295U +#define UINT64_MAX 18446744073709551615ULL #if defined(__wasm32__) diff --git a/crates/language/wasm/include/string.h b/crates/language/wasm/include/string.h index 2d576f08..10f11958 100644 --- a/crates/language/wasm/include/string.h +++ b/crates/language/wasm/include/string.h @@ -13,4 +13,6 @@ void *memset(void *dst, int value, size_t count); int strncmp(const char *left, const char *right, size_t n); +size_t strlen(const char *str); + #endif // TREE_SITTER_WASM_STRING_H_ diff --git a/crates/language/wasm/src/stdio.c b/crates/language/wasm/src/stdio.c index 3432699a..470c1ecc 100644 --- a/crates/language/wasm/src/stdio.c +++ b/crates/language/wasm/src/stdio.c @@ -1,4 +1,5 @@ #include +#include typedef struct { bool left_justify; // - @@ -105,12 +106,6 @@ static int ptr_to_str(void *ptr, char *buffer) { return 2 + len; } -size_t strlen(const char *str) { - const char *s = str; - while (*s) s++; - return s - str; -} - char *strncpy(char *dest, const char *src, size_t n) { char *d = dest; const char *s = src; diff --git a/crates/language/wasm/src/string.c b/crates/language/wasm/src/string.c index 0fcf4b85..2d0d9096 100644 --- a/crates/language/wasm/src/string.c +++ b/crates/language/wasm/src/string.c @@ -58,3 +58,9 @@ int strncmp(const char *left, const char *right, size_t n) { } return 0; } + +size_t strlen(const char *str) { + const char *s = str; + while (*s) s++; + return s - str; +}