From 24daa4427c75ea0f2ea0c7706b20849ac297c6fc Mon Sep 17 00:00:00 2001 From: Harold Brenes Date: Mon, 29 Sep 2025 19:54:53 -0400 Subject: [PATCH] Fix various foreign signatures --- core/c/libc/stdio.odin | 2 +- core/sys/darwin/CoreFoundation/CFString.odin | 6 ++++-- core/sys/posix/arpa_inet.odin | 1 - core/sys/posix/pthread.odin | 4 ++-- core/sys/posix/sys_mman.odin | 7 ++++++- src/check_decl.cpp | 6 ++++++ 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/core/c/libc/stdio.odin b/core/c/libc/stdio.odin index 854a98637..aa92e4a6b 100644 --- a/core/c/libc/stdio.odin +++ b/core/c/libc/stdio.odin @@ -275,7 +275,7 @@ foreign libc { // 7.21.7 Character input/output functions fgetc :: proc(stream: ^FILE) -> int --- fgets :: proc(s: [^]char, n: int, stream: ^FILE) -> [^]char --- - fputc :: proc(s: cstring, stream: ^FILE) -> int --- + fputc :: proc(s: c.int, stream: ^FILE) -> int --- getc :: proc(stream: ^FILE) -> int --- getchar :: proc() -> int --- putc :: proc(c: int, stream: ^FILE) -> int --- diff --git a/core/sys/darwin/CoreFoundation/CFString.odin b/core/sys/darwin/CoreFoundation/CFString.odin index 24485a494..d245ba793 100644 --- a/core/sys/darwin/CoreFoundation/CFString.odin +++ b/core/sys/darwin/CoreFoundation/CFString.odin @@ -1,10 +1,12 @@ package CoreFoundation +import "core:c" + foreign import CoreFoundation "system:CoreFoundation.framework" String :: distinct TypeRef // same as CFStringRef -StringEncoding :: distinct u32 +StringEncoding :: distinct c.long StringBuiltInEncodings :: enum StringEncoding { MacRoman = 0, @@ -171,7 +173,7 @@ foreign CoreFoundation { // Fetches a range of the characters from a string into a byte buffer after converting the characters to a specified encoding. StringGetBytes :: proc(thestring: String, range: Range, encoding: StringEncoding, lossByte: u8, isExternalRepresentation: b8, buffer: [^]byte, maxBufLen: Index, usedBufLen: ^Index) -> Index --- - StringIsEncodingAvailable :: proc(encoding: StringEncoding) -> bool --- + StringIsEncodingAvailable :: proc(encoding: StringEncoding) -> b8 --- @(link_name = "__CFStringMakeConstantString") StringMakeConstantString :: proc "c" (#const c: cstring) -> String --- diff --git a/core/sys/posix/arpa_inet.odin b/core/sys/posix/arpa_inet.odin index 6edb9e535..70b12678c 100644 --- a/core/sys/posix/arpa_inet.odin +++ b/core/sys/posix/arpa_inet.odin @@ -50,7 +50,6 @@ foreign lib { af: AF, // INET or INET6 src: cstring, dst: rawptr, // either ^in_addr or ^in_addr6 - size: socklen_t, // size_of(dst^) ) -> pton_result --- } diff --git a/core/sys/posix/pthread.odin b/core/sys/posix/pthread.odin index c7255baa3..733725e2c 100644 --- a/core/sys/posix/pthread.odin +++ b/core/sys/posix/pthread.odin @@ -124,7 +124,7 @@ foreign lib { [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getscope.html ]] */ - pthread_attr_setscope :: proc(attr: ^pthread_attr_t, contentionscope: ^Thread_Scope) -> Errno --- + pthread_attr_setscope :: proc(attr: ^pthread_attr_t, contentionscope: Thread_Scope) -> Errno --- /* Get the area of storage to be used for the created thread's stack. @@ -400,7 +400,7 @@ when ODIN_OS == .Darwin { PTHREAD_SCOPE_PROCESS :: 2 PTHREAD_SCOPE_SYSTEM :: 1 - pthread_t :: distinct u64 + pthread_t :: distinct rawptr pthread_attr_t :: struct { __sig: c.long, diff --git a/core/sys/posix/sys_mman.odin b/core/sys/posix/sys_mman.odin index 2d51083dc..1bf3615dc 100644 --- a/core/sys/posix/sys_mman.odin +++ b/core/sys/posix/sys_mman.odin @@ -92,7 +92,12 @@ foreign lib { [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/shm_open.html ]] */ - shm_open :: proc(name: cstring, oflag: O_Flags, mode: mode_t) -> FD --- + when ODIN_OS == .Darwin { + // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/shm_open.2.html + shm_open :: proc(name: cstring, oflag: O_Flags, #c_vararg args: ..any) -> FD --- + } else { + shm_open :: proc(name: cstring, oflag: O_Flags, mode: mode_t) -> FD --- + } /* Removes a shared memory object. diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 842f8653c..f7df73953 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -851,6 +851,12 @@ gb_internal bool signature_parameter_similar_enough(Type *x, Type *y) { } } + Type *x_base = base_type(x); + Type *y_base = base_type(y); + if (x_base->kind == y_base->kind && x_base->kind == Type_Struct) { + return type_size_of(x_base) == type_size_of(y_base) && type_align_of(x_base) == type_align_of(y_base); + } + return are_types_identical(x, y); }