Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed Jul 1, 2024
2 parents 539dc47 + 312a86d commit 992cc83
Show file tree
Hide file tree
Showing 17 changed files with 191 additions and 555 deletions.
2 changes: 1 addition & 1 deletion .dscanner.ini
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ redundant_attributes_check="-std.concurrency,-std.digest.md,-std.digest.ripemd,-
style_check="+disabled"
;style_check="-etc.c.curl,-etc.c.odbc.sqlext,-etc.c.odbc.sqltypes,-etc.c.odbc.sqlucode,-etc.c.sqlite3,-etc.c.zlib,-std.algorithm.comparison,-std.algorithm.internal,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.sorting,-std.array,-std.base64,-std.bitmanip,-std.c.linux.linux,-std.compiler,-std.container.array,-std.conv,-std.datetime.date,-std.datetime.interval,-std.datetime.systime,-std.digest,-std.digest.murmurhash,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.bucketizer,-std.experimental.allocator.building_blocks.fallback_allocator,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.null_allocator,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.building_blocks.segregator,-std.experimental.allocator.common,-std.experimental.allocator.gc_allocator,-std.experimental.allocator.mallocator,-std.experimental.allocator.mmap_allocator,-std.experimental.checkedint,-std.format,-std.functional,-std.getopt,-std.internal.digest.sha_SSSE3,-std.internal.math.errorfunction,-std.internal.math.gammafunction,-std.internal.test.dummyrange,-std.internal.unicode_tables,-std.json,-std.math,-std.meta,-std.numeric,-std.parallelism,-std.path,-std.process,-std.random,-std.range,-std.range.primitives,-std.regex,-std.regex.internal.ir,-std.regex.internal.kickstart,-std.signals,-std.socket,-std.stdio,-std.string,-std.uni,-std.uri,-std.utf,-std.uuid,-std.variant,-std.zlib"
; Checks for undocumented public declarations
undocumented_declaration_check="-etc.c.curl,-etc.c.odbc.sql,-etc.c.odbc.sqlext,-etc.c.odbc.sqltypes,-etc.c.odbc.sqlucode,-etc.c.sqlite3,-etc.c.zlib,-std.algorithm.sorting,-std.array,-std.ascii,-std.base64,-std.bitmanip,-std.c.linux.linux,-std.c.linux.socket,-std.c.osx.socket,-std.c.process,-std.compiler,-std.complex,-std.concurrency,-std.container,-std.container.array,-std.container.binaryheap,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.conv,-std.csv,-std.datetime,-std.datetime.date,-std.digest,-std.digest.hmac,-std.digest.md,-std.digest.murmurhash,-std.digest.ripemd,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.fallback_allocator,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.quantizer,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.building_blocks.segregator,-std.experimental.allocator.building_blocks.stats_collector,-std.experimental.allocator.gc_allocator,-std.experimental.allocator.mallocator,-std.experimental.checkedint,-std.logger.core,-std.file,-std.format,-std.functional,-std.internal.digest.sha_SSSE3,-std.internal.math.biguintcore,-std.internal.math.biguintnoasm,-std.internal.math.biguintx86,-std.internal.math.errorfunction,-std.internal.math.gammafunction,-std.internal.test.dummyrange,-std.internal.test.uda,-std.internal.windows.advapi32,-std.json,-std.math,-std.mmfile,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.process,-std.regex,-std.regex.internal.parser,-std.signals,-std.socket,-std.stdio,-std.string,-std.system,-std.traits,-std.uni,-std.utf,-std.variant,-std.windows.charset,-std.windows.registry,-std.windows.syserror,-std.zip,-std.zlib,-std.int128"
undocumented_declaration_check="-etc.c.curl,-etc.c.odbc.sql,-etc.c.odbc.sqlext,-etc.c.odbc.sqltypes,-etc.c.odbc.sqlucode,-etc.c.sqlite3,-etc.c.zlib,-std.algorithm.sorting,-std.array,-std.ascii,-std.base64,-std.bitmanip,-std.c.linux.linux,-std.c.linux.socket,-std.c.osx.socket,-std.c.process,-std.compiler,-std.complex,-std.concurrency,-std.container,-std.container.array,-std.container.binaryheap,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.conv,-std.csv,-std.datetime,-std.datetime.date,-std.digest,-std.digest.hmac,-std.digest.md,-std.digest.murmurhash,-std.digest.ripemd,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.allocator_list,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.fallback_allocator,-std.experimental.allocator.building_blocks.free_list,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.quantizer,-std.experimental.allocator.building_blocks.region,-std.experimental.allocator.building_blocks.segregator,-std.experimental.allocator.building_blocks.stats_collector,-std.experimental.allocator.gc_allocator,-std.experimental.allocator.mallocator,-std.experimental.checkedint,-std.logger.core,-std.file,-std.format,-std.functional,-std.internal.digest.sha_SSSE3,-std.internal.math.biguintcore,-std.internal.math.biguintnoasm,-std.internal.math.biguintx86,-std.internal.math.errorfunction,-std.internal.math.gammafunction,-std.internal.test.dummyrange,-std.internal.test.sumtype_example_overloads,-std.internal.test.uda,-std.internal.windows.advapi32,-std.json,-std.math,-std.mmfile,-std.numeric,-std.outbuffer,-std.parallelism,-std.path,-std.process,-std.regex,-std.regex.internal.parser,-std.signals,-std.socket,-std.stdio,-std.string,-std.system,-std.traits,-std.uni,-std.utf,-std.variant,-std.windows.charset,-std.windows.registry,-std.windows.syserror,-std.zip,-std.zlib,-std.int128"
; Checks for unused labels
unused_label_check="-std.conv,-std.internal.math.biguintx86,-std.regex.internal.thompson,-std.signals,-std.uni"
; Checks for unused function parameters
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# make BUILD=debug => makes debug build of the library
#
# make unittest => builds all unittests (for debug AND release) and runs them
# make std/somemodule.test => only builds and unittests std.somemodule
# make std/somepackage.test => only builds and unittests modules in std.somepackage
# make unittest/std/somemodule.run => run std.somemodule unittest
#
# make BUILD=debug unittest => builds all unittests (for debug) and runs them
#
Expand All @@ -25,8 +28,6 @@
#
# make install => copies library to /usr/lib
#
# make std/somemodule.test => only builds and unittests std.somemodule
#
################################################################################
# Configurable stuff, usually from the command line
#
Expand Down Expand Up @@ -272,6 +273,7 @@ EXTRA_MODULES_INTERNAL := $(addprefix std/, \
$(addprefix math/, biguintcore biguintnoasm biguintx86 \
errorfunction gammafunction ) \
scopebuffer test/dummyrange test/range \
test/sumtype_example_overloads \
$(addprefix unicode_, comp decomp grapheme norm tables) \
windows/advapi32 \
) \
Expand Down
7 changes: 7 additions & 0 deletions std/bitmanip.d
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ private struct FloatingPointRepresentation(T)
Allows manipulating the fraction, exponent, and sign parts of a
`float` separately. The definition is:
$(RUNNABLE_EXAMPLE
----
struct FloatRep
{
Expand All @@ -819,6 +820,7 @@ struct FloatRep
enum uint bias = 127, fractionBits = 23, exponentBits = 8, signBits = 1;
}
----
)
*/
alias FloatRep = FloatingPointRepresentation!float;

Expand Down Expand Up @@ -874,6 +876,7 @@ alias FloatRep = FloatingPointRepresentation!float;
Allows manipulating the fraction, exponent, and sign parts of a
`double` separately. The definition is:
$(RUNNABLE_EXAMPLE
----
struct DoubleRep
{
Expand All @@ -888,6 +891,7 @@ struct DoubleRep
enum uint bias = 1023, signBits = 1, fractionBits = 52, exponentBits = 11;
}
----
)
*/
alias DoubleRep = FloatingPointRepresentation!double;

Expand Down Expand Up @@ -1050,6 +1054,8 @@ public:
of a type different than `size_t`, firstly because its length should
be a multiple of `size_t.sizeof`, and secondly because how the bits
are mapped:
$(RUNNABLE_EXAMPLE
---
size_t[] source = [1, 2, 3, 3424234, 724398, 230947, 389492];
enum sbits = size_t.sizeof * 8;
Expand All @@ -1060,6 +1066,7 @@ public:
assert(ba[n] == nth_bit);
}
---
)
The least significant bit in any `size_t` unit is the starting bit of this
unit, and the most significant bit is the last bit of this unit. Therefore,
passing e.g. an array of `int`s may result in a different `BitArray`
Expand Down
137 changes: 4 additions & 133 deletions std/experimental/allocator/mallocator.d
Original file line number Diff line number Diff line change
Expand Up @@ -116,93 +116,11 @@ struct Mallocator
test!Mallocator();
}

version (Windows)
version (CRuntime_Microsoft)
{
// DMD Win 32 bit, DigitalMars C standard library misses the _aligned_xxx
// functions family (snn.lib)
version (CRuntime_DigitalMars)
{
// Helper to cast the infos written before the aligned pointer
// this header keeps track of the size (required to realloc) and of
// the base ptr (required to free).
private struct AlignInfo
{
void* basePtr;
size_t size;

@nogc nothrow
static AlignInfo* opCall(void* ptr)
{
return cast(AlignInfo*) (ptr - AlignInfo.sizeof);
}
}

@nogc nothrow
private void* _aligned_malloc(size_t size, size_t alignment)
{
import core.stdc.stdlib : malloc;
size_t offset = alignment + size_t.sizeof * 2 - 1;

// unaligned chunk
void* basePtr = malloc(size + offset);
if (!basePtr) return null;

// get aligned location within the chunk
void* alignedPtr = cast(void**)((cast(size_t)(basePtr) + offset)
& ~(alignment - 1));

// write the header before the aligned pointer
AlignInfo* head = AlignInfo(alignedPtr);
head.basePtr = basePtr;
head.size = size;

return alignedPtr;
}

@nogc nothrow
private void* _aligned_realloc(void* ptr, size_t size, size_t alignment)
{
import core.stdc.stdlib : free;
import core.stdc.string : memcpy;

if (!ptr) return _aligned_malloc(size, alignment);

// gets the header from the exising pointer
AlignInfo* head = AlignInfo(ptr);

// gets a new aligned pointer
void* alignedPtr = _aligned_malloc(size, alignment);
if (!alignedPtr)
{
//to https://msdn.microsoft.com/en-us/library/ms235462.aspx
//see Return value: in this case the original block is unchanged
return null;
}

// copy exising data
memcpy(alignedPtr, ptr, head.size);
free(head.basePtr);

return alignedPtr;
}

@nogc nothrow
private void _aligned_free(void *ptr)
{
import core.stdc.stdlib : free;
if (!ptr) return;
AlignInfo* head = AlignInfo(ptr);
free(head.basePtr);
}

}
// DMD Win 64 bit, uses microsoft standard C library which implements them
else
{
@nogc nothrow private extern(C) void* _aligned_malloc(size_t, size_t);
@nogc nothrow private extern(C) void _aligned_free(void *memblock);
@nogc nothrow private extern(C) void* _aligned_realloc(void *, size_t, size_t);
}
@nogc nothrow private extern(C) void* _aligned_malloc(size_t, size_t);
@nogc nothrow private extern(C) void _aligned_free(void *memblock);
@nogc nothrow private extern(C) void* _aligned_realloc(void *, size_t, size_t);
}

/**
Expand Down Expand Up @@ -399,50 +317,3 @@ version (Posix)
assert(!AlignedMallocator.instance.alignedReallocate(c, size_t.max, 4096));
AlignedMallocator.instance.deallocate(c);
}

version (CRuntime_DigitalMars)
@nogc @system nothrow unittest
{
void* m;

size_t m_addr() { return cast(size_t) m; }

m = _aligned_malloc(16, 0x10);
if (m)
{
assert((m_addr & 0xF) == 0);
_aligned_free(m);
}

m = _aligned_malloc(16, 0x100);
if (m)
{
assert((m_addr & 0xFF) == 0);
_aligned_free(m);
}

m = _aligned_malloc(16, 0x1000);
if (m)
{
assert((m_addr & 0xFFF) == 0);
_aligned_free(m);
}

m = _aligned_malloc(16, 0x10);
if (m)
{
assert((cast(size_t) m & 0xF) == 0);
m = _aligned_realloc(m, 32, 0x10000);
if (m) assert((m_addr & 0xFFFF) == 0);
_aligned_free(m);
}

m = _aligned_malloc(8, 0x10);
if (m)
{
*cast(ulong*) m = 0X01234567_89ABCDEF;
m = _aligned_realloc(m, 0x800, 0x1000);
if (m) assert(*cast(ulong*) m == 0X01234567_89ABCDEF);
_aligned_free(m);
}
}
20 changes: 8 additions & 12 deletions std/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -4053,12 +4053,10 @@ else version (Posix)
+/
void _ensureStatDone() @trusted scope
{
import std.exception : enforce;

if (_didStat)
return;

enforce(stat(_name.tempCString(), &_statBuf) == 0,
cenforce(stat(_name.tempCString(), &_statBuf) == 0,
"Failed to stat file `" ~ _name ~ "'");

_didStat = true;
Expand Down Expand Up @@ -4095,13 +4093,11 @@ else version (Posix)
+/
void _ensureLStatDone() @trusted scope
{
import std.exception : enforce;

if (_didLStat)
return;

stat_t statbuf = void;
enforce(lstat(_name.tempCString(), &statbuf) == 0,
cenforce(lstat(_name.tempCString(), &statbuf) == 0,
"Failed to stat file `" ~ _name ~ "'");

_lstatMode = statbuf.st_mode;
Expand Down Expand Up @@ -4183,12 +4179,12 @@ else version (Posix)
assert(!de.isFile);
assert(!de.isDir);
assert(de.isSymlink);
assertThrown(de.size);
assertThrown(de.timeStatusChanged);
assertThrown(de.timeLastAccessed);
assertThrown(de.timeLastModified);
assertThrown(de.attributes);
assertThrown(de.statBuf);
assertThrown!FileException(de.size);
assertThrown!FileException(de.timeStatusChanged);
assertThrown!FileException(de.timeLastAccessed);
assertThrown!FileException(de.timeLastModified);
assertThrown!FileException(de.attributes);
assertThrown!FileException(de.statBuf);
assert(symfile.exists);
symfile.remove();
}
Expand Down
6 changes: 3 additions & 3 deletions std/format/spec.d
Original file line number Diff line number Diff line change
Expand Up @@ -681,21 +681,21 @@ if (is(Unqual!Char == Char))
auto fmt = "Number: %6.4e\nString: %s";
auto f = FormatSpec!char(fmt);

assert(f.writeUpToNextSpec(a) == true);
assert(f.writeUpToNextSpec(a));

assert(a.data == "Number: ");
assert(f.trailing == "\nString: %s");
assert(f.spec == 'e');
assert(f.width == 6);
assert(f.precision == 4);

assert(f.writeUpToNextSpec(a) == true);
assert(f.writeUpToNextSpec(a));

assert(a.data == "Number: \nString: ");
assert(f.trailing == "");
assert(f.spec == 's');

assert(f.writeUpToNextSpec(a) == false);
assert(!f.writeUpToNextSpec(a));

assert(a.data == "Number: \nString: ");
}
Expand Down
17 changes: 17 additions & 0 deletions std/internal/test/sumtype_example_overloads.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/++
For testing only.
Overload set used in std.sumtype example. Needs its own internal module so that
it can be available for `make publictests` without polluting the public API.
+/
module std.internal.test.sumtype_example_overloads;

import std.sumtype;

@safe
{
string handle(int) { return "got an int"; }
string handle(string) { return "got a string"; }
string handle(double) { return "got a double"; }
alias handle = match!handle;
}
2 changes: 1 addition & 1 deletion std/math/exponential.d
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ if (isFloatingPoint!(F) && isIntegral!(G))
* If x is 0 and n is negative, the result is the same as the result of a
* division by zero.
*/
typeof(Unqual!(F).init * Unqual!(G).init) pow(F, G)(F x, G n) @nogc @trusted pure nothrow
typeof(Unqual!(F).init * Unqual!(G).init) pow(F, G)(F x, G n) @nogc @safe pure nothrow
if (isIntegral!(F) && isIntegral!(G))
{
import std.traits : isSigned;
Expand Down
17 changes: 4 additions & 13 deletions std/math/rounding.d
Original file line number Diff line number Diff line change
Expand Up @@ -772,27 +772,18 @@ version (Posix)
*
* If the fractional part of x is exactly 0.5, the return value is rounded
* away from zero.
*
* $(BLUE This function is not implemented for Digital Mars C runtime.)
*/
long lround(real x) @trusted nothrow @nogc
{
version (CRuntime_DigitalMars)
assert(0, "lround not implemented");
else
return core.stdc.math.llroundl(x);
return core.stdc.math.llroundl(x);
}

///
@safe nothrow @nogc unittest
{
version (CRuntime_DigitalMars) {}
else
{
assert(lround(0.49) == 0);
assert(lround(0.5) == 1);
assert(lround(1.5) == 2);
}
assert(lround(0.49) == 0);
assert(lround(0.5) == 1);
assert(lround(1.5) == 2);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions std/net/curl.d
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ private auto _basicHTTP(T)(const(char)[] url, const(void)[] sendData, HTTP clien
{
size_t minLen = min(buf.length, remainingData.length);
if (minLen == 0) return 0;
buf[0 .. minLen] = remainingData[0 .. minLen];
buf[0 .. minLen] = cast(void[]) remainingData[0 .. minLen];
remainingData = remainingData[minLen..$];
return minLen;
};
Expand Down Expand Up @@ -1202,7 +1202,7 @@ private auto _basicFTP(T)(const(char)[] url, const(void)[] sendData, FTP client)
{
size_t minLen = min(buf.length, sendData.length);
if (minLen == 0) return 0;
buf[0 .. minLen] = sendData[0 .. minLen];
buf[0 .. minLen] = cast(void[]) sendData[0 .. minLen];
sendData = sendData[minLen..$];
return minLen;
};
Expand Down
Loading

0 comments on commit 992cc83

Please sign in to comment.