From ac711b7ede5a2c5aa1d9bcf72d6440c4299382d1 Mon Sep 17 00:00:00 2001 From: Jonas Meeuws Date: Sat, 4 Jan 2025 15:46:48 +0100 Subject: [PATCH] Use selective imports for core.sys.darwin,solaris --- druntime/src/core/sync/semaphore.d | 9 ++++----- druntime/src/core/thread/osthread.d | 11 +++++++---- druntime/src/core/time.d | 2 +- druntime/src/rt/sections_darwin_64.d | 11 ++++++++--- druntime/src/rt/sections_osx_x86.d | 17 +++++++++++------ druntime/src/rt/sections_osx_x86_64.d | 11 ++++++----- druntime/test/shared/src/load.d | 9 +-------- druntime/test/thread/src/external_threads.d | 3 ++- druntime/test/thread/src/fiber_guard_page.d | 2 +- 9 files changed, 41 insertions(+), 34 deletions(-) diff --git a/druntime/src/core/sync/semaphore.d b/druntime/src/core/sync/semaphore.d index 80d036f2836d..a4dae042ee3b 100644 --- a/druntime/src/core/sync/semaphore.d +++ b/druntime/src/core/sync/semaphore.d @@ -39,15 +39,16 @@ else version (Darwin) { import core.stdc.errno; import core.sync.config; - import core.sys.darwin.mach.semaphore; - import core.sys.posix.time; + import core.sys.darwin.mach.kern_return : KERN_ABORTED, KERN_OPERATION_TIMED_OUT; + import core.sys.darwin.mach.semaphore : mach_task_self, mach_timespec_t, semaphore_create, semaphore_destroy, + semaphore_signal, semaphore_t, semaphore_timedwait, semaphore_wait, SYNC_POLICY_FIFO; } else version (Posix) { import core.stdc.errno; import core.sync.config; import core.sys.posix.semaphore : sem_destroy, sem_init, sem_post, sem_t, sem_timedwait, sem_trywait, sem_wait; - import core.sys.posix.time : timespec; + import core.sys.posix.time : clock_gettime, CLOCK_REALTIME, timespec; } else { @@ -253,8 +254,6 @@ class Semaphore } else version (Posix) { - import core.sys.posix.time : clock_gettime, CLOCK_REALTIME; - timespec t = void; clock_gettime( CLOCK_REALTIME, &t ); mvtspec( t, period ); diff --git a/druntime/src/core/thread/osthread.d b/druntime/src/core/thread/osthread.d index e2a53b1103fa..504b083f475b 100644 --- a/druntime/src/core/thread/osthread.d +++ b/druntime/src/core/thread/osthread.d @@ -105,7 +105,10 @@ else version (Posix) version (Darwin) { - import core.sys.darwin.mach.thread_act; + import core.sys.darwin.mach.kern_return : KERN_SUCCESS; + import core.sys.darwin.mach.port : mach_port_t; + import core.sys.darwin.mach.thread_act : mach_msg_type_number_t, thread_get_state, thread_resume, + thread_suspend, x86_THREAD_STATE64, x86_THREAD_STATE64_COUNT, x86_thread_state64_t; import core.sys.darwin.pthread : pthread_mach_thread_np; } } @@ -113,8 +116,8 @@ else version (Posix) version (Solaris) { import core.sys.posix.sys.wait : idtype_t; - import core.sys.solaris.sys.priocntl; - import core.sys.solaris.sys.types; + import core.sys.solaris.sys.priocntl : PC_CLNULL, PC_GETCLINFO, PC_GETPARMS, PC_SETPARMS, pcinfo_t, pcparms_t, priocntl; + import core.sys.solaris.sys.types : P_MYID, pri_t; } version (GNU) @@ -1426,7 +1429,7 @@ private extern(D) void* getStackBottom() nothrow @nogc } else version (Darwin) { - import core.sys.darwin.pthread; + import core.sys.darwin.pthread : pthread_get_stackaddr_np; return pthread_get_stackaddr_np(pthread_self()); } else version (PThread_Getattr_NP) diff --git a/druntime/src/core/time.d b/druntime/src/core/time.d index 1c1d99641d8e..79dfee7cb3c9 100644 --- a/druntime/src/core/time.d +++ b/druntime/src/core/time.d @@ -100,7 +100,7 @@ else version (Posix) version (Darwin) { -public import core.sys.darwin.mach.kern_return; +import core.sys.darwin.mach.kern_return : kern_return_t; extern(C) nothrow @nogc { diff --git a/druntime/src/rt/sections_darwin_64.d b/druntime/src/rt/sections_darwin_64.d index 825f92dae52c..12395a28dcb0 100644 --- a/druntime/src/rt/sections_darwin_64.d +++ b/druntime/src/rt/sections_darwin_64.d @@ -23,9 +23,14 @@ else version (WatchOS) version (Darwin): version (D_LP64): -import core.sys.darwin.mach.dyld; -import core.sys.darwin.mach.getsect; -import core.sys.posix.pthread; +import core.stdc.stdint : intptr_t, uintptr_t; +import core.sys.darwin.mach.dyld : _dyld_get_image_header, _dyld_image_count; +import core.sys.darwin.mach.getsect : getsectbynamefromheader_64, section_64; +import core.sys.darwin.mach.loader : LC_SEGMENT_64, load_command, mach_header, mach_header_64, MH_MAGIC_64, + S_THREAD_LOCAL_VARIABLES, SECT_BSS, SECT_COMMON, SECT_DATA, SECTION_TYPE, SEG_DATA, segment_command_64, + tlv_descriptor; +import core.sys.posix.pthread : pthread_getspecific; +import core.sys.posix.sys.types : pthread_key_t; import rt.util.utility : safeAssert; diff --git a/druntime/src/rt/sections_osx_x86.d b/druntime/src/rt/sections_osx_x86.d index 232f8ebd71c3..c2a6fee55631 100644 --- a/druntime/src/rt/sections_osx_x86.d +++ b/druntime/src/rt/sections_osx_x86.d @@ -24,13 +24,18 @@ version (Darwin): version (X86): // debug = PRINTF; -import core.stdc.stdio; -import core.stdc.string, core.stdc.stdlib; -import core.sys.posix.pthread; -import core.sys.darwin.mach.dyld; -import core.sys.darwin.mach.getsect; -import rt.deh, rt.minfo; import core.internal.container.array; +import core.stdc.stdint : intptr_t; +import core.stdc.stdio; +import core.stdc.stdlib; +import core.stdc.string; +import core.sys.darwin.mach.dyld : _dyld_register_func_for_add_image; +import core.sys.darwin.mach.getsect : getsectbynamefromheader; +import core.sys.darwin.mach.loader : mach_header, MH_MAGIC, SECT_BSS, SECT_COMMON, SECT_DATA, SEG_DATA; +import core.sys.posix.pthread : pthread_getspecific, pthread_key_create, pthread_key_delete, pthread_key_t, + pthread_setspecific; +import rt.deh; +import rt.minfo; struct SectionGroup { diff --git a/druntime/src/rt/sections_osx_x86_64.d b/druntime/src/rt/sections_osx_x86_64.d index a6ce6b688b46..2e321929bf04 100644 --- a/druntime/src/rt/sections_osx_x86_64.d +++ b/druntime/src/rt/sections_osx_x86_64.d @@ -25,15 +25,16 @@ version (X86_64): // debug = PRINTF; import core.stdc.stdio; -import core.stdc.string, core.stdc.stdlib; -import core.sys.posix.pthread; -import core.sys.darwin.mach.dyld; -import core.sys.darwin.mach.getsect; +import core.stdc.stdlib; +import core.stdc.string; +import core.stdc.stdint : intptr_t; +import core.sys.darwin.mach.dyld : _dyld_register_func_for_add_image; +import core.sys.darwin.mach.getsect : mach_header; +import core.internal.container.array; import rt.deh; import rt.minfo; import rt.sections_darwin_64; -import core.internal.container.array; import rt.util.utility : safeAssert; struct SectionGroup diff --git a/druntime/test/shared/src/load.d b/druntime/test/shared/src/load.d index 3322718d1d12..530f7434ad0a 100644 --- a/druntime/test/shared/src/load.d +++ b/druntime/test/shared/src/load.d @@ -3,13 +3,6 @@ import core.stdc.stdio; import core.stdc.string; import core.thread; -version (DragonFlyBSD) import core.sys.dragonflybsd.dlfcn : RTLD_NOLOAD; -version (FreeBSD) import core.sys.freebsd.dlfcn : RTLD_NOLOAD; -version (linux) import core.sys.linux.dlfcn : RTLD_NOLOAD; -version (NetBSD) import core.sys.netbsd.dlfcn : RTLD_NOLOAD; -version (OSX) import core.sys.darwin.dlfcn : RTLD_NOLOAD; -version (Solaris) import core.sys.solaris.dlfcn : RTLD_NOLOAD; - void* openLib(string s) { auto h = Runtime.loadLibrary(s); @@ -145,7 +138,7 @@ void main(string[] args) } else { - import core.sys.posix.dlfcn; + import core.sys.posix.dlfcn : dlopen, RTLD_LAZY, RTLD_NOLOAD; assert(dlopen(name.ptr, RTLD_LAZY | RTLD_NOLOAD) is null); } name = name[0 .. $-1]; diff --git a/druntime/test/thread/src/external_threads.d b/druntime/test/thread/src/external_threads.d index 9c98a3fa13d1..a59fc76dbb98 100644 --- a/druntime/test/thread/src/external_threads.d +++ b/druntime/test/thread/src/external_threads.d @@ -1,5 +1,6 @@ -import core.sys.posix.pthread; import core.memory; +import core.sys.posix.pthread : pthread_create, pthread_join; +import core.sys.posix.sys.types : pthread_t; import core.thread; extern (C) void rt_moduleTlsCtor(); diff --git a/druntime/test/thread/src/fiber_guard_page.d b/druntime/test/thread/src/fiber_guard_page.d index f19ddae7c32a..6527a590ccf0 100644 --- a/druntime/test/thread/src/fiber_guard_page.d +++ b/druntime/test/thread/src/fiber_guard_page.d @@ -1,5 +1,5 @@ +import core.sys.posix.sys.mman : MAP_ANON, MAP_PRIVATE, mmap, PROT_READ, PROT_WRITE; import core.thread; -import core.sys.posix.sys.mman; version (LDC) import ldc.attributes; else struct optStrategy { string a; }