Skip to content

Commit

Permalink
Get rid of obsolete CRuntime_DigitalMars support
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke authored and dlang-bot committed May 25, 2024
1 parent 38fa9c3 commit acd2013
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 431 deletions.
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);
}
}
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
19 changes: 6 additions & 13 deletions std/process.d
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,19 @@ else version (WatchOS)
version = iOSDerived;
}

// When the DMC runtime is used, we have to use some custom functions
// to convert between Windows file handles and FILE*s.
version (Win32) version (CRuntime_DigitalMars) version = DMC_RUNTIME;


// Some of the following should be moved to druntime.
private
{
// Microsoft Visual C Runtime (MSVCRT) declarations.
version (Windows)
version (CRuntime_Microsoft)
{
version (DMC_RUNTIME) { } else
import core.stdc.stdint;
enum
{
import core.stdc.stdint;
enum
{
STDIN_FILENO = 0,
STDOUT_FILENO = 1,
STDERR_FILENO = 2,
}
STDIN_FILENO = 0,
STDOUT_FILENO = 1,
STDERR_FILENO = 2,
}
}

Expand Down
Loading

0 comments on commit acd2013

Please sign in to comment.