Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use selective imports when importing platform-specific modules (core.sys) #20632

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions druntime/src/core/internal/atomic.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

module core.internal.atomic;

import core.atomic : MemoryOrder, has128BitCAS;
import core.atomic : has128BitCAS, MemoryOrder;

version (DigitalMars)
{
Expand Down Expand Up @@ -912,7 +912,7 @@ else version (GNU)
{
static if (GNU_Thread_Model == ThreadModel.Posix)
{
import core.sys.posix.pthread;
import core.sys.posix.sys.types : pthread_mutex_t, pthread_mutexattr_t;
alias atomicMutexHandle = pthread_mutex_t;

pragma(mangle, "pthread_mutex_init") int fakePureMutexInit(pthread_mutex_t*, pthread_mutexattr_t*);
Expand All @@ -921,7 +921,7 @@ else version (GNU)
}
else static if (GNU_Thread_Model == ThreadModel.Win32)
{
import core.sys.windows.winbase;
import core.sys.windows.winbase : CRITICAL_SECTION;
alias atomicMutexHandle = CRITICAL_SECTION;

pragma(mangle, "InitializeCriticalSection") int fakePureMutexInit(CRITICAL_SECTION*);
Expand Down
10 changes: 5 additions & 5 deletions druntime/src/core/internal/backtrace/elf.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ module core.internal.backtrace.elf;

version (linux)
{
import core.sys.linux.elf;
import core.sys.linux.elf : SHF_COMPRESSED, ET_DYN;
version = LinuxOrBSD;
}
else version (FreeBSD)
{
import core.sys.freebsd.sys.elf;
import core.sys.freebsd.sys.elf : SHF_COMPRESSED, ET_DYN;
version = LinuxOrBSD;
}
else version (DragonFlyBSD)
{
import core.sys.dragonflybsd.sys.elf;
import core.sys.dragonflybsd.sys.elf : SHF_COMPRESSED, ET_DYN;
version = LinuxOrBSD;
}
else version (OpenBSD)
{
import core.sys.openbsd.sys.elf;
import core.sys.openbsd.sys.elf : SHF_COMPRESSED, ET_DYN;
version = LinuxOrBSD;
}
else version (Solaris)
{
import core.sys.solaris.sys.elf;
import core.sys.solaris.sys.elf : SHF_COMPRESSED, ET_DYN;
version = LinuxOrBSD;
}

Expand Down
2 changes: 1 addition & 1 deletion druntime/src/core/internal/backtrace/handler.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ version (DRuntime_Use_Libunwind):
import core.internal.backtrace.dwarf;
import core.internal.backtrace.libunwind;
import core.stdc.string;
import core.sys.posix.dlfcn;
import core.sys.posix.dlfcn : Dl_info, dladdr;

/// Ditto
class LibunwindHandler : Throwable.TraceInfo
Expand Down
5 changes: 2 additions & 3 deletions druntime/src/core/internal/backtrace/macho.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ else version (WatchOS)
version (Darwin):

import core.stdc.config : c_ulong;
import core.sys.darwin.crt_externs;
import core.sys.darwin.mach.getsect;
import core.sys.darwin.mach.loader;
import core.sys.darwin.crt_externs : _NSGetMachExecuteHeader;
import core.sys.darwin.mach.getsect : mach_header_64, getsectiondata;

struct Image
{
Expand Down
18 changes: 10 additions & 8 deletions druntime/src/core/internal/elf/dl.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ module core.internal.elf.dl;

version (linux)
{
import core.sys.linux.link;
import core.sys.linux.link : dl_iterate_phdr, dl_phdr_info, ElfW;
version = LinuxOrBSD;
}
else version (FreeBSD)
{
import core.sys.freebsd.sys.link_elf;
import core.sys.freebsd.sys.link_elf : _rtld_addr_phdr, dl_iterate_phdr, dl_phdr_info, ElfW;
version = LinuxOrBSD;
}
else version (DragonFlyBSD)
{
import core.sys.dragonflybsd.sys.link_elf;
import core.sys.dragonflybsd.sys.link_elf : _rtld_addr_phdr, dl_iterate_phdr, dl_phdr_info, ElfW;
version = LinuxOrBSD;
}
else version (NetBSD)
{
import core.sys.netbsd.sys.link_elf;
import core.sys.netbsd.sys.link_elf : dl_iterate_phdr, dl_phdr_info, ElfW;
version = LinuxOrBSD;
}
else version (OpenBSD)
{
import core.sys.openbsd.sys.link_elf;
import core.sys.openbsd.sys.link_elf : dl_iterate_phdr, dl_phdr_info, ElfW;
version = LinuxOrBSD;
}
else version (Solaris)
{
import core.sys.solaris.link;
import core.sys.solaris.link : dl_iterate_phdr, dl_phdr_info, ElfW;
version = LinuxOrBSD;
}

Expand Down Expand Up @@ -146,7 +146,9 @@ struct SharedObject
char[] getPath(size_t N)(ref char[N] buffer) const
if (N > 1)
{
import core.stdc.stdio, core.stdc.string, core.sys.posix.unistd;
import core.stdc.stdio;
import core.stdc.string;
import core.sys.posix.unistd : getpid;

char[N + 128] lineBuffer = void;

Expand Down Expand Up @@ -219,7 +221,7 @@ version (Linux_Use_GNU)
{
const(char)* getprogname()
{
import core.sys.linux.errno;
import core.sys.linux.errno : program_invocation_name;
return program_invocation_name;
}
}
Expand Down
32 changes: 15 additions & 17 deletions druntime/src/core/internal/elf/io.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ module core.internal.elf.io;

version (Posix):

import core.memory : pageSize;
import core.lifetime : move;
import core.stdc.stdlib : malloc, free;
import core.sys.posix.fcntl;
import core.sys.posix.sys.mman;
import core.sys.posix.unistd;
import core.memory : pageSize;
import core.stdc.stdlib : free, malloc;
import core.sys.posix.fcntl : O_RDONLY, open;
import core.sys.posix.sys.mman : MAP_FAILED, MAP_PRIVATE, mmap, munmap, PROT_READ;
import core.sys.posix.unistd : close, lseek, readlink;

version (linux)
{
import core.sys.linux.link;
import core.sys.linux.link : ElfW;
version = LinuxOrBSD;
}
else version (FreeBSD)
{
import core.sys.freebsd.sys.link_elf;
import core.sys.freebsd.sys.link_elf : ElfW;
version = LinuxOrBSD;
}
else version (DragonFlyBSD)
{
import core.sys.dragonflybsd.sys.link_elf;
import core.sys.dragonflybsd.sys.link_elf : ElfW;
version = LinuxOrBSD;
}
else version (NetBSD)
{
import core.sys.netbsd.sys.link_elf;
import core.sys.netbsd.sys.link_elf : ElfW;
version = LinuxOrBSD;
}
else version (OpenBSD)
{
import core.sys.openbsd.sys.link_elf;
import core.sys.openbsd.sys.link_elf : ElfW;
version = LinuxOrBSD;
}
else version (Solaris)
{
import core.sys.solaris.link;
import core.sys.solaris.link : ElfW;
version = LinuxOrBSD;
}

Expand Down Expand Up @@ -374,9 +374,6 @@ private struct MMapRegion

@nogc nothrow:

version (OpenBSD)
private extern(C) const(char)* getprogname();

/// Returns the path to the process' executable as newly allocated C string
/// (free() when done), or null on error.
version (LinuxOrBSD)
Expand All @@ -403,23 +400,24 @@ char* thisExePath()
{
// there's apparently no proper way :/
import core.stdc.string : strdup;
import core.sys.openbsd.stdlib : getprogname;
return strdup(getprogname());
}
else
{
version (DragonFlyBSD)
{
import core.sys.dragonflybsd.sys.sysctl : sysctl, CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME;
import core.sys.dragonflybsd.sys.sysctl : CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, sysctl;
int[4] mib = [CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1];
}
else version (FreeBSD)
{
import core.sys.freebsd.sys.sysctl : sysctl, CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME;
import core.sys.freebsd.sys.sysctl : CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, sysctl;
int[4] mib = [CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1];
}
else version (NetBSD)
{
import core.sys.netbsd.sys.sysctl : sysctl, CTL_KERN, KERN_PROC_ARGS, KERN_PROC_PATHNAME;
import core.sys.netbsd.sys.sysctl : CTL_KERN, KERN_PROC_ARGS, KERN_PROC_PATHNAME, sysctl;
int[4] mib = [CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME];
}
else
Expand Down
18 changes: 9 additions & 9 deletions druntime/src/core/internal/execinfo.d
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ else version (ExtExecinfo_SolarisFmt)
version (linux)
{
version (CRuntime_Glibc)
import _execinfo = core.sys.linux.execinfo;
import _execinfo = core.sys.linux.execinfo : backtrace, backtrace_symbols, backtrace_symbols_fd;
else version (CRuntime_UClibc)
import _execinfo = core.sys.linux.execinfo;
import _execinfo = core.sys.linux.execinfo : backtrace, backtrace_symbols, backtrace_symbols_fd;
else version (_extExecinfo)
import _execinfo = core.sys.linux.execinfo;
import _execinfo = core.sys.linux.execinfo : backtrace, backtrace_symbols, backtrace_symbols_fd;
}
else version (Darwin)
import _execinfo = core.sys.darwin.execinfo;
import _execinfo = core.sys.darwin.execinfo : backtrace, backtrace_symbols, backtrace_symbols_fd;
else version (FreeBSD)
import _execinfo = core.sys.freebsd.execinfo;
import _execinfo = core.sys.freebsd.execinfo : backtrace, backtrace_symbols, backtrace_symbols_fd;
else version (NetBSD)
import _execinfo = core.sys.netbsd.execinfo;
import _execinfo = core.sys.netbsd.execinfo : backtrace, backtrace_symbols, backtrace_symbols_fd;
else version (OpenBSD)
import _execinfo = core.sys.openbsd.execinfo;
import _execinfo = core.sys.openbsd.execinfo : backtrace, backtrace_symbols, backtrace_symbols_fd;
else version (DragonFlyBSD)
import _execinfo = core.sys.dragonflybsd.execinfo;
import _execinfo = core.sys.dragonflybsd.execinfo : backtrace, backtrace_symbols, backtrace_symbols_fd;
else version (Solaris)
import _execinfo = core.sys.solaris.execinfo;
import _execinfo = core.sys.solaris.execinfo : backtrace, backtrace_symbols, backtrace_symbols_fd;

/// Indicates the availability of backtrace functions
enum bool hasExecinfo = is(_execinfo == module);
Expand Down
2 changes: 1 addition & 1 deletion druntime/src/core/internal/gc/impl/conservative/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -3575,7 +3575,7 @@ Lmark:

version (Posix)
{
import core.sys.posix.signal;
import core.sys.posix.signal : pthread_sigmask, SIG_BLOCK, SIG_SETMASK, sigfillset, sigset_t;
// block all signals, scanBackground inherits this mask.
// see https://issues.dlang.org/show_bug.cgi?id=20256
sigset_t new_mask, old_mask;
Expand Down
18 changes: 12 additions & 6 deletions druntime/src/core/internal/gc/os.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ else version (Posix)
else version (WatchOS)
version = Darwin;

import core.sys.posix.sys.mman;
import core.stdc.stdlib;
import core.sys.posix.sys.mman : MAP_ANON, MAP_FAILED, MAP_PRIVATE, MAP_SHARED, mmap, munmap, PROT_READ, PROT_WRITE;


/// Possible results for the wait_pid() function.
Expand Down Expand Up @@ -74,9 +74,9 @@ else version (Posix)
return ChildStatus.done;
}

public import core.sys.posix.unistd: pid_t, fork;
import core.sys.posix.sys.wait: waitpid, WNOHANG;
import core.stdc.errno: errno, EINTR, ECHILD;
public import core.sys.posix.unistd : fork, pid_t;
import core.stdc.errno : ECHILD, EINTR, errno;
import core.sys.posix.sys.wait : waitpid, WNOHANG;

//version = GC_Use_Alloc_MMap;
}
Expand Down Expand Up @@ -292,12 +292,18 @@ else version (Posix)
{
ulong os_physical_mem(bool avail) nothrow @nogc
{
import core.sys.posix.unistd;
static import core.sys.posix.unistd;
import core.sys.posix.unistd : _SC_PAGESIZE, _SC_PHYS_PAGES, sysconf;
const pageSize = sysconf(_SC_PAGESIZE);
static if (__traits(compiles, _SC_AVPHYS_PAGES)) // not available on all platforms
static if (__traits(compiles, core.sys.posix.unistd._SC_AVPHYS_PAGES)) // not available on all platforms
{
import core.sys.posix.unistd : _SC_AVPHYS_PAGES;
const sc = avail ? _SC_AVPHYS_PAGES : _SC_PHYS_PAGES;
}
else
{
const sc = _SC_PHYS_PAGES;
}
const pages = sysconf(sc);
return pageSize * pages;
}
Expand Down
2 changes: 1 addition & 1 deletion druntime/src/core/memory.d
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ extern (C) private @system @nogc nothrow
{
ref int fakePureErrnoImpl()
{
import core.stdc.errno;
import core.stdc.errno : errno;
return errno();
}
}
Expand Down
4 changes: 3 additions & 1 deletion druntime/src/core/runtime.d
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,9 @@ extern (C) UnitTestResult runModuleUnitTests()

static if (hasExecinfo)
{
import core.sys.posix.signal; // segv handler
// segv handler
import core.sys.posix.signal : SA_RESETHAND, SA_SIGINFO, sigaction, sigaction_t, SIGBUS, sigfillset, siginfo_t,
SIGSEGV;

static extern (C) void unittestSegvHandler( int signum, siginfo_t* info, void* ptr ) nothrow
{
Expand Down
17 changes: 11 additions & 6 deletions druntime/src/core/sync/condition.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ version (Windows)
}
else version (Posix)
{
import core.sync.config;
import core.stdc.errno;
import core.sys.posix.pthread;
import core.sys.posix.time;
import core.sync.config;
import core.sys.posix.pthread : pthread_cond_broadcast, pthread_cond_destroy, pthread_cond_init,
pthread_cond_signal, pthread_cond_t, pthread_cond_timedwait, pthread_cond_wait;
import core.sys.posix.time : timespec;
}
else
{
Expand Down Expand Up @@ -127,8 +128,12 @@ class Condition
{
m_assocMutex = m;
}
static if ( is( typeof( pthread_condattr_setclock ) ) )
static if ( is( typeof( imported!"core.sys.posix.pthread".pthread_condattr_setclock ) ) )
{
import core.sys.posix.pthread : pthread_condattr_destroy, pthread_condattr_init,
pthread_condattr_setclock;
import core.sys.posix.sys.types : pthread_condattr_t;
import core.sys.posix.time : CLOCK_MONOTONIC;
() @trusted
{
pthread_condattr_t attr = void;
Expand Down Expand Up @@ -620,9 +625,9 @@ private:

unittest
{
import core.thread;
import core.sync.mutex;
import core.sync.semaphore;
import core.thread;


void testNotify()
Expand Down Expand Up @@ -786,9 +791,9 @@ unittest

unittest
{
import core.thread;
import core.sync.mutex;
import core.sync.semaphore;
import core.thread;


void testNotify()
Expand Down
Loading
Loading