aboutsummaryrefslogtreecommitdiff
path: root/libphobos/libdruntime
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2022-02-20 20:02:23 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2022-02-20 23:37:32 +0100
commit6384eff56dba1fac071c1b525f7e49cf03f2737f (patch)
tree7263a4a6ec603a81f6df660f4f6b19a4607513fc /libphobos/libdruntime
parente49508ac6b36adb8a2056c5a1fb6e0178de2439d (diff)
d: Merge upstream dmd cb49e99f8, druntime 55528bd1, phobos 1a3e80ec2.
D front-end changes: - Import dmd v2.099.0-beta.1. - It's now an error to use `alias this' for partial assignment. - The `delete' keyword has been removed from the language. - Using `this' and `super' as types has been removed from the language, the parser no longer specially handles this wrong code with an informative error. D Runtime changes: - Import druntime v2.099.0-beta.1. Phobos changes: - Import phobos v2.099.0-beta.1. gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd cb49e99f8. * dmd/VERSION: Update version to v2.099.0-beta.1. * decl.cc (layout_class_initializer): Update call to NewExp::create. * expr.cc (ExprVisitor::visit (DeleteExp *)): Remove handling of deleting arrays and pointers. (ExprVisitor::visit (DotVarExp *)): Convert complex types to the front-end library type representing them. (ExprVisitor::visit (StringExp *)): Use getCodeUnit instead of charAt to get the value of each index in a string expression. * runtime.def (DELMEMORY): Remove. (DELARRAYT): Remove. * types.cc (TypeVisitor::visit (TypeEnum *)): Handle anonymous enums. libphobos/ChangeLog: * libdruntime/MERGE: Merge upstream druntime 55528bd1. * src/MERGE: Merge upstream phobos 1a3e80ec2. * testsuite/libphobos.hash/test_hash.d: Update. * testsuite/libphobos.betterc/test19933.d: New test.
Diffstat (limited to 'libphobos/libdruntime')
-rw-r--r--libphobos/libdruntime/MERGE2
-rw-r--r--libphobos/libdruntime/__builtins.di65
-rw-r--r--libphobos/libdruntime/core/attribute.d49
-rw-r--r--libphobos/libdruntime/core/bitop.d13
-rw-r--r--libphobos/libdruntime/core/int128.d2
-rw-r--r--libphobos/libdruntime/core/internal/array/appending.d8
-rw-r--r--libphobos/libdruntime/core/internal/array/comparison.d33
-rw-r--r--libphobos/libdruntime/core/internal/convert.d22
-rw-r--r--libphobos/libdruntime/core/lifetime.d4
-rw-r--r--libphobos/libdruntime/core/math.d1
-rw-r--r--libphobos/libdruntime/core/runtime.d2
-rw-r--r--libphobos/libdruntime/core/stdc/stdio.d17
-rw-r--r--libphobos/libdruntime/core/sys/linux/config.d3
-rw-r--r--libphobos/libdruntime/core/sys/linux/dlfcn.d22
-rw-r--r--libphobos/libdruntime/core/sys/linux/errno.d2
-rw-r--r--libphobos/libdruntime/core/sys/linux/netinet/in_.d10
-rw-r--r--libphobos/libdruntime/core/sys/linux/string.d2
-rw-r--r--libphobos/libdruntime/core/sys/linux/sys/mman.d72
-rw-r--r--libphobos/libdruntime/core/sys/posix/aio.d132
-rw-r--r--libphobos/libdruntime/core/sys/posix/config.d58
-rw-r--r--libphobos/libdruntime/core/sys/posix/spawn.d12
-rw-r--r--libphobos/libdruntime/core/sys/posix/sys/ipc.d65
-rw-r--r--libphobos/libdruntime/core/sys/posix/sys/mman.d4
-rw-r--r--libphobos/libdruntime/core/sys/posix/sys/shm.d12
-rw-r--r--libphobos/libdruntime/core/sys/posix/sys/socket.d32
-rw-r--r--libphobos/libdruntime/core/sys/posix/sys/stat.d24
-rw-r--r--libphobos/libdruntime/core/sys/posix/sys/statvfs.d2
-rw-r--r--libphobos/libdruntime/core/sys/posix/sys/types.d2
-rw-r--r--libphobos/libdruntime/object.d4
-rw-r--r--libphobos/libdruntime/rt/util/typeinfo.d289
30 files changed, 484 insertions, 481 deletions
diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index 251d78de19b..49f6ae282e0 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-dbd0c874a345438b8b4379a67525a933436d039a
+55528bd1e963d858eaa63901fc818b957c349fbc
The first line of this file holds the git revision number of the last
merge done from the dlang/druntime repository.
diff --git a/libphobos/libdruntime/__builtins.di b/libphobos/libdruntime/__builtins.di
index cd64881529e..e5c448e00cf 100644
--- a/libphobos/libdruntime/__builtins.di
+++ b/libphobos/libdruntime/__builtins.di
@@ -38,3 +38,68 @@ alias __builtin_va_copy = core.stdc.stdarg.va_copy;
/* dmd's ImportC rewrites __builtin_va_arg into an instantiation of va_arg
*/
alias va_arg = core.stdc.stdarg.va_arg;
+
+version (CRuntime_Microsoft)
+{
+ //https://docs.microsoft.com/en-us/cpp/cpp/int8-int16-int32-int64?view=msvc-170
+ alias __int8 = byte;
+ alias __int16 = short;
+ alias __int32 = int;
+ alias __int64 = long;
+}
+
+/*********** floating point *************/
+
+/* https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
+ */
+
+version (DigitalMars)
+{
+ double __builtin_inf()() { return double.infinity; }
+ float __builtin_inff()() { return float.infinity; }
+ real __builtin_infl()() { return real.infinity; }
+
+ alias __builtin_huge_val = __builtin_inf;
+ alias __builtin_huge_valf = __builtin_inff;
+ alias __builtin_huge_vall = __builtin_infl;
+
+ import core.stdc.math;
+
+ alias __builtin_fabs = core.stdc.math.fabs;
+ alias __builtin_fabsf = core.stdc.math.fabsf;
+ alias __builtin_fabsl = core.stdc.math.fabsl;
+
+ ushort __builtin_bswap16()(ushort value)
+ {
+ import core.bitop;
+ return core.bitop.byteswap(value);
+ }
+
+ uint __builtin_bswap32()(uint value)
+ {
+ import core.bitop;
+ return core.bitop.bswap(value);
+ }
+
+ ulong __builtin_bswap64()(ulong value)
+ {
+ import core.bitop;
+ return core.bitop.bswap(value);
+ }
+
+ // Stub these out to no-ops
+ int __builtin_constant_p(T)(T exp) { return 0; } // should be something like __traits(compiles, enum X = expr)
+ long __builtin_expect()(long exp, long c) { return exp; }
+ void* __builtin_assume_aligned()(const void* p, size_t align_, ...) { return cast(void*)p; }
+
+ // https://releases.llvm.org/13.0.0/tools/clang/docs/LanguageExtensions.html#builtin-assume
+ void __builtin_assume(T)(lazy T arg) { }
+
+ /* Header on macOS for arm64 references this.
+ * Don't need to implement it, it just needs to compile
+ */
+ align (16) struct __uint128_t
+ {
+ ulong a, b;
+ }
+}
diff --git a/libphobos/libdruntime/core/attribute.d b/libphobos/libdruntime/core/attribute.d
index b0b973fbfa6..69b20f0bd3c 100644
--- a/libphobos/libdruntime/core/attribute.d
+++ b/libphobos/libdruntime/core/attribute.d
@@ -241,3 +241,52 @@ version (UdaGNUAbiTag) struct gnuAbiTag
this.tags = tags;
}
}
+
+/**
+ * Use this attribute to ensure that values of a `struct` or `union` type are
+ * not discarded.
+ *
+ * The value of an expression is considered to be discarded if
+ *
+ * $(UL
+ * $(LI
+ * the expression is the top-level expression in a statement or the
+ * left-hand expression in a comma expression, and
+ * ),
+ * $(LI
+ * the expression is not an assignment (`=`, `+=`, etc.), increment
+ * (`++`), or decrement (`--`) expression.
+ * ),
+ * )
+ *
+ * If the declaration of a `struct` or `union` type has the `@mustuse`
+ * attribute, the compiler will emit an error any time a value of that type
+ * would be discarded.
+ *
+ * Currently, `@mustuse` is only recognized by the compiler when attached to
+ * `struct` and `union` declarations. To allow for future expansion, attaching
+ * `@mustuse` to a `class`, `interface`, `enum`, or function declaration is
+ * currently forbidden, and will result in a compile-time error. All other uses
+ * of `@mustuse` are ignored.
+ *
+ * Examples:
+ * ---
+ * @mustuse struct ErrorCode { int value; }
+ *
+ * extern(C) ErrorCode doSomething();
+ *
+ * void main()
+ * {
+ * // error: would discard a value of type ErrorCode
+ * //doSomething();
+ *
+ * ErrorCode result;
+ * // ok: value is assigned to a variable
+ * result = doSomething();
+ *
+ * // ok: can ignore the value explicitly with a cast
+ * cast(void) doSomething();
+ * }
+ * ---
+ */
+enum mustuse;
diff --git a/libphobos/libdruntime/core/bitop.d b/libphobos/libdruntime/core/bitop.d
index 40f224214e3..59445f09147 100644
--- a/libphobos/libdruntime/core/bitop.d
+++ b/libphobos/libdruntime/core/bitop.d
@@ -758,19 +758,6 @@ version (DigitalMars) version (AnyX86)
}
-// @@@DEPRECATED_2.099@@@
-deprecated("volatileLoad has been moved to core.volatile. Use core.volatile.volatileLoad instead.")
-{
- public import core.volatile : volatileLoad;
-}
-
-// @@@DEPRECATED_2.099@@@
-deprecated("volatileStore has been moved to core.volatile. Use core.volatile.volatileStore instead.")
-{
- public import core.volatile : volatileStore;
-}
-
-
/**
* Reverses the order of bits in a 32-bit integer.
*/
diff --git a/libphobos/libdruntime/core/int128.d b/libphobos/libdruntime/core/int128.d
index aad2cf23942..2f628c03138 100644
--- a/libphobos/libdruntime/core/int128.d
+++ b/libphobos/libdruntime/core/int128.d
@@ -801,6 +801,7 @@ unittest
const Cm10_0 = inc(com(C10_0)); // Cent(0, -10);
const Cm10_1 = inc(com(C10_1)); // Cent(-1, -11);
const Cm10_3 = inc(com(C10_3)); // Cent(-3, -11);
+ const Cm20_0 = inc(com(C20_0)); // Cent(0, -20);
enum Cs_3 = Cent(3, I.min);
@@ -904,6 +905,7 @@ unittest
assert(mul(C9_3, C10) == C90_30);
assert(mul(Cs_3, C10) == C30);
assert(mul(Cm10, Cm10) == C100);
+ assert(mul(C20_0, Cm1) == Cm20_0);
assert( or(C4_8, C3_1) == C7_9);
assert(and(C4_8, C7_9) == C4_8);
diff --git a/libphobos/libdruntime/core/internal/array/appending.d b/libphobos/libdruntime/core/internal/array/appending.d
index 1e58ddc9880..172263c684a 100644
--- a/libphobos/libdruntime/core/internal/array/appending.d
+++ b/libphobos/libdruntime/core/internal/array/appending.d
@@ -35,14 +35,14 @@ template _d_arrayappendcTXImpl(Tarr : T[], T)
* is temporarily declared `@trusted pure` until the implementation can be brought up to modern D expectations.
*/
static if (isCopyingNothrow!T) // `nothrow` deduction doesn't work, so this is needed
- ref Tarr _d_arrayappendcTX(return scope ref Tarr px, size_t n) @trusted pure nothrow
+ ref Tarr _d_arrayappendcTX(return ref scope Tarr px, size_t n) @trusted pure nothrow
{
pragma(inline, false);
mixin(_d_arrayappendcTXBody);
}
else
- ref Tarr _d_arrayappendcTX(return scope ref Tarr px, size_t n) @trusted pure nothrow
+ ref Tarr _d_arrayappendcTX(return ref scope Tarr px, size_t n) @trusted pure nothrow
{
pragma(inline, false);
@@ -96,14 +96,14 @@ template _d_arrayappendTImpl(Tarr : T[], T)
* is temporarily declared `@trusted pure` until the implementation can be brought up to modern D expectations.
*/
static if (isCopyingNothrow!T)
- ref Tarr _d_arrayappendT(return scope ref Tarr x, scope Tarr y) @trusted pure nothrow
+ ref Tarr _d_arrayappendT(return ref scope Tarr x, scope Tarr y) @trusted pure nothrow
{
pragma(inline, false);
mixin(_d_arrayappendTBody);
}
else
- ref Tarr _d_arrayappendT(return scope ref Tarr x, scope Tarr y) @trusted pure
+ ref Tarr _d_arrayappendT(return ref scope Tarr x, scope Tarr y) @trusted pure
{
pragma(inline, false);
diff --git a/libphobos/libdruntime/core/internal/array/comparison.d b/libphobos/libdruntime/core/internal/array/comparison.d
index 1a68b9b9e71..821f96e25c0 100644
--- a/libphobos/libdruntime/core/internal/array/comparison.d
+++ b/libphobos/libdruntime/core/internal/array/comparison.d
@@ -60,24 +60,21 @@ int __cmp(T)(scope const T[] lhs, scope const T[] rhs) @trusted
immutable len = lhs.length <= rhs.length ? lhs.length : rhs.length;
foreach (const u; 0 .. len)
{
- static if (__traits(isFloating, T))
+ auto a = lhs.ptr[u], b = rhs.ptr[u];
+ static if (is(T : creal))
{
- immutable a = lhs.ptr[u], b = rhs.ptr[u];
- static if (is(T == cfloat) || is(T == cdouble)
- || is(T == creal))
- {
- // Use rt.cmath2._Ccmp instead ?
- auto r = (a.re > b.re) - (a.re < b.re);
- if (!r) r = (a.im > b.im) - (a.im < b.im);
- }
- else
- {
- const r = (a > b) - (a < b);
- }
- if (r) return r;
+ // Use rt.cmath2._Ccmp instead ?
+ // Also: if NaN is present, numbers will appear equal.
+ auto r = (a.re > b.re) - (a.re < b.re);
+ if (!r) r = (a.im > b.im) - (a.im < b.im);
+ }
+ else
+ {
+ // This pattern for three-way comparison is better than conditional operators
+ // See e.g. https://godbolt.org/z/3j4vh1
+ const r = (a > b) - (a < b);
}
- else if (lhs.ptr[u] != rhs.ptr[u])
- return lhs.ptr[u] < rhs.ptr[u] ? -1 : 1;
+ if (r) return r;
}
return (lhs.length > rhs.length) - (lhs.length < rhs.length);
}
@@ -117,8 +114,8 @@ if (!__traits(isScalar, T1) && !__traits(isScalar, T2))
}
else static if (__traits(compiles, at(s1, u) < at(s2, u)))
{
- if (at(s1, u) != at(s2, u))
- return at(s1, u) < at(s2, u) ? -1 : 1;
+ if (int result = (at(s1, u) > at(s2, u)) - (at(s1, u) < at(s2, u)))
+ return result;
}
else
{
diff --git a/libphobos/libdruntime/core/internal/convert.d b/libphobos/libdruntime/core/internal/convert.d
index a876fcc537f..92eb243ec1a 100644
--- a/libphobos/libdruntime/core/internal/convert.d
+++ b/libphobos/libdruntime/core/internal/convert.d
@@ -741,28 +741,6 @@ const(ubyte)[] toUbyte(T)(const ref scope T val) if (is(T == __vector))
}
}
-// @@@DEPRECATED_2022-02@@@
-deprecated
-@trusted pure nothrow @nogc
-const(ubyte)[] toUbyte(T)(const ref return scope T val) if (__traits(isFloating, T) && is(T : creal))
-{
- if (__ctfe)
- {
- auto re = val.re;
- auto im = val.im;
- auto a = re.toUbyte();
- auto b = im.toUbyte();
- ubyte[] result = ctfe_alloc(a.length + b.length);
- result[0 .. a.length] = a[0 .. a.length];
- result[a.length .. $] = b[0 .. b.length];
- return result;
- }
- else
- {
- return (cast(const(ubyte)*)&val)[0 .. T.sizeof];
- }
-}
-
@trusted pure nothrow @nogc
const(ubyte)[] toUbyte(T)(const ref return scope T val) if (is(T == enum))
{
diff --git a/libphobos/libdruntime/core/lifetime.d b/libphobos/libdruntime/core/lifetime.d
index 091269ac9a1..3a7c8e02b8a 100644
--- a/libphobos/libdruntime/core/lifetime.d
+++ b/libphobos/libdruntime/core/lifetime.d
@@ -2646,9 +2646,9 @@ T _d_newThrowable(T, Args...)(auto ref Args args) @trusted
{
debug(PRINTF) printf("_d_newThrowable(%s)\n", cast(char*) T.stringof);
- import core.stdc.stdlib : malloc;
+ import core.memory : pureMalloc;
auto init = __traits(initSymbol, T);
- void* p = malloc(init.length);
+ void* p = pureMalloc(init.length);
if (!p)
{
import core.exception : onOutOfMemoryError;
diff --git a/libphobos/libdruntime/core/math.d b/libphobos/libdruntime/core/math.d
index 4d46b67d2a3..30fc1308e4b 100644
--- a/libphobos/libdruntime/core/math.d
+++ b/libphobos/libdruntime/core/math.d
@@ -36,6 +36,7 @@ nothrow:
* greater than long.max, the result is
* indeterminate.
*/
+deprecated("rndtonl is to be removed by 2.100. Please use round instead")
extern (C) real rndtonl(real x);
pure:
diff --git a/libphobos/libdruntime/core/runtime.d b/libphobos/libdruntime/core/runtime.d
index 81d2d261a80..d1378afca91 100644
--- a/libphobos/libdruntime/core/runtime.d
+++ b/libphobos/libdruntime/core/runtime.d
@@ -285,7 +285,7 @@ struct Runtime
* an appropriate calling context from which to begin the trace.
*
* Params:
- * h = The new trace handler. Set to null to use the default handler.
+ * h = The new trace handler. Set to null to disable exception backtracing.
*/
extern(C) pragma(mangle, "rt_setTraceHandler") static @property void traceHandler(TraceHandler h);
diff --git a/libphobos/libdruntime/core/stdc/stdio.d b/libphobos/libdruntime/core/stdc/stdio.d
index c76b922a3eb..0dcdb6efc26 100644
--- a/libphobos/libdruntime/core/stdc/stdio.d
+++ b/libphobos/libdruntime/core/stdc/stdio.d
@@ -700,9 +700,8 @@ else version (Solaris)
}
else version (CRuntime_Bionic)
{
- import core.sys.posix.sys.types : off_t;
///
- alias off_t fpos_t;
+ alias c_long fpos_t; // couldn't use off_t because of static if issue
///
struct __sFILE
@@ -745,12 +744,10 @@ else version (CRuntime_UClibc)
import core.stdc.stddef : wchar_t;
import core.sys.posix.sys.types : ssize_t, pthread_mutex_t;
- alias long off_t;
-
///
struct fpos_t
{
- off_t __pos;
+ long __pos; // couldn't use off_t because of static if issue
mbstate_t __state;
int __mblen_pending;
}
@@ -759,7 +756,7 @@ else version (CRuntime_UClibc)
{
ssize_t function(void* __cookie, char* __buf, size_t __bufsize) read;
ssize_t function(void* __cookie, const char* __buf, size_t __bufsize) write;
- int function(void* __cookie, off_t* __pos, int __whence) seek;
+ int function(void* __cookie, long* __pos, int __whence) seek;
int function(void* __cookie) close;
}
@@ -900,12 +897,14 @@ else version (CRuntime_Microsoft)
extern shared void function() _fcloseallp;
+ FILE* __acrt_iob_func(int hnd); // VS2015+, reimplemented in msvc.d for VS2013-
+
///
- shared FILE* stdin; // = &__iob_func()[0];
+ FILE* stdin()() { return __acrt_iob_func(0); }
///
- shared FILE* stdout; // = &__iob_func()[1];
+ FILE* stdout()() { return __acrt_iob_func(1); }
///
- shared FILE* stderr; // = &__iob_func()[2];
+ FILE* stderr()() { return __acrt_iob_func(2); }
}
else version (CRuntime_Glibc)
{
diff --git a/libphobos/libdruntime/core/sys/linux/config.d b/libphobos/libdruntime/core/sys/linux/config.d
index 03d3e17e166..5d38244f858 100644
--- a/libphobos/libdruntime/core/sys/linux/config.d
+++ b/libphobos/libdruntime/core/sys/linux/config.d
@@ -24,6 +24,9 @@ deprecated("use _DEFAULT_SOURCE")
enum _SVID_SOURCE = true;
}
+deprecated("use _DEFAULT_SOURCE")
enum __USE_MISC = _DEFAULT_SOURCE;
+deprecated("use _ATFILE_SOURCE")
enum __USE_ATFILE = _ATFILE_SOURCE;
+deprecated("use _GNU_SOURCE")
enum __USE_GNU = _GNU_SOURCE;
diff --git a/libphobos/libdruntime/core/sys/linux/dlfcn.d b/libphobos/libdruntime/core/sys/linux/dlfcn.d
index 4a122849471..fbb84627af8 100644
--- a/libphobos/libdruntime/core/sys/linux/dlfcn.d
+++ b/libphobos/libdruntime/core/sys/linux/dlfcn.d
@@ -34,7 +34,7 @@ import core.sys.linux.config;
version (X86_Any)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
- static if (__USE_GNU)
+ static if (_GNU_SOURCE)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
@@ -48,7 +48,7 @@ version (X86_Any)
else version (HPPA_Any)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=ports/sysdeps/hppa/bits/dlfcn.h
- static if (__USE_GNU)
+ static if (_GNU_SOURCE)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
@@ -62,7 +62,7 @@ else version (HPPA_Any)
else version (MIPS_Any)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=ports/sysdeps/mips/bits/dlfcn.h
- static if (__USE_GNU)
+ static if (_GNU_SOURCE)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
@@ -76,7 +76,7 @@ else version (MIPS_Any)
else version (PPC_Any)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
- static if (__USE_GNU)
+ static if (_GNU_SOURCE)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
@@ -90,7 +90,7 @@ else version (PPC_Any)
else version (ARM_Any)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
- static if (__USE_GNU)
+ static if (_GNU_SOURCE)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
@@ -104,7 +104,7 @@ else version (ARM_Any)
else version (RISCV_Any)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
- static if (__USE_GNU)
+ static if (_GNU_SOURCE)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
@@ -118,7 +118,7 @@ else version (RISCV_Any)
else version (SPARC_Any)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
- static if (__USE_GNU)
+ static if (_GNU_SOURCE)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
@@ -132,7 +132,7 @@ else version (SPARC_Any)
else version (IBMZ_Any)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
- static if (__USE_GNU)
+ static if (_GNU_SOURCE)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
@@ -148,7 +148,7 @@ else
// <bits/dlfcn.h>
-static if (__USE_GNU)
+static if (_GNU_SOURCE)
{
enum RTLD_NEXT = cast(void *)-1L;
enum RTLD_DEFAULT = cast(void *)0;
@@ -161,7 +161,7 @@ static if (__USE_GNU)
// int dlclose(void* __handle); // POSIX
// void* dlsym(void* __handle, const scope char* __name); // POSIX
-static if (__USE_GNU)
+static if (_GNU_SOURCE)
{
void* dlmopen(Lmid_t __nsid, const scope char* __file, int __mode);
void* dlvsym(void* __handle, const scope char* __name, const scope char* __version);
@@ -169,7 +169,7 @@ static if (__USE_GNU)
// char* dlerror(); // POSIX
-static if (__USE_GNU)
+static if (_GNU_SOURCE)
{
int dladdr1(void* __address, Dl_info* __info, void** __extra_info, int __flags);
diff --git a/libphobos/libdruntime/core/sys/linux/errno.d b/libphobos/libdruntime/core/sys/linux/errno.d
index 02ae151427e..d7a39acb932 100644
--- a/libphobos/libdruntime/core/sys/linux/errno.d
+++ b/libphobos/libdruntime/core/sys/linux/errno.d
@@ -13,7 +13,7 @@ nothrow:
public import core.stdc.errno;
import core.sys.linux.config;
-static if (__USE_GNU)
+static if (_GNU_SOURCE)
{
extern __gshared char* program_invocation_name, program_invocation_short_name;
alias error_t = int;
diff --git a/libphobos/libdruntime/core/sys/linux/netinet/in_.d b/libphobos/libdruntime/core/sys/linux/netinet/in_.d
index 67bf6545c8f..1b428f5aecc 100644
--- a/libphobos/libdruntime/core/sys/linux/netinet/in_.d
+++ b/libphobos/libdruntime/core/sys/linux/netinet/in_.d
@@ -115,7 +115,7 @@ version (linux_libc)
enum IN6ADDR_ANY_INIT = in6_addr.init;
enum IN6ADDR_LOOPBACK_INIT = in6_addr([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
- version (gnu_libc) static if (__USE_MISC)
+ version (gnu_libc) static if (_DEFAULT_SOURCE)
{
struct ip_mreq
{
@@ -174,13 +174,13 @@ version (linux_libc)
extern(D) bool IN6_ARE_ADDR_EQUAL(in6_addr* a, in6_addr* b) pure @safe { return *a == *b; }
- version (gnu_libc) static if (__USE_MISC)
+ version (gnu_libc) static if (_DEFAULT_SOURCE)
{
int bindresvport(int __sockfd, sockaddr_in* __sock_in);
int bindresvport6(int __sockfd, sockaddr_in6* _);
}
- version (gnu_libc) static if (__USE_GNU)
+ version (gnu_libc) static if (_GNU_SOURCE)
{
struct in6_pktinfo
{
@@ -254,7 +254,7 @@ version (linux_libc)
enum IP_DROP_SOURCE_MEMBERSHIP = 40;
enum IP_MSFILTER = 41;
- version (gnu_libc) static if (__USE_MISC)
+ version (gnu_libc) static if (_DEFAULT_SOURCE)
{
enum MCAST_JOIN_GROUP = 42;
enum MCAST_BLOCK_SOURCE = 43;
@@ -307,7 +307,7 @@ version (linux_libc)
enum IP_DEFAULT_MULTICAST_LOOP = 1;
enum IP_MAX_MEMBERSHIPS = 20;
- version (gnu_libc) static if (__USE_MISC)
+ version (gnu_libc) static if (_DEFAULT_SOURCE)
{
struct ip_opts
{
diff --git a/libphobos/libdruntime/core/sys/linux/string.d b/libphobos/libdruntime/core/sys/linux/string.d
index e3c94cf6a8a..880faa4d701 100644
--- a/libphobos/libdruntime/core/sys/linux/string.d
+++ b/libphobos/libdruntime/core/sys/linux/string.d
@@ -16,7 +16,7 @@ nothrow:
@nogc:
@system:
-static if (__USE_GNU)
+static if (_GNU_SOURCE)
{
pure void* memmem(return scope const void* haystack, size_t haystacklen, scope const void* needle, size_t needlelen);
}
diff --git a/libphobos/libdruntime/core/sys/linux/sys/mman.d b/libphobos/libdruntime/core/sys/linux/sys/mman.d
index a6548a7802c..649e2af848f 100644
--- a/libphobos/libdruntime/core/sys/linux/sys/mman.d
+++ b/libphobos/libdruntime/core/sys/linux/sys/mman.d
@@ -37,7 +37,7 @@ version (PPC_Any)
{
enum PROT_SAO = 0x10;
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x00100,
MAP_DENYWRITE = 0x00800,
@@ -60,7 +60,7 @@ version (PPC_Any)
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/riscv/bits/mman.h
else version (RISCV_Any)
{
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x00100,
MAP_DENYWRITE = 0x00800,
@@ -85,7 +85,7 @@ else version (RISCV_Any)
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/s390/bits/mman.h
else version (IBMZ_Any)
{
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x00100,
MAP_DENYWRITE = 0x00800,
@@ -101,7 +101,7 @@ else version (IBMZ_Any)
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sh/bits/mman.h
else version (SH)
{
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x0100,
MAP_DENYWRITE = 0x0800,
@@ -117,7 +117,7 @@ else version (SH)
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sparc/bits/mman.h
else version (SPARC_Any)
{
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x0200,
MAP_DENYWRITE = 0x0800,
@@ -141,9 +141,9 @@ else version (SPARC_Any)
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86/bits/mman.h
else version (X86_Any)
{
- static if (__USE_MISC) enum MAP_32BIT = 0x40;
+ static if (_DEFAULT_SOURCE) enum MAP_32BIT = 0x40;
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x00100,
MAP_DENYWRITE = 0x00800,
@@ -159,7 +159,7 @@ else version (X86_Any)
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/bits/mman.h
else version (AArch64)
{
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x00100,
MAP_DENYWRITE = 0x00800,
@@ -187,11 +187,11 @@ else version (Alpha)
enum MAP_SHARED = 0x01;
enum MAP_PRIVATE = 0x02;
- static if (__USE_MISC)
+ static if (_DEFAULT_SOURCE)
enum MAP_TYPE = 0x0f;
enum MAP_FIXED = 0x10;
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_FILE = 0,
MAP_ANONYMOUS = MAP_ANON,
@@ -201,7 +201,7 @@ else version (Alpha)
MAP_HUGE_MASK = 0x3f,
}
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x01000,
MAP_DENYWRITE = 0x02000,
@@ -229,13 +229,13 @@ else version (Alpha)
// MCL_FUTURE = 16384,
// }
- static if (__USE_GNU) enum
+ static if (_GNU_SOURCE) enum
{
MREMAP_MAYMOVE = 1,
MREMAP_FIXED = 2,
}
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MADV_NORMAL = 0,
MADV_RANDOM = 1,
@@ -255,7 +255,7 @@ else version (Alpha)
}
// in core.sys.posix.sys.mman
- // static if (__USE_XOPEN2K) enum
+ // static if (_XOPEN_SOURCE >= 600) enum
// {
// POSIX_MADV_NORMAL = 0,
// POSIX_MADV_RANDOM = 1,
@@ -267,7 +267,7 @@ else version (Alpha)
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/arm/bits/mman.h
else version (ARM)
{
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x00100,
MAP_DENYWRITE = 0x00800,
@@ -295,11 +295,11 @@ else version (HPPA_Any)
enum MAP_SHARED = 0x01;
enum MAP_PRIVATE = 0x02;
- static if (__USE_MISC)
+ static if (_DEFAULT_SOURCE)
enum MAP_TYPE = 0x0f;
enum MAP_FIXED = 0x04;
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_FILE = 0,
MAP_ANONYMOUS = MAP_ANON,
@@ -310,7 +310,7 @@ else version (HPPA_Any)
MAP_HUGE_MASK = 0x3f,
}
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_DENYWRITE = 0x0800,
MAP_EXECUTABLE = 0x1000,
@@ -336,13 +336,13 @@ else version (HPPA_Any)
// MCL_FUTURE = 2,
// }
- static if (__USE_GNU) enum
+ static if (_GNU_SOURCE) enum
{
MREMAP_MAYMOVE = 1,
MREMAP_FIXED = 2,
}
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MADV_NORMAL = 0,
MADV_RANDOM = 1,
@@ -375,7 +375,7 @@ else version (HPPA_Any)
}
// in core.sys.posix.sys.mman
- // static if (__USE_XOPEN2K) enum
+ // static if (_XOPEN_SOURCE >= 600) enum
// {
// POSIX_MADV_NORMAL = 0,
// POSIX_MADV_RANDOM = 1,
@@ -387,7 +387,7 @@ else version (HPPA_Any)
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/ia64/bits/mman.h
else version (IA64)
{
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x00100,
MAP_GROWSUP = 0x00200,
@@ -404,7 +404,7 @@ else version (IA64)
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/m68k/bits/mman.h
else version (M68K)
{
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_GROWSDOWN = 0x00100,
MAP_DENYWRITE = 0x00800,
@@ -420,7 +420,7 @@ else version (M68K)
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/mips/bits/mman.h
else version (MIPS_Any)
{
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_NORESERVE = 0x0400,
MAP_GROWSDOWN = 0x1000,
@@ -460,11 +460,11 @@ else
enum MAP_SHARED = 0x01;
enum MAP_PRIVATE = 0x02;
- static if (__USE_MISC)
+ static if (_DEFAULT_SOURCE)
enum MAP_TYPE = 0x0f;
enum MAP_FIXED = 0x10;
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MAP_FILE = 0,
MAP_ANONYMOUS = MAP_ANON,
@@ -482,13 +482,13 @@ else
// MS_INVALIDATE = 2,
// }
- static if (__USE_GNU) enum
+ static if (_GNU_SOURCE) enum
{
MREMAP_MAYMOVE = 1,
MREMAP_FIXED = 2,
}
- static if (__USE_MISC) enum
+ static if (_DEFAULT_SOURCE) enum
{
MADV_NORMAL = 0,
MADV_RANDOM = 1,
@@ -508,7 +508,7 @@ else
}
// in core.sys.posix.sys.mman
- // static if (__USE_XOPEN2K) enum
+ // static if (_XOPEN_SOURCE >= 600) enum
// {
// POSIX_MADV_NORMAL = 0,
// POSIX_MADV_RANDOM = 1,
@@ -530,12 +530,12 @@ else
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sparc/bits/mman.h
version (SPARC_Any)
{
- static if (__USE_MISC) enum MAP_RENAME = MAP_ANONYMOUS;
+ static if (_DEFAULT_SOURCE) enum MAP_RENAME = MAP_ANONYMOUS;
}
// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/mips/bits/mman.h
else version (MIPS_Any)
{
- static if (__USE_MISC) enum MAP_RENAME = MAP_ANONYMOUS;
+ static if (_DEFAULT_SOURCE) enum MAP_RENAME = MAP_ANONYMOUS;
}
// http://sourceware.org/git/?p=glibc.git;a=blob;f=misc/sys/mman.h
@@ -548,14 +548,14 @@ else version (MIPS_Any)
// int munmap(void*, size_t);
// int mprotect(void *__addr, size_t __len, int __prot);
// int msync(void *__addr, size_t __len, int __flags);
-static if (__USE_MISC) int madvise(void *__addr, size_t __len, int __advice);
-// static if (__USE_XOPEN2K) int posix_madvise(void *__addr, size_t __len, int __advice);
+static if (_DEFAULT_SOURCE) int madvise(void *__addr, size_t __len, int __advice);
+// static if (_XOPEN_SOURCE >= 600) int posix_madvise(void *__addr, size_t __len, int __advice);
// int mlock(const(void) *__addr, size_t __len);
// int munlock(const(void) *__addr, size_t __len);
// int mlockall(int __flags);
// int munlockall();
-static if (__USE_MISC) int mincore(void *__start, size_t __len, ubyte *__vec);
-static if (__USE_GNU) void *mremap(void *__addr, size_t __old_len, size_t __new_len, int __flags, ...);
-static if (__USE_GNU) int remap_file_pages(void *__start, size_t __size, int __prot, size_t __pgoff, int __flags);
+static if (_DEFAULT_SOURCE) int mincore(void *__start, size_t __len, ubyte *__vec);
+static if (_GNU_SOURCE) void *mremap(void *__addr, size_t __old_len, size_t __new_len, int __flags, ...);
+static if (_GNU_SOURCE) int remap_file_pages(void *__start, size_t __size, int __prot, size_t __pgoff, int __flags);
// int shm_open(in char *__name, int __oflag, mode_t __mode);
// int shm_unlink(in char *__name);
diff --git a/libphobos/libdruntime/core/sys/posix/aio.d b/libphobos/libdruntime/core/sys/posix/aio.d
index f4e0f122d30..a76846e91df 100644
--- a/libphobos/libdruntime/core/sys/posix/aio.d
+++ b/libphobos/libdruntime/core/sys/posix/aio.d
@@ -99,57 +99,7 @@ else version (CRuntime_Musl)
}
else version (CRuntime_UClibc)
{
- import core.sys.posix.config;
- import core.sys.posix.sys.types;
-
- struct aiocb
- {
- int aio_fildes;
- int aio_lio_opcode;
- int aio_reqprio;
- void* aio_buf; //volatile
- size_t aio_nbytes;
- sigevent aio_sigevent;
-
- aiocb* __next_prio;
- int __abs_prio;
- int __policy;
- int __error_code;
- ssize_t __return_value;
-
- static if (__USE_LARGEFILE64)
- {
- off_t aio_offset;
- ubyte[off64_t.sizeof - off_t.sizeof] __pad;
- }
- else
- {
- off64_t aio_offset;
- }
- ubyte[32] __unused;
- }
-
- static if (__USE_LARGEFILE64)
- {
- struct aiocb64
- {
- int aio_fildes;
- int aio_lio_opcode;
- int aio_reqprio;
- void* aio_buf; //volatile
- size_t aio_nbytes;
- sigevent aio_sigevent;
-
- aiocb* __next_prio;
- int __abs_prio;
- int __policy;
- int __error_code;
- ssize_t __return_value;
-
- off64_t aio_offset;
- ubyte[32] __unused;
- }
- }
+ // UClibc does not implement aiocb.
}
else version (Darwin)
{
@@ -272,15 +222,6 @@ else version (CRuntime_Musl)
AIO_ALLDONE
}
}
-else version (CRuntime_UClibc)
-{
- enum
- {
- AIO_CANCELED,
- AIO_NOTCANCELED,
- AIO_ALLDONE
- }
-}
else version (Darwin)
{
enum
@@ -328,15 +269,6 @@ else version (CRuntime_Musl)
LIO_NOP
}
}
-else version (CRuntime_UClibc)
-{
- enum
- {
- LIO_READ,
- LIO_WRITE,
- LIO_NOP
- }
-}
else version (Darwin)
{
enum
@@ -382,14 +314,6 @@ else version (CRuntime_Musl)
LIO_NOWAIT
}
}
-else version (CRuntime_UClibc)
-{
- enum
- {
- LIO_WAIT,
- LIO_NOWAIT
- }
-}
else version (Darwin)
{
enum
@@ -456,37 +380,7 @@ else version (CRuntime_Bionic)
}
else version (CRuntime_UClibc)
{
- static if (__USE_LARGEFILE64)
- {
- int aio_read64(aiocb64* aiocbp);
- int aio_write64(aiocb64* aiocbp);
- int aio_fsync64(int op, aiocb64* aiocbp);
- int aio_error64(const(aiocb64)* aiocbp);
- ssize_t aio_return64(aiocb64* aiocbp);
- int aio_suspend64(const(aiocb64*)* aiocb_list, int nitems, const(timespec)* timeout);
- int aio_cancel64(int fd, aiocb64* aiocbp);
- int lio_listio64(int mode, const(aiocb64*)* aiocb_list, int nitems, sigevent* sevp);
-
- alias aio_read = aio_read64;
- alias aio_write = aio_write64;
- alias aio_fsync = aio_fsync64;
- alias aio_error = aio_error64;
- alias aio_return = aio_return64;
- alias aio_suspend = aio_suspend64;
- alias aio_cancel = aio_cancel64;
- alias lio_listio = lio_listio64;
- }
- else
- {
- int aio_read(aiocb* aiocbp);
- int aio_write(aiocb* aiocbp);
- int aio_fsync(int op, aiocb* aiocbp);
- int aio_error(const(aiocb)* aiocbp);
- ssize_t aio_return(aiocb* aiocbp);
- int aio_suspend(const(aiocb*)* aiocb_list, int nitems, const(timespec)* timeout);
- int aio_cancel(int fd, aiocb* aiocbp);
- int lio_listio(int mode, const(aiocb*)* aiocb_list, int nitems, sigevent* sevp);
- }
+ // UClibc does not implement aio.h
}
else version (OpenBSD)
{
@@ -507,27 +401,7 @@ else
/* Functions outside/extending POSIX requirement. */
version (CRuntime_Glibc)
{
- static if (__USE_GNU)
- {
- /* To customize the implementation one can use the following struct. */
- struct aioinit
- {
- int aio_threads;
- int aio_num;
- int aio_locks;
- int aio_usedba;
- int aio_debug;
- int aio_numusers;
- int aio_idle_time;
- int aio_reserved;
- }
-
- void aio_init(const(aioinit)* init);
- }
-}
-else version (CRuntime_UClibc)
-{
- static if (__USE_GNU)
+ static if (_GNU_SOURCE)
{
/* To customize the implementation one can use the following struct. */
struct aioinit
diff --git a/libphobos/libdruntime/core/sys/posix/config.d b/libphobos/libdruntime/core/sys/posix/config.d
index 3b575fa5b48..7bd07229ea5 100644
--- a/libphobos/libdruntime/core/sys/posix/config.d
+++ b/libphobos/libdruntime/core/sys/posix/config.d
@@ -51,14 +51,24 @@ version (CRuntime_Glibc)
enum __USE_LARGEFILE = __USE_FILE_OFFSET64 && !__REDIRECT;
enum __USE_LARGEFILE64 = __USE_FILE_OFFSET64 && !__REDIRECT;
- enum __USE_XOPEN2K = _XOPEN_SOURCE >= 600;
- enum __USE_XOPEN2KXSI = _XOPEN_SOURCE >= 600;
- enum __USE_XOPEN2K8 = _XOPEN_SOURCE >= 700;
- enum __USE_XOPEN2K8XSI = _XOPEN_SOURCE >= 700;
+ deprecated("use _XOPEN_SOURCE >= 600")
+ {
+ enum __USE_XOPEN2K = _XOPEN_SOURCE >= 600;
+ enum __USE_XOPEN2KXSI = _XOPEN_SOURCE >= 600;
+ }
+ deprecated("use _XOPEN_SOURCE >= 700")
+ {
+ enum __USE_XOPEN2K8 = _XOPEN_SOURCE >= 700;
+ enum __USE_XOPEN2K8XSI = _XOPEN_SOURCE >= 700;
+ }
+ deprecated("use _DEFAULT_SOURCE")
enum __USE_MISC = _DEFAULT_SOURCE;
+ deprecated("use _ATFILE_SOURCE")
enum __USE_ATFILE = _ATFILE_SOURCE;
+ deprecated("use _GNU_SOURCE")
enum __USE_GNU = _GNU_SOURCE;
+ deprecated("use _REENTRANT")
enum __USE_REENTRANT = _REENTRANT;
version (D_LP64)
@@ -68,6 +78,10 @@ version (CRuntime_Glibc)
}
else version (CRuntime_Musl)
{
+ enum _GNU_SOURCE = false;
+ enum _DEFAULT_SOURCE = false;
+ enum _ATFILE_SOURCE = false;
+
// off_t is always 64 bits on Musl
enum _FILE_OFFSET_BITS = 64;
@@ -99,14 +113,24 @@ else version (CRuntime_UClibc)
enum __USE_LARGEFILE = __USE_FILE_OFFSET64 && !__REDIRECT;
enum __USE_LARGEFILE64 = __USE_FILE_OFFSET64 && !__REDIRECT;
- enum __USE_XOPEN2K = _XOPEN_SOURCE >= 600;
- enum __USE_XOPEN2KXSI = _XOPEN_SOURCE >= 600;
- enum __USE_XOPEN2K8 = _XOPEN_SOURCE >= 700;
- enum __USE_XOPEN2K8XSI = _XOPEN_SOURCE >= 700;
+ deprecated("use _XOPEN_SOURCE >= 600")
+ {
+ enum __USE_XOPEN2K = _XOPEN_SOURCE >= 600;
+ enum __USE_XOPEN2KXSI = _XOPEN_SOURCE >= 600;
+ }
+ deprecated("use _XOPEN_SOURCE >= 700")
+ {
+ enum __USE_XOPEN2K8 = _XOPEN_SOURCE >= 700;
+ enum __USE_XOPEN2K8XSI = _XOPEN_SOURCE >= 700;
+ }
+ deprecated("use _DEFAULT_SOURCE")
enum __USE_MISC = _DEFAULT_SOURCE;
+ deprecated("use _ATFILE_SOURCE")
enum __USE_ATFILE = _ATFILE_SOURCE;
+ deprecated("use _GNU_SOURCE")
enum __USE_GNU = _GNU_SOURCE;
+ deprecated("use _REENTRANT")
enum __USE_REENTRANT = _REENTRANT;
version (D_LP64)
@@ -117,7 +141,11 @@ else version (CRuntime_UClibc)
else version (CRuntime_Bionic)
{
enum _GNU_SOURCE = false;
+ enum _DEFAULT_SOURCE = false;
+ enum _ATFILE_SOURCE = false;
+
enum __USE_FILE_OFFSET64 = false; // see https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
+ deprecated("use _GNU_SOURCE")
enum __USE_GNU = _GNU_SOURCE;
version (D_LP64)
@@ -187,10 +215,16 @@ else version (Solaris)
enum __USE_LARGEFILE = __USE_FILE_OFFSET64 && !__REDIRECT;
enum __USE_LARGEFILE64 = __USE_FILE_OFFSET64 && !__REDIRECT;
- enum __USE_XOPEN2K = _XOPEN_SOURCE >= 600;
- enum __USE_XOPEN2KXSI = _XOPEN_SOURCE >= 600;
- enum __USE_XOPEN2K8 = _XOPEN_SOURCE >= 700;
- enum __USE_XOPEN2K8XSI = _XOPEN_SOURCE >= 700;
+ deprecated("use _XOPEN_SOURCE >= 600")
+ {
+ enum __USE_XOPEN2K = _XOPEN_SOURCE >= 600;
+ enum __USE_XOPEN2KXSI = _XOPEN_SOURCE >= 600;
+ }
+ deprecated("use _XOPEN_SOURCE >= 700")
+ {
+ enum __USE_XOPEN2K8 = _XOPEN_SOURCE >= 700;
+ enum __USE_XOPEN2K8XSI = _XOPEN_SOURCE >= 700;
+ }
version (D_LP64)
enum __WORDSIZE = 64;
diff --git a/libphobos/libdruntime/core/sys/posix/spawn.d b/libphobos/libdruntime/core/sys/posix/spawn.d
index 86b17517335..cfa3a40057c 100644
--- a/libphobos/libdruntime/core/sys/posix/spawn.d
+++ b/libphobos/libdruntime/core/sys/posix/spawn.d
@@ -100,8 +100,8 @@ version (linux)
POSIX_SPAWN_SETSCHEDPARAM = 0x10,
POSIX_SPAWN_SETSCHEDULER = 0x20
}
- import core.sys.posix.config : __USE_GNU;
- static if (__USE_GNU)
+ import core.sys.posix.config : _GNU_SOURCE;
+ static if (_GNU_SOURCE)
{
enum
{
@@ -140,8 +140,8 @@ version (linux)
POSIX_SPAWN_SETSCHEDPARAM = 16,
POSIX_SPAWN_SETSCHEDULER = 32
}
- import core.sys.posix.config : __USE_GNU;
- static if (__USE_GNU)
+ import core.sys.posix.config : _GNU_SOURCE;
+ static if (_GNU_SOURCE)
{
enum
{
@@ -196,8 +196,8 @@ version (linux)
POSIX_SPAWN_SETSCHEDPARAM = 0x10,
POSIX_SPAWN_SETSCHEDULER = 0x20
}
- import core.sys.posix.config : __USE_GNU;
- static if (__USE_GNU)
+ import core.sys.posix.config : _GNU_SOURCE;
+ static if (_GNU_SOURCE)
{
enum
{
diff --git a/libphobos/libdruntime/core/sys/posix/sys/ipc.d b/libphobos/libdruntime/core/sys/posix/sys/ipc.d
index 18a6cbd4d53..17182438e7a 100644
--- a/libphobos/libdruntime/core/sys/posix/sys/ipc.d
+++ b/libphobos/libdruntime/core/sys/posix/sys/ipc.d
@@ -83,7 +83,26 @@ version (linux)
}
else version (Darwin)
{
+ align(4) struct ipc_perm
+ {
+ uid_t uid;
+ gid_t gid;
+ uid_t cuid;
+ gid_t cgid;
+ mode_t mode;
+ ushort _seq;
+ key_t _key;
+ }
+
+ enum IPC_CREAT = 0x0200; // 01000
+ enum IPC_EXCL = 0x0400; // 02000
+ enum IPC_NOWAIT = 0x0800; // 04000
+
+ enum key_t IPC_PRIVATE = 0;
+ enum IPC_RMID = 0;
+ enum IPC_SET = 1;
+ enum IPC_STAT = 2;
}
else version (FreeBSD)
{
@@ -188,6 +207,46 @@ else version (DragonFlyBSD)
enum IPC_SET = 1;
enum IPC_STAT = 2;
}
+else version (Solaris)
+{
+ version (D_LP64)
+ {
+ struct ipc_perm
+ {
+ uid_t uid;
+ gid_t gid;
+ uid_t cuid;
+ gid_t cgid;
+ mode_t mode;
+ uint seq;
+ key_t key;
+ }
+ }
+ else
+ {
+ struct ipc_perm
+ {
+ uid_t uid;
+ gid_t gid;
+ uid_t cuid;
+ gid_t cgid;
+ mode_t mode;
+ uint seq;
+ key_t key;
+ int[4] pad;
+ }
+ }
+
+ enum IPC_CREAT = 0x200;
+ enum IPC_EXCL = 0x400;
+ enum IPC_NOWAIT = 0x800;
+
+ enum key_t IPC_PRIVATE = 0;
+
+ enum IPC_RMID = 10;
+ enum IPC_SET = 11;
+ enum IPC_STAT = 12;
+}
else
{
static assert(false, "Unsupported platform");
@@ -203,7 +262,7 @@ version (CRuntime_Glibc)
}
else version (Darwin)
{
-
+ key_t ftok(const scope char*, int);
}
else version (FreeBSD)
{
@@ -221,6 +280,10 @@ else version (DragonFlyBSD)
{
key_t ftok(const scope char*, int);
}
+else version (Solaris)
+{
+ key_t ftok(const scope char*, int);
+}
else version (CRuntime_Bionic)
{
key_t ftok(const scope char*, int);
diff --git a/libphobos/libdruntime/core/sys/posix/sys/mman.d b/libphobos/libdruntime/core/sys/posix/sys/mman.d
index 33ce88feb4e..430f21571ec 100644
--- a/libphobos/libdruntime/core/sys/posix/sys/mman.d
+++ b/libphobos/libdruntime/core/sys/posix/sys/mman.d
@@ -56,7 +56,7 @@ int posix_madvise(void*, size_t, int);
version (CRuntime_Glibc)
{
- static if (__USE_XOPEN2K)
+ static if (_XOPEN_SOURCE >= 600)
{
int posix_madvise(void *__addr, size_t __len, int __advice);
}
@@ -303,7 +303,7 @@ else version (CRuntime_Musl)
}
else version (CRuntime_UClibc)
{
- static if (__USE_LARGEFILE64) void* mmap64(void*, size_t, int, int, int, off64_t);
+ static if (__USE_LARGEFILE64) void* mmap64(void*, size_t, int, int, int, off_t);
static if (__USE_FILE_OFFSET64)
alias mmap = mmap64;
else
diff --git a/libphobos/libdruntime/core/sys/posix/sys/shm.d b/libphobos/libdruntime/core/sys/posix/sys/shm.d
index ce341418f36..d04e7926913 100644
--- a/libphobos/libdruntime/core/sys/posix/sys/shm.d
+++ b/libphobos/libdruntime/core/sys/posix/sys/shm.d
@@ -259,6 +259,18 @@ else version (CRuntime_Musl)
int shmdt(const scope void*);
int shmget(key_t, size_t, int);
}
+else version (CRuntime_Bionic)
+{
+ enum SHMLBA = 4096;
+
+ deprecated("Not useful on Android because it's disallowed by SELinux")
+ {
+ void* shmat(int, const scope void*, int);
+ int shmctl(int, int, shmid_ds*);
+ int shmdt(const scope void*);
+ int shmget(key_t, size_t, int);
+ }
+}
else version (CRuntime_UClibc)
{
int __getpagesize();
diff --git a/libphobos/libdruntime/core/sys/posix/sys/socket.d b/libphobos/libdruntime/core/sys/posix/sys/socket.d
index 670ead73c64..c1309a68c9c 100644
--- a/libphobos/libdruntime/core/sys/posix/sys/socket.d
+++ b/libphobos/libdruntime/core/sys/posix/sys/socket.d
@@ -1038,9 +1038,9 @@ else version (OpenBSD)
{
ubyte ss_len;
sa_family_t ss_family;
- byte[6] __ss_pad1;
+ ubyte[6] __ss_pad1;
long __ss_align;
- byte[240] __ss_pad2;
+ ubyte[240] __ss_pad2;
}
struct msghdr
@@ -1063,20 +1063,25 @@ else version (OpenBSD)
enum : uint
{
- SCM_RIGHTS = 0x01
+ SCM_RIGHTS = 0x01,
+ SCM_TIMESTAMP = 0x04
}
private // <sys/_types.h>
{
- extern (D) size_t _ALIGN(size_t p) { return (p + _ALIGNBYTES) & ~_ALIGNBYTES; }
+ enum _ALIGNBYTES = c_long.sizeof - 1;
+ extern (D) size_t _ALIGN(size_t p) pure nothrow @nogc
+ {
+ return (p + _ALIGNBYTES) & ~_ALIGNBYTES;
+ }
}
- extern (D) ubyte* CMSG_DATA(cmsghdr* cmsg)
+ extern (D) ubyte* CMSG_DATA(cmsghdr* cmsg) pure nothrow @nogc
{
return cast(ubyte*) cmsg + _ALIGN(cmsghdr.sizeof);
}
- extern (D) cmsghdr* CMSG_NXTHDR(msghdr* mhdr, cmsghdr* cmsg)
+ extern (D) cmsghdr* CMSG_NXTHDR(msghdr* mhdr, cmsghdr* cmsg) pure nothrow @nogc
{
if (cast(ubyte*) cmsg + _ALIGN(cmsg.cmsg_len) + _ALIGN(cmsghdr.sizeof) >
cast(ubyte*) mhdr.msg_control + mhdr.msg_controllen)
@@ -1085,11 +1090,24 @@ else version (OpenBSD)
return cast(cmsghdr*) (cast(ubyte*) cmsg + _ALIGN(cmsg.cmsg_len));
}
- extern (D) cmsghdr* CMSG_FIRSTHDR(msghdr* mhdr)
+ extern (D) cmsghdr* CMSG_FIRSTHDR(msghdr* mhdr) pure nothrow @nogc
{
return mhdr.msg_controllen >= cmsghdr.sizeof ? cast(cmsghdr*) mhdr.msg_control : null;
}
+ extern (D)
+ {
+ size_t CMSG_LEN(size_t len) pure nothrow @nogc
+ {
+ return _ALIGN(cmsghdr.sizeof) + len;
+ }
+ }
+
+ extern (D) size_t CMSG_SPACE(size_t len) pure nothrow @nogc
+ {
+ return _ALIGN(cmsghdr.sizeof) + _ALIGN(len);
+ }
+
struct linger
{
int l_onoff;
diff --git a/libphobos/libdruntime/core/sys/posix/sys/stat.d b/libphobos/libdruntime/core/sys/posix/sys/stat.d
index 51455a98e6f..22f4df66455 100644
--- a/libphobos/libdruntime/core/sys/posix/sys/stat.d
+++ b/libphobos/libdruntime/core/sys/posix/sys/stat.d
@@ -89,7 +89,7 @@ version (linux)
off_t st_size;
blksize_t st_blksize;
blkcnt_t st_blocks;
- static if (__USE_MISC || __USE_XOPEN2K8)
+ static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
{
timespec st_atim;
timespec st_mtim;
@@ -136,7 +136,7 @@ version (linux)
off_t st_size;
blksize_t st_blksize;
blkcnt_t st_blocks;
- static if (__USE_MISC || __USE_XOPEN2K8)
+ static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
{
timespec st_atim;
timespec st_mtim;
@@ -218,7 +218,7 @@ version (linux)
__blkcnt64_t st_blocks;
}
- static if ( __USE_MISC || __USE_XOPEN2K8)
+ static if ( _DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
{
__timespec st_atim;
__timespec st_mtim;
@@ -278,7 +278,7 @@ version (linux)
c_long[3] st_pad2;
off_t st_size;
}
- static if (__USE_MISC || __USE_XOPEN2K8)
+ static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
{
timespec st_atim;
timespec st_mtim;
@@ -339,7 +339,7 @@ version (linux)
uint[3] st_pad2;
off_t st_size;
}
- static if (__USE_MISC || __USE_XOPEN2K8)
+ static if (_DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
{
timespec st_atim;
timespec st_mtim;
@@ -491,7 +491,7 @@ version (linux)
__blkcnt_t st_blocks;
}
- static if (__USE_MISC)
+ static if (_DEFAULT_SOURCE)
{
__timespec st_atim;
__timespec st_mtim;
@@ -573,7 +573,7 @@ version (linux)
__blkcnt64_t st_blocks;
}
- static if ( __USE_MISC || __USE_XOPEN2K8)
+ static if ( _DEFAULT_SOURCE || _XOPEN_SOURCE >= 700)
{
__timespec st_atim;
__timespec st_mtim;
@@ -668,7 +668,7 @@ version (linux)
__blkcnt64_t st_blocks;
}
- static if (__USE_MISC)
+ static if (_DEFAULT_SOURCE)
{
__timespec st_atim;
__timespec st_mtim;
@@ -753,7 +753,7 @@ version (linux)
__blkcnt64_t st_blocks;
}
- static if (__USE_XOPEN2K8)
+ static if (_XOPEN_SOURCE >= 700)
{
__timespec st_atim;
__timespec st_mtim;
@@ -830,7 +830,7 @@ version (linux)
__blkcnt_t st_blocks;
else
__blkcnt64_t st_blocks;
- static if (__USE_XOPEN2K8)
+ static if (_XOPEN_SOURCE >= 700)
{
__timespec st_atim;
__timespec st_mtim;
@@ -894,7 +894,7 @@ version (linux)
int __glibc_reserved0;
__dev_t st_rdev;
__off_t st_size;
- static if (__USE_XOPEN2K8)
+ static if (_XOPEN_SOURCE >= 700)
{
__timespec st_atim;
__timespec st_mtim;
@@ -919,7 +919,7 @@ version (linux)
__blkcnt_t st_blocks;
c_long[3] __glibc_reserved;
}
- static if (__USE_XOPEN2K8)
+ static if (_XOPEN_SOURCE >= 700)
static assert(stat_t.sizeof == 144);
else
static assert(stat_t.sizeof == 144);
diff --git a/libphobos/libdruntime/core/sys/posix/sys/statvfs.d b/libphobos/libdruntime/core/sys/posix/sys/statvfs.d
index 49c84508b9a..df9030d6e5b 100644
--- a/libphobos/libdruntime/core/sys/posix/sys/statvfs.d
+++ b/libphobos/libdruntime/core/sys/posix/sys/statvfs.d
@@ -44,7 +44,7 @@ version (CRuntime_Glibc) {
}
/* Definitions for the flag in `f_flag'. These definitions should be
kept in sync with the definitions in <sys/mount.h>. */
- static if (__USE_GNU)
+ static if (_GNU_SOURCE)
{
enum FFlag
{
diff --git a/libphobos/libdruntime/core/sys/posix/sys/types.d b/libphobos/libdruntime/core/sys/posix/sys/types.d
index 02cf799ff27..ec229dd3b2b 100644
--- a/libphobos/libdruntime/core/sys/posix/sys/types.d
+++ b/libphobos/libdruntime/core/sys/posix/sys/types.d
@@ -322,7 +322,7 @@ else version (Darwin)
alias uint fsfilcnt_t;
alias c_long clock_t;
alias uint id_t;
- // key_t
+ alias int key_t;
alias int suseconds_t;
alias uint useconds_t;
}
diff --git a/libphobos/libdruntime/object.d b/libphobos/libdruntime/object.d
index 7bb6bec7ed9..cf7cf967aa6 100644
--- a/libphobos/libdruntime/object.d
+++ b/libphobos/libdruntime/object.d
@@ -1885,8 +1885,8 @@ class TypeInfo_Struct : TypeInfo
return false;
else if (xopEquals)
{
- const dg = _memberFunc(p2, xopEquals);
- return dg.xopEquals(p1);
+ const dg = _memberFunc(p1, xopEquals);
+ return dg.xopEquals(p2);
}
else if (p1 == p2)
return true;
diff --git a/libphobos/libdruntime/rt/util/typeinfo.d b/libphobos/libdruntime/rt/util/typeinfo.d
index 26c24c4c8f0..7b55693a720 100644
--- a/libphobos/libdruntime/rt/util/typeinfo.d
+++ b/libphobos/libdruntime/rt/util/typeinfo.d
@@ -1,8 +1,8 @@
/**
- * This module contains utilities for TypeInfo implementation.
+ * A few predefined implementations for primitive types and arrays thereof. Also a couple of helpers.
*
* Copyright: Copyright Kenji Hara 2014-.
- * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
+ * License: <a href="https://boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: Kenji Hara
* Source: $(DRUNTIMESRC rt/util/_typeinfo.d)
*/
@@ -10,100 +10,74 @@ module rt.util.typeinfo;
import rt.util.utility : d_cfloat, d_cdouble, d_creal, isComplex;
static import core.internal.hash;
-template Floating(T)
-if (is(T == float) || is(T == double) || is(T == real))
+// Three-way compare for integrals: negative if `lhs < rhs`, positive if `lhs > rhs`, 0 otherwise.
+pragma(inline, true)
+private int cmp3(T)(const T lhs, const T rhs)
+if (__traits(isIntegral, T))
{
- pure nothrow @safe:
-
- bool equals(T f1, T f2)
- {
- return f1 == f2;
- }
-
- int compare(T d1, T d2)
- {
- if (d1 != d1 || d2 != d2) // if either are NaN
- {
- if (d1 != d1)
- {
- if (d2 != d2)
- return 0;
- return -1;
- }
- return 1;
- }
- return (d1 == d2) ? 0 : ((d1 < d2) ? -1 : 1);
- }
+ static if (T.sizeof < int.sizeof)
+ // Taking the difference will always fit in an int.
+ return int(lhs) - int(rhs);
+ else
+ return (lhs > rhs) - (lhs < rhs);
+}
- public alias hashOf = core.internal.hash.hashOf;
+// Three-way compare for real fp types. NaN is smaller than all valid numbers.
+// Code is small and fast, see https://godbolt.org/z/fzb877
+pragma(inline, true)
+private int cmp3(T)(const T d1, const T d2)
+if (is(T == float) || is(T == double) || is(T == real))
+{
+ if (d2 != d2)
+ return d1 == d1; // 0 if both ar NaN, 1 if d1 is valid and d2 is NaN.
+ // If d1 is NaN, both comparisons are false so we get -1, as needed.
+ return (d1 > d2) - !(d1 >= d2);
}
-// @@@DEPRECATED_2.105@@@
-template Floating(T)
+// Three-way compare for complex types.
+pragma(inline, true)
+private int cmp3(T)(const T f1, const T f2)
if (isComplex!T)
{
- pure nothrow @safe:
-
- bool equals(T f1, T f2)
- {
- return f1.re == f2.re && f1.im == f2.im;
- }
-
- int compare(T f1, T f2)
- {
- int result;
-
- if (f1.re < f2.re)
- result = -1;
- else if (f1.re > f2.re)
- result = 1;
- else if (f1.im < f2.im)
- result = -1;
- else if (f1.im > f2.im)
- result = 1;
- else
- result = 0;
+ if (int result = cmp3(f1.re, f2.re))
return result;
- }
-
- size_t hashOf(scope const T val)
- {
- return core.internal.hash.hashOf(val.re, core.internal.hash.hashOf(val.im));
- }
+ return cmp3(f1.im, f2.im);
}
-template Array(T)
-if (is(T == float) || is(T == double) || is(T == real))
+unittest
{
- pure nothrow @safe:
-
- bool equals(T[] s1, T[] s2)
- {
- size_t len = s1.length;
- if (len != s2.length)
- return false;
- for (size_t u = 0; u < len; u++)
- {
- if (!Floating!T.equals(s1[u], s2[u]))
- return false;
- }
- return true;
- }
-
- int compare(T[] s1, T[] s2)
- {
- size_t len = s1.length;
- if (s2.length < len)
- len = s2.length;
- for (size_t u = 0; u < len; u++)
- {
- if (int c = Floating!T.compare(s1[u], s2[u]))
- return c;
- }
- return (s1.length > s2.length) - (s1.length < s2.length);
- }
-
- public alias hashOf = core.internal.hash.hashOf;
+ assert(cmp3(short.max, short.min) > 0);
+ assert(cmp3(42, 42) == 0);
+ assert(cmp3(int.max, int.min) > 0);
+
+ double x, y;
+ assert(cmp3(x, y) == 0);
+ assert(cmp3(y, x) == 0);
+ x = 42;
+ assert(cmp3(x, y) > 0);
+ assert(cmp3(y, x) < 0);
+ y = 43;
+ assert(cmp3(x, y) < 0);
+ assert(cmp3(y, x) > 0);
+ y = 42;
+ assert(cmp3(x, y) == 0);
+ assert(cmp3(y, x) == 0);
+
+ d_cdouble u, v;
+ assert(cmp3(u, v) == 0);
+ assert(cmp3(v, u) == 0);
+ u = d_cdouble(42, 42);
+ assert(cmp3(u, v) > 0);
+ assert(cmp3(v, u) < 0);
+ v = d_cdouble(43, 42);
+ assert(cmp3(u, v) < 0);
+ assert(cmp3(v, u) > 0);
+ v = d_cdouble(42, 43);
+ assert(cmp3(u, v) < 0);
+ assert(cmp3(v, u) > 0);
+ v = d_cdouble(42, 42);
+ assert(cmp3(u, v) == 0);
+ assert(cmp3(v, u) == 0);
}
// @@@DEPRECATED_2.105@@@
@@ -209,7 +183,7 @@ unittest
}();
}
-// Reduces to `T` if `cond` is `true` or `U` otherwise.
+// Reduces to `T` if `cond` is `true` or `U` otherwise. Consider moving elsewhere if useful.
private template Select(bool cond, T, U)
{
static if (cond) alias Select = T;
@@ -238,57 +212,38 @@ if (T.sizeof == Base.sizeof && T.alignof == Base.alignof)
static if (is(T == Base))
override size_t getHash(scope const void* p)
{
- static if (__traits(isFloating, T) || isComplex!T)
- return Floating!T.hashOf(*cast(T*)p);
- else
- return hashOf(*cast(const T *)p);
+ return hashOf(*cast(const T *)p);
}
// `equals` is the same for `Base` and `T`, introduce it just once.
static if (is(T == Base))
override bool equals(in void* p1, in void* p2)
{
- static if (__traits(isFloating, T) || isComplex!T)
- return Floating!T.equals(*cast(T*)p1, *cast(T*)p2);
- else
- return *cast(T *)p1 == *cast(T *)p2;
+ return *cast(const T *)p1 == *cast(const T *)p2;
}
// `T` and `Base` may have different signedness, so this function is introduced conditionally.
static if (is(T == Base) || (__traits(isIntegral, T) && T.max != Base.max))
override int compare(in void* p1, in void* p2)
{
- static if (__traits(isFloating, T) || isComplex!T)
- {
- return Floating!T.compare(*cast(T*)p1, *cast(T*)p2);
- }
- else static if (T.sizeof < int.sizeof)
- {
- // Taking the difference will always fit in an int.
- return int(*cast(T *) p1) - int(*cast(T *) p2);
- }
- else
- {
- auto lhs = *cast(T *) p1, rhs = *cast(T *) p2;
- return (lhs > rhs) - (lhs < rhs);
- }
+ return cmp3(*cast(const T*) p1, *cast(const T*) p2);
}
static if (is(T == Base))
- override @property size_t tsize() nothrow pure
+ override @property size_t tsize()
{
return T.sizeof;
}
static if (is(T == Base))
- override @property size_t talign() nothrow pure
+ override @property size_t talign()
{
return T.alignof;
}
// Override initializer only if necessary.
static if (is(T == Base) || T.init != Base.init)
- override const(void)[] initializer() @trusted
+ override const(void)[] initializer()
{
static if (__traits(isZeroInit, T))
{
@@ -311,7 +266,7 @@ if (T.sizeof == Base.sizeof && T.alignof == Base.alignof)
}
static if (is(T == Base) || RTInfo!T != RTInfo!Base)
- override @property immutable(void)* rtInfo() nothrow pure const @safe
+ override @property immutable(void)* rtInfo()
{
return RTInfo!T;
}
@@ -377,52 +332,33 @@ private class TypeInfoArrayGeneric(T, Base = T) : Select!(is(T == Base), TypeInf
static if (is(T == Base))
override size_t getHash(scope const void* p) @trusted const
{
- static if (__traits(isFloating, T) || isComplex!T)
- return Array!T.hashOf(*cast(T[]*)p);
- else
- return hashOf(*cast(const T[]*) p);
+ return hashOf(*cast(const T[]*) p);
}
static if (is(T == Base))
override bool equals(in void* p1, in void* p2) const
{
- static if (__traits(isFloating, T) || isComplex!T)
- {
- return Array!T.equals(*cast(T[]*)p1, *cast(T[]*)p2);
- }
- else
- {
- import core.stdc.string;
- auto s1 = *cast(T[]*)p1;
- auto s2 = *cast(T[]*)p2;
- return s1.length == s2.length &&
- memcmp(s1.ptr, s2.ptr, s1.length) == 0;
- }
+ // Just reuse the builtin.
+ return *cast(const(T)[]*) p1 == *cast(const(T)[]*) p2;
}
static if (is(T == Base) || (__traits(isIntegral, T) && T.max != Base.max))
override int compare(in void* p1, in void* p2) const
{
- static if (__traits(isFloating, T) || isComplex!T)
- {
- return Array!T.compare(*cast(T[]*)p1, *cast(T[]*)p2);
- }
- else
+ // Can't reuse __cmp in object.d because that handles NaN differently.
+ // (Q: would it make sense to unify behaviors?)
+ // return __cmp(*cast(const T[]*) p1, *cast(const T[]*) p2);
+ auto lhs = *cast(const T[]*) p1;
+ auto rhs = *cast(const T[]*) p2;
+ size_t len = lhs.length;
+ if (rhs.length < len)
+ len = rhs.length;
+ for (size_t u = 0; u < len; u++)
{
- auto s1 = *cast(T[]*)p1;
- auto s2 = *cast(T[]*)p2;
- auto len = s1.length;
-
- if (s2.length < len)
- len = s2.length;
- for (size_t u = 0; u < len; u++)
- {
- if (int result = (s1[u] > s2[u]) - (s1[u] < s2[u]))
- return result;
- }
- return (s1.length > s2.length) - (s1.length < s2.length);
+ if (int result = cmp3(lhs.ptr[u], rhs.ptr[u]))
+ return result;
}
- }
+ return cmp3(lhs.length, rhs.length); }
override @property inout(TypeInfo) next() inout
{
@@ -692,52 +628,37 @@ unittest
// typeof(null)
class TypeInfo_n : TypeInfo
{
- override string toString() const @safe { return "typeof(null)"; }
+ const: pure: @nogc: nothrow: @safe:
- override size_t getHash(scope const void* p) const
- {
- return 0;
- }
+ override string toString() { return "typeof(null)"; }
- override bool equals(in void* p1, in void* p2) const @trusted
- {
- return true;
- }
+ override size_t getHash(scope const void*) { return 0; }
- override int compare(in void* p1, in void* p2) const @trusted
- {
- return 0;
- }
+ override bool equals(in void*, in void*) { return true; }
- override @property size_t tsize() const
- {
- return typeof(null).sizeof;
- }
+ override int compare(in void*, in void*) { return 0; }
- override const(void)[] initializer() const @trusted
- {
- __gshared immutable void[typeof(null).sizeof] init;
- return init;
- }
+ override @property size_t tsize() { return typeof(null).sizeof; }
- override void swap(void *p1, void *p2) const @trusted
- {
- }
+ override const(void)[] initializer() @trusted { return (cast(void *)null)[0 .. size_t.sizeof]; }
- override @property immutable(void)* rtInfo() nothrow pure const @safe { return rtinfoNoPointers; }
+ override void swap(void*, void*) {}
- unittest
+ override @property immutable(void)* rtInfo() { return rtinfoNoPointers; }
+}
+
+unittest
+{
+ with (typeid(typeof(null)))
{
- with (typeid(typeof(null)))
- {
- assert(toString == "typeof(null)");
- assert(getHash(null) == 0);
- assert(equals(null, null));
- assert(compare(null, null) == 0);
- assert(tsize == typeof(null).sizeof);
- assert(initializer == new ubyte[(void*).sizeof]);
- assert(rtInfo == rtinfoNoPointers);
- }
+ assert(toString == "typeof(null)");
+ assert(getHash(null) == 0);
+ assert(equals(null, null));
+ assert(compare(null, null) == 0);
+ assert(tsize == typeof(null).sizeof);
+ assert(initializer.ptr is null);
+ assert(initializer.length == typeof(null).sizeof);
+ assert(rtInfo == rtinfoNoPointers);
}
}