7 Commits

Author SHA1 Message Date
6072bfab68 Marke SingletonByRef functions scope 2025-05-03 18:52:24 +02:00
4acf163b42 Combine dependencies and dependencies-linux
Platform dependencies aren't supported according to the dub
documentation, that states: "this setting does not support platform
suffixes".

dub test with dub 1.34.0 produces a warning:

"dependencies-linux: Key is not a valid member of this section.
Did you mean: dependencies"

Then the build fails because it cannot find modules defined in the
dependency.
2023-09-25 18:35:33 +02:00
e1fd528607 Merge remote-tracking branch 'n8sh/DMD_2.105' 2023-09-23 17:22:27 +02:00
1c57368f43 Merge remote-tracking branch 'n8sh/windows-iface-mmappool' 2023-09-23 16:16:33 +02:00
1c5e18b92e Add Windows support to tanya.memory.mmappool 2023-09-22 16:08:24 -04:00
07b388eecb Update tanya.net.iface to work on Windows
Needed because 0fcc83d00e removed
tanya.sys.windows.ifdef and tanya.sys.windows.iphlpapi.
2023-09-22 16:07:59 -04:00
20ae6465d6 Update to compile with DMD 2.105
https://dlang.org/changelog/2.105.0.html#dmd.enum-function

> enum on a function declaration had no effect other than being
> equivalent to the auto storage class when no return type was present.
> That syntax could be confused with enum manifest constants and is now
> an error... Instead, remove enum and use auto where necessary
2023-09-22 15:43:36 -04:00
5 changed files with 69 additions and 24 deletions

View File

@ -13,10 +13,7 @@
"tanya:meta": "*",
"tanya:os": "*",
"tanya:middle": "*",
"tanya:test": "*"
},
"dependencies-linux": {
"tanya:test": "*",
"mir-linux-kernel": "~>1.0.0"
},

View File

@ -2128,7 +2128,7 @@ if (isCallable!F)
}
else
{
enum getDefault(T[i .. i + 1] name)
auto getDefault(T[i .. i + 1] name)
{
return name[0];
}

View File

@ -19,6 +19,22 @@ import tanya.memory.allocator;
import tanya.memory.op;
import tanya.os.error;
version (Windows)
{
import core.sys.windows.basetsd : SIZE_T;
import core.sys.windows.windef : BOOL, DWORD;
import core.sys.windows.winnt : MEM_COMMIT, MEM_RELEASE, PAGE_READWRITE, PVOID;
extern (Windows)
private PVOID VirtualAlloc(PVOID, SIZE_T, DWORD, DWORD)
@nogc nothrow pure @system;
extern (Windows)
private BOOL VirtualFree(shared PVOID, SIZE_T, DWORD)
@nogc nothrow pure @system;
}
else
{
extern(C) pragma(mangle, "mmap")
private void* mapMemory(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
@nogc nothrow pure @system;
@ -26,6 +42,7 @@ private void* mapMemory(void *addr, size_t length, int prot, int flags, int fd,
extern(C) pragma(mangle, "munmap")
private bool unmapMemory(shared void* addr, size_t length)
@nogc nothrow pure @system;
}
/*
* This allocator allocates memory in regions (multiple of 64 KB for example).
@ -192,6 +209,9 @@ final class MmapPool : Allocator
{
block.region.next.prev = block.region.prev;
}
version (Windows)
return VirtualFree(block.region, 0, MEM_RELEASE) != 0;
else
return unmapMemory(block.region, block.region.size) == 0;
}
// Merge blocks if neigbours are free.
@ -380,6 +400,19 @@ final class MmapPool : Allocator
{
return null;
}
version (Windows)
{
void* p = VirtualAlloc(null,
regionSize,
MEM_COMMIT,
PAGE_READWRITE);
if (p is null)
{
return null;
}
}
else
{
void* p = mapMemory(null,
regionSize,
PROT_READ | PROT_WRITE,
@ -390,6 +423,7 @@ final class MmapPool : Allocator
{
return null;
}
}
Region region = cast(Region) p;
region.blocks = 1;

View File

@ -109,7 +109,7 @@ private struct SingletonByRef(E)
this.element = &element;
}
@property ref inout(E) front() inout return
@property ref inout(E) front() inout return scope
in
{
assert(!empty);
@ -148,7 +148,7 @@ private struct SingletonByRef(E)
return typeof(this)(*this.element);
}
ref inout(E) opIndex(size_t i) inout return
ref inout(E) opIndex(size_t i) inout return scope
in
{
assert(!empty);

View File

@ -22,8 +22,22 @@ import tanya.range;
version (Windows)
{
import tanya.sys.windows.ifdef;
import tanya.sys.windows.iphlpapi;
private union NET_LUID_LH { ulong Value, Info; }
private alias NET_LUID = NET_LUID_LH;
private alias NET_IFINDEX = uint;
private enum IF_MAX_STRING_SIZE = 256;
extern(Windows) @nogc nothrow private @system
{
uint ConvertInterfaceNameToLuidA(const(char)* InterfaceName,
NET_LUID* InterfaceLuid);
uint ConvertInterfaceLuidToIndex(const(NET_LUID)* InterfaceLuid,
NET_IFINDEX* InterfaceIndex);
uint ConvertInterfaceIndexToLuid(NET_IFINDEX InterfaceIndex,
NET_LUID* InterfaceLuid);
uint ConvertInterfaceLuidToNameA(const(NET_LUID)* InterfaceLuid,
char* InterfaceName,
size_t Length);
}
}
else version (Posix)
{