math.mp: Fix initialization issues after resizing
This commit is contained in:
parent
7892c1a930
commit
402fdfae89
@ -537,7 +537,7 @@ struct Integer
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private unittest
|
private @nogc unittest
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
auto h1 = Integer(1019);
|
auto h1 = Integer(1019);
|
||||||
@ -761,6 +761,7 @@ struct Integer
|
|||||||
static if (op == "/")
|
static if (op == "/")
|
||||||
{
|
{
|
||||||
auto quotient = allocator.resize!ubyte(null, bitSize / 8 + 1);
|
auto quotient = allocator.resize!ubyte(null, bitSize / 8 + 1);
|
||||||
|
quotient.initializeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
// bitPosition keeps track of which bit, of the quotient,
|
// bitPosition keeps track of which bit, of the quotient,
|
||||||
|
@ -87,8 +87,8 @@ shared Allocator allocator;
|
|||||||
|
|
||||||
shared static this() nothrow @trusted @nogc
|
shared static this() nothrow @trusted @nogc
|
||||||
{
|
{
|
||||||
import tanya.memory.mmappool;
|
import tanya.memory.mallocator;
|
||||||
allocator = MmapPool.instance;
|
allocator = Mallocator.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property ref shared(Allocator) defaultAllocator() nothrow @safe @nogc
|
@property ref shared(Allocator) defaultAllocator() nothrow @safe @nogc
|
||||||
@ -162,11 +162,22 @@ package(tanya) T[] resize(T)(shared Allocator allocator,
|
|||||||
auto ref T[] array,
|
auto ref T[] array,
|
||||||
const size_t length) @trusted
|
const size_t length) @trusted
|
||||||
{
|
{
|
||||||
void[] buf = array;
|
if (length == 0)
|
||||||
|
{
|
||||||
|
if (allocator.deallocate(array))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
onOutOfMemoryErrorNoGC();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void[] buf = array;
|
||||||
if (!allocator.reallocate(buf, length * T.sizeof))
|
if (!allocator.reallocate(buf, length * T.sizeof))
|
||||||
{
|
{
|
||||||
onOutOfMemoryError;
|
onOutOfMemoryErrorNoGC();
|
||||||
}
|
}
|
||||||
// Casting from void[] is unsafe, but we know we cast to the original type.
|
// Casting from void[] is unsafe, but we know we cast to the original type.
|
||||||
array = cast(T[]) buf;
|
array = cast(T[]) buf;
|
||||||
|
Loading…
Reference in New Issue
Block a user