From 1ae57d8d20cc0c04a26ee34285540160dd58a8b6 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 22 Sep 2024 13:32:28 +0100 Subject: [PATCH] Fix more JS stuff --- core/c/libc/stdio.odin | 26 +++++++++++++++++++++++++- core/c/libc/stdlib.odin | 10 ++++++++++ core/c/libc/wctype.odin | 2 +- vendor/stb/image/stb_image.odin | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/core/c/libc/stdio.odin b/core/c/libc/stdio.odin index f02453bba..a94a53696 100644 --- a/core/c/libc/stdio.odin +++ b/core/c/libc/stdio.odin @@ -59,7 +59,7 @@ when ODIN_OS == .Windows { } // GLIBC and MUSL compatible. -when ODIN_OS == .Linux || ODIN_OS == .JS { +when ODIN_OS == .Linux { fpos_t :: struct #raw_union { _: [16]char, _: longlong, _: double, } _IOFBF :: 0 @@ -89,6 +89,30 @@ when ODIN_OS == .Linux || ODIN_OS == .JS { } } +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/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 diff --git a/vendor/stb/image/stb_image.odin b/vendor/stb/image/stb_image.odin index 0151899d9..0c2ad7d05 100644 --- a/vendor/stb/image/stb_image.odin +++ b/vendor/stb/image/stb_image.odin @@ -1,6 +1,6 @@ package stb_image -import "core:c" +import c "core:c/libc" @(private) LIB :: (