Skip to content

Commit

Permalink
Use selective imports for core.sys.darwin,solaris
Browse files Browse the repository at this point in the history
  • Loading branch information
Reavershark committed Jan 4, 2025
1 parent ce893be commit ac711b7
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 34 deletions.
9 changes: 4 additions & 5 deletions druntime/src/core/sync/semaphore.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 );
Expand Down
11 changes: 7 additions & 4 deletions druntime/src/core/thread/osthread.d
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,19 @@ 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;
}
}

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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion druntime/src/core/time.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
11 changes: 8 additions & 3 deletions druntime/src/rt/sections_darwin_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
17 changes: 11 additions & 6 deletions druntime/src/rt/sections_osx_x86.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
11 changes: 6 additions & 5 deletions druntime/src/rt/sections_osx_x86_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions druntime/test/shared/src/load.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion druntime/test/thread/src/external_threads.d
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion druntime/test/thread/src/fiber_guard_page.d
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down

0 comments on commit ac711b7

Please sign in to comment.