Commit eb5f748a by Iain Buclaw

libphobos: Merge upstream druntime 109f0f2e

Backports more extern(C) bindings and platform ports.

Reviewed-on: https://github.com/dlang/druntime/pull/2569

From-SVN: r270490
parent 16a51cf5
4b2674b36b1f6aac75db2a5aa38d67d4be55a987
109f0f2e11aaaddd2b158117928e10c3c4688870
The first line of this file holds the git revision number of the last
merge done from the dlang/druntime repository.
......@@ -464,10 +464,14 @@ extern (C) bool runModuleUnitTests()
import core.sys.freebsd.execinfo;
else version (NetBSD)
import core.sys.netbsd.execinfo;
else version (DragonFlyBSD)
import core.sys.dragonflybsd.execinfo;
else version (Windows)
import core.sys.windows.stacktrace;
else version (Solaris)
import core.sys.solaris.execinfo;
else version (CRuntime_UClibc)
import core.sys.linux.execinfo;
static if ( __traits( compiles, new LibBacktrace(0) ) )
{
......@@ -591,10 +595,14 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
import core.sys.freebsd.execinfo;
else version (NetBSD)
import core.sys.netbsd.execinfo;
else version (DragonFlyBSD)
import core.sys.dragonflybsd.execinfo;
else version (Windows)
import core.sys.windows.stacktrace;
else version (Solaris)
import core.sys.solaris.execinfo;
else version (CRuntime_UClibc)
import core.sys.linux.execinfo;
// avoid recursive GC calls in finalizer, trace handlers should be made @nogc instead
import core.memory : gc_inFinalizer;
......@@ -709,6 +717,8 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
version (linux) enum enableDwarf = true;
else version (FreeBSD) enum enableDwarf = true;
else version (DragonFlyBSD) enum enableDwarf = true;
else version (Darwin) enum enableDwarf = true;
else enum enableDwarf = false;
static if (enableDwarf)
......@@ -832,6 +842,18 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
symEnd = eptr - buf.ptr;
}
}
else version (DragonFlyBSD)
{
// format is: 0x00000000 <_D6module4funcAFZv+0x78> at module
auto bptr = cast(char*) memchr( buf.ptr, '<', buf.length );
auto eptr = cast(char*) memchr( buf.ptr, '+', buf.length );
if ( bptr++ && eptr )
{
symBeg = bptr - buf.ptr;
symEnd = eptr - buf.ptr;
}
}
else version (Solaris)
{
// format is object'symbol+offset [pc]
......@@ -896,7 +918,7 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
{
static enum FIRSTFRAME = 0;
}
import core.sys.windows.windows : CONTEXT;
import core.sys.windows.winnt : CONTEXT;
auto s = new StackTrace(FIRSTFRAME, cast(CONTEXT*)ptr);
return s;
}
......
......@@ -120,6 +120,13 @@ version (CRuntime_Glibc)
enum F_SETLK = 6;
enum F_SETLKW = 7;
}
else version (SystemZ)
{
static assert(off_t.sizeof == 8);
enum F_GETLK = 5;
enum F_SETLK = 6;
enum F_SETLKW = 7;
}
else
static if ( __USE_FILE_OFFSET64 )
{
......
......@@ -239,7 +239,8 @@ else version (Darwin)
// POSIX_SPAWN_SETSCHEDPARAM = 0x10, // not supported
// POSIX_SPAWN_SETSCHEDULER = 0x20, // ditto
POSIX_SPAWN_SETEXEC = 0x40,
POSIX_SPAWN_START_SUSPENDED = 0x80
POSIX_SPAWN_START_SUSPENDED = 0x80,
POSIX_SPAWN_CLOEXEC_DEFAULT = 0x4000
}
alias posix_spawnattr_t = void*;
alias posix_spawn_file_actions_t = void*;
......@@ -288,6 +289,8 @@ else version (NetBSD)
uint len;
posix_spawn_file_actions_entry_t* fae;
}
alias posix_spawnattr_t = posix_spawnattr;
alias posix_spawn_file_actions_t = posix_spawn_file_actions;
}
else version (OpenBSD)
{
......
......@@ -799,12 +799,12 @@ version (CRuntime_Glibc)
alias __ino_t = c_ulong;
alias __ino64_t = ulong;
alias __mode_t = uint;
alias __nlink_t = uint;
alias __nlink_t = ulong;
alias __uid_t = uint;
alias __gid_t = uint;
alias __off_t = c_long;
alias __off64_t = long;
alias __blksize_t = int;
alias __blksize_t = c_long;
alias __blkcnt_t = c_long;
alias __blkcnt64_t = long;
alias __timespec = timespec;
......
......@@ -1187,7 +1187,7 @@ class Thread
}
else
{
// NOTE: pthread_setschedprio is not implemented on Darwin or FreeBSD, so use
// NOTE: pthread_setschedprio is not implemented on Darwin, FreeBSD or DragonFlyBSD, so use
// the more complicated get/set sequence below.
int policy;
sched_param param;
......@@ -3202,8 +3202,11 @@ extern (C) @nogc nothrow
version (CRuntime_Glibc) int pthread_getattr_np(pthread_t thread, pthread_attr_t* attr);
version (FreeBSD) int pthread_attr_get_np(pthread_t thread, pthread_attr_t* attr);
version (NetBSD) int pthread_attr_get_np(pthread_t thread, pthread_attr_t* attr);
version (DragonFlyBSD) int pthread_attr_get_np(pthread_t thread, pthread_attr_t* attr);
version (Solaris) int thr_stksegment(stack_t* stk);
version (CRuntime_Bionic) int pthread_getattr_np(pthread_t thid, pthread_attr_t* attr);
version (CRuntime_Musl) int pthread_getattr_np(pthread_t, pthread_attr_t*);
version (CRuntime_UClibc) int pthread_getattr_np(pthread_t thread, pthread_attr_t* attr);
}
......@@ -3292,6 +3295,19 @@ private void* getStackBottom() nothrow @nogc
addr += size;
return addr;
}
else version (DragonFlyBSD)
{
pthread_attr_t attr;
void* addr; size_t size;
pthread_attr_init(&attr);
pthread_attr_get_np(pthread_self(), &attr);
pthread_attr_getstack(&attr, &addr, &size);
pthread_attr_destroy(&attr);
version (StackGrowsDown)
addr += size;
return addr;
}
else version (Solaris)
{
stack_t stk;
......@@ -3311,6 +3327,30 @@ private void* getStackBottom() nothrow @nogc
addr += size;
return addr;
}
else version (CRuntime_Musl)
{
pthread_attr_t attr;
void* addr; size_t size;
pthread_getattr_np(pthread_self(), &attr);
pthread_attr_getstack(&attr, &addr, &size);
pthread_attr_destroy(&attr);
version (StackGrowsDown)
addr += size;
return addr;
}
else version (CRuntime_UClibc)
{
pthread_attr_t attr;
void* addr; size_t size;
pthread_getattr_np(pthread_self(), &attr);
pthread_attr_getstack(&attr, &addr, &size);
pthread_attr_destroy(&attr);
version (StackGrowsDown)
addr += size;
return addr;
}
else
static assert(false, "Platform not supported.");
}
......@@ -4569,8 +4609,10 @@ private:
version (Posix) import core.sys.posix.sys.mman; // mmap
version (FreeBSD) import core.sys.freebsd.sys.mman : MAP_ANON;
version (NetBSD) import core.sys.netbsd.sys.mman : MAP_ANON;
version (DragonFlyBSD) import core.sys.dragonflybsd.sys.mman : MAP_ANON;
version (CRuntime_Glibc) import core.sys.linux.sys.mman : MAP_ANON;
version (Darwin) import core.sys.darwin.sys.mman : MAP_ANON;
version (CRuntime_UClibc) import core.sys.linux.sys.mman : MAP_ANON;
static if ( __traits( compiles, mmap ) )
{
......@@ -5612,6 +5654,27 @@ version (FreeBSD) unittest
thr.join();
}
version (DragonFlyBSD) unittest
{
static void loop()
{
pthread_attr_t attr;
pthread_attr_init(&attr);
auto thr = pthread_self();
foreach (i; 0 .. 50)
pthread_attr_get_np(thr, &attr);
pthread_attr_destroy(&attr);
}
auto thr = new Thread(&loop).start();
foreach (i; 0 .. 50)
{
thread_suspendAll();
thread_resumeAll();
}
thr.join();
}
unittest
{
// use >PAGESIZE to avoid stack overflow (e.g. in an syscall)
......
......@@ -272,7 +272,7 @@ extern (C) int _aApplyRwc1(in wchar[] aa, dg_t dg)
if (d & ~0x7F)
{
char[4] buf;
char[4] buf = void;
auto b = toUTF8(buf, d);
foreach (char c2; b)
......@@ -348,7 +348,7 @@ extern (C) int _aApplyRdc1(in dchar[] aa, dg_t dg)
if (d & ~0x7F)
{
char[4] buf;
char[4] buf = void;
auto b = toUTF8(buf, d);
foreach (char c2; b)
......@@ -741,7 +741,7 @@ extern (C) int _aApplyRwc2(in wchar[] aa, dg2_t dg)
if (d & ~0x7F)
{
char[4] buf;
char[4] buf = void;
auto b = toUTF8(buf, d);
foreach (char c2; b)
......@@ -819,7 +819,7 @@ extern (C) int _aApplyRdc2(in dchar[] aa, dg2_t dg)
if (d & ~0x7F)
{
char[4] buf;
char[4] buf = void;
auto b = toUTF8(buf, d);
foreach (char c2; b)
......
......@@ -115,7 +115,7 @@ string rt_envvarsOption(string opt, scope rt_configCallBack dg) @nogc nothrow
if (opt.length >= 32)
assert(0);
char[40] var;
char[40] var = void;
var[0 .. 4] = "DRT_";
foreach (i, c; opt)
var[4 + i] = cast(char) toupper(c);
......
......@@ -42,6 +42,10 @@ version (NetBSD)
{
import core.stdc.fenv;
}
version (DragonFlyBSD)
{
import core.stdc.fenv;
}
extern (C) void _d_monitor_staticctor();
extern (C) void _d_monitor_staticdtor();
......
......@@ -193,7 +193,8 @@ else version (Windows)
{
pragma(lib, "snn.lib");
}
import core.sys.windows.windows;
import core.sys.windows.winbase /+: CRITICAL_SECTION, DeleteCriticalSection,
EnterCriticalSection, InitializeCriticalSection, LeaveCriticalSection+/;
alias Mutex = CRITICAL_SECTION;
......@@ -206,6 +207,7 @@ else version (Posix)
{
import core.sys.posix.pthread;
@nogc:
alias Mutex = pthread_mutex_t;
__gshared pthread_mutexattr_t gattr;
......@@ -244,17 +246,17 @@ struct Monitor
private:
@property ref shared(Monitor*) monitor(Object h) pure nothrow
@property ref shared(Monitor*) monitor(Object h) pure nothrow @nogc
{
return *cast(shared Monitor**)&h.__monitor;
}
private shared(Monitor)* getMonitor(Object h) pure
private shared(Monitor)* getMonitor(Object h) pure @nogc
{
return atomicLoad!(MemoryOrder.acq)(h.monitor);
}
void setMonitor(Object h, shared(Monitor)* m) pure
void setMonitor(Object h, shared(Monitor)* m) pure @nogc
{
atomicStore!(MemoryOrder.rel)(h.monitor, m);
}
......@@ -296,7 +298,7 @@ shared(Monitor)* ensureMonitor(Object h)
}
}
void deleteMonitor(Monitor* m)
void deleteMonitor(Monitor* m) @nogc
{
destroyMutex(&m.mtx);
free(m);
......
......@@ -75,6 +75,21 @@ else version (FreeBSD)
return a;
}
}
else version (DragonFlyBSD)
{
alias extern (C) int function(scope void *, scope const void *, scope const void *) Cmp;
extern (C) void qsort_r(scope void *base, size_t nmemb, size_t size, scope void *thunk, Cmp cmp);
extern (C) void[] _adSort(return scope void[] a, TypeInfo ti)
{
extern (C) int cmp(scope void* ti, scope const void* p1, scope const void* p2)
{
return (cast(TypeInfo)ti).compare(p1, p2);
}
qsort_r(a.ptr, a.length, ti.tsize, cast(void*)ti, &cmp);
return a;
}
}
else version (Darwin)
{
alias extern (C) int function(scope void *, scope const void *, scope const void *) Cmp;
......@@ -90,6 +105,21 @@ else version (Darwin)
return a;
}
}
else version (CRuntime_UClibc)
{
alias extern (C) int function(scope const void *, scope const void *, scope void *) __compar_d_fn_t;
extern (C) void qsort_r(scope void *base, size_t nmemb, size_t size, __compar_d_fn_t cmp, scope void *arg);
extern (C) void[] _adSort(return scope void[] a, TypeInfo ti)
{
extern (C) int cmp(scope const void* p1, scope const void* p2, scope void* ti)
{
return (cast(TypeInfo)ti).compare(p1, p2);
}
qsort_r(a.ptr, a.length, ti.tsize, &cmp, cast(void*)ti);
return a;
}
}
else
{
private TypeInfo tiglobal;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment