diff options
| author | Antonino Simone Di Stefano <simon.distefano@gmx.de> | 2024-09-22 23:32:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-22 23:32:22 +0200 |
| commit | e9e78630336e0f83ad4cb5ca74886dad8f08ffee (patch) | |
| tree | 906422a53e4ce1d2b68c3b48087c6c10b75be7d3 /core/c | |
| parent | 5bced00f5d37f9ac513c7ad7350e38aa4b58c85b (diff) | |
| parent | f7d74ff3a8596efef67d151ffb758ed085e94be0 (diff) | |
Merge branch 'odin-lang:master' into master
Diffstat (limited to 'core/c')
| -rw-r--r-- | core/c/libc/errno.odin | 8 | ||||
| -rw-r--r-- | core/c/libc/stdio.odin | 24 | ||||
| -rw-r--r-- | core/c/libc/stdlib.odin | 10 | ||||
| -rw-r--r-- | core/c/libc/string.odin | 1 | ||||
| -rw-r--r-- | core/c/libc/time.odin | 2 | ||||
| -rw-r--r-- | core/c/libc/wctype.odin | 2 |
6 files changed, 45 insertions, 2 deletions
diff --git a/core/c/libc/errno.odin b/core/c/libc/errno.odin index 843b2f1b6..de429a6ec 100644 --- a/core/c/libc/errno.odin +++ b/core/c/libc/errno.odin @@ -98,6 +98,14 @@ when ODIN_OS == .Haiku { ERANGE :: B_POSIX_ERROR_BASE + 17 } +when ODIN_OS == .JS { + _ :: libc + _get_errno :: proc "c" () -> ^int { + @(static) errno: int + return &errno + } +} + // Odin has no way to make an identifier "errno" behave as a function call to // read the value, or to produce an lvalue such that you can assign a different // error value to errno. To work around this, just expose it as a function like diff --git a/core/c/libc/stdio.odin b/core/c/libc/stdio.odin index 019389b0d..a94a53696 100644 --- a/core/c/libc/stdio.odin +++ b/core/c/libc/stdio.odin @@ -89,6 +89,30 @@ when ODIN_OS == .Linux { } } +when ODIN_OS == .JS { + fpos_t :: struct #raw_union { _: [16]char, _: longlong, _: double, } + + _IOFBF :: 0 + _IOLBF :: 1 + _IONBF :: 2 + + BUFSIZ :: 1024 + + EOF :: int(-1) + + FOPEN_MAX :: 1000 + + FILENAME_MAX :: 4096 + + L_tmpnam :: 20 + + SEEK_SET :: 0 + SEEK_CUR :: 1 + SEEK_END :: 2 + + TMP_MAX :: 308915776 +} + when ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD { fpos_t :: distinct i64 diff --git a/core/c/libc/stdlib.odin b/core/c/libc/stdlib.odin index 08c6fa6f0..98280e44b 100644 --- a/core/c/libc/stdlib.odin +++ b/core/c/libc/stdlib.odin @@ -10,6 +10,9 @@ when ODIN_OS == .Windows { foreign import libc "system:c" } +@(require) +import "base:runtime" + when ODIN_OS == .Windows { RAND_MAX :: 0x7fff @@ -145,6 +148,10 @@ aligned_alloc :: #force_inline proc "c" (alignment, size: size_t) -> rawptr { _aligned_malloc :: proc(size, alignment: size_t) -> rawptr --- } return _aligned_malloc(size=size, alignment=alignment) + } else when ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32 { + context = runtime.default_context() + data, _ := runtime.mem_alloc_bytes(auto_cast size, auto_cast alignment) + return raw_data(data) } else { foreign libc { aligned_alloc :: proc(alignment, size: size_t) -> rawptr --- @@ -160,6 +167,9 @@ aligned_free :: #force_inline proc "c" (ptr: rawptr) { _aligned_free :: proc(ptr: rawptr) --- } _aligned_free(ptr) + } else when ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32 { + context = runtime.default_context() + runtime.mem_free(ptr) } else { free(ptr) } diff --git a/core/c/libc/string.odin b/core/c/libc/string.odin index cde9c7e6b..4ec4f3a7a 100644 --- a/core/c/libc/string.odin +++ b/core/c/libc/string.odin @@ -12,6 +12,7 @@ when ODIN_OS == .Windows { foreign import libc "system:c" } +@(default_calling_convention="c") foreign libc { // 7.24.2 Copying functions memcpy :: proc(s1, s2: rawptr, n: size_t) -> rawptr --- diff --git a/core/c/libc/time.odin b/core/c/libc/time.odin index 48def707e..6828793ec 100644 --- a/core/c/libc/time.odin +++ b/core/c/libc/time.odin @@ -45,7 +45,7 @@ when ODIN_OS == .Windows { } } -when ODIN_OS == .Linux || ODIN_OS == .FreeBSD || ODIN_OS == .Darwin || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD || ODIN_OS == .Haiku { +when ODIN_OS == .Linux || ODIN_OS == .FreeBSD || ODIN_OS == .Darwin || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD || ODIN_OS == .Haiku || ODIN_OS == .JS { @(default_calling_convention="c") foreign libc { // 7.27.2 Time manipulation functions diff --git a/core/c/libc/wctype.odin b/core/c/libc/wctype.odin index a41fe7fac..b96410b4c 100644 --- a/core/c/libc/wctype.odin +++ b/core/c/libc/wctype.odin @@ -14,7 +14,7 @@ when ODIN_OS == .Windows { wctrans_t :: distinct wchar_t wctype_t :: distinct ushort -} else when ODIN_OS == .Linux { +} else when ODIN_OS == .Linux || ODIN_OS == .JS { wctrans_t :: distinct intptr_t wctype_t :: distinct ulong |