diff --git a/src/core/memory.d b/src/core/memory.d index 5ec946d269..7020a72ac2 100644 --- a/src/core/memory.d +++ b/src/core/memory.d @@ -91,9 +91,10 @@ private extern (C) void gc_collect() nothrow; extern (C) void gc_minimize() nothrow; - extern (C) uint gc_getAttr( void* p ) pure nothrow; - extern (C) uint gc_setAttr( void* p, uint a ) pure nothrow; - extern (C) uint gc_clrAttr( void* p, uint a ) pure nothrow; + extern (C) uint gc_getAttr( in void* p ) pure nothrow; + extern (C) uint gc_setAttr( in void* p, uint a ) pure nothrow; + extern (C) uint gc_clrAttr( in void* p, uint a ) pure nothrow; + extern (C) uint gc_isCollecting( in void* p ); // pure nothrow??? extern (C) void* gc_malloc( size_t sz, uint ba = 0 ) pure nothrow; extern (C) void* gc_calloc( size_t sz, uint ba = 0 ) pure nothrow; @@ -103,8 +104,9 @@ private extern (C) size_t gc_reserve( size_t sz ) nothrow; extern (C) void gc_free( void* p ) pure nothrow; - extern (C) void* gc_addrOf( void* p ) pure nothrow; - extern (C) size_t gc_sizeOf( void* p ) pure nothrow; + extern (C) void* gc_addrOf( in void* p ) pure nothrow; + extern (C) size_t gc_sizeOf( in void* p ) pure nothrow; + extern (C) BlkInfo_ gc_query( in void* p ) pure nothrow; struct BlkInfo_ { @@ -113,8 +115,6 @@ private uint attr; } - extern (C) BlkInfo_ gc_query( void* p ) pure nothrow; - extern (C) void gc_addRoot( in void* p ) nothrow; extern (C) void gc_addRange( in void* p, size_t sz ) nothrow; diff --git a/src/object.di b/src/object.di index 7c288e80ff..c40be04174 100644 --- a/src/object.di +++ b/src/object.di @@ -544,8 +544,8 @@ template _isStaticArray(T) private { - extern (C) void _d_arrayshrinkfit(TypeInfo ti, void[] arr); - extern (C) size_t _d_arraysetcapacity(TypeInfo ti, size_t newcapacity, void *arrptr) pure nothrow; + extern (C) void _d_arrayshrinkfit(TypeInfo ti, void[] arr) pure nothrow; //not actually pure + extern (C) size_t _d_arraysetcapacity(TypeInfo ti, size_t newcapacity, void *arrptr) pure nothrow; //not actually pure or nothrow } @property size_t capacity(T)(T[] arr) pure nothrow @@ -558,7 +558,7 @@ size_t reserve(T)(ref T[] arr, size_t newcapacity) pure nothrow @trusted return _d_arraysetcapacity(typeid(T[]), newcapacity, cast(void *)&arr); } -auto ref inout(T[]) assumeSafeAppend(T)(auto ref inout(T[]) arr) +auto ref inout(T[]) assumeSafeAppend(T)(auto ref inout(T[]) arr) pure nothrow { _d_arrayshrinkfit(typeid(T[]), *(cast(void[]*)&arr)); return arr; diff --git a/src/object_.d b/src/object_.d index f8b68eacca..c46515ed72 100644 --- a/src/object_.d +++ b/src/object_.d @@ -33,7 +33,7 @@ private extern (C) void onOutOfMemoryError(); extern (C) Object _d_newclass(const TypeInfo_Class ci); - extern (C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr); + extern (C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr) pure nothrow; //not actually pure extern (C) size_t _d_arraysetcapacity(const TypeInfo ti, size_t newcapacity, void *arrptr) pure nothrow; extern (C) void rt_finalize(void *data, bool det=true); } @@ -2500,7 +2500,7 @@ unittest * Returns: * The input is returned. */ -auto ref inout(T[]) assumeSafeAppend(T)(auto ref inout(T[]) arr) +auto ref inout(T[]) assumeSafeAppend(T)(auto ref inout(T[]) arr) pure nothrow { _d_arrayshrinkfit(typeid(T[]), *(cast(void[]*)&arr)); return arr; diff --git a/src/rt/lifetime.d b/src/rt/lifetime.d index 260c83f523..6358dd666f 100644 --- a/src/rt/lifetime.d +++ b/src/rt/lifetime.d @@ -40,20 +40,22 @@ private uint attr; } - extern (C) uint gc_getAttr( in void* p ); - extern (C) uint gc_isCollecting( in void* p ); - extern (C) uint gc_setAttr( in void* p, uint a ); - extern (C) uint gc_clrAttr( in void* p, uint a ); - - extern (C) void* gc_malloc( size_t sz, uint ba = 0 ); - extern (C) BlkInfo gc_qalloc( size_t sz, uint ba = 0 ); - extern (C) void* gc_calloc( size_t sz, uint ba = 0 ); - extern (C) size_t gc_extend( void* p, size_t mx, size_t sz ); - extern (C) void gc_free( void* p ); - - extern (C) void* gc_addrOf( in void* p ); - extern (C) size_t gc_sizeOf( in void* p ); - extern (C) BlkInfo gc_query( in void* p ); + extern (C) uint gc_getAttr( in void* p ) pure nothrow; + extern (C) uint gc_setAttr( in void* p, uint a ) pure nothrow; + extern (C) uint gc_clrAttr( in void* p, uint a ) pure nothrow; + extern (C) uint gc_isCollecting( in void* p ); // pure nothrow??? + + extern (C) void* gc_malloc( size_t sz, uint ba = 0 ) pure nothrow; + extern (C) void* gc_calloc( size_t sz, uint ba = 0 ) pure nothrow; + extern (C) BlkInfo gc_qalloc( size_t sz, uint ba = 0 ) pure nothrow; + extern (C) void* gc_realloc( void* p, size_t sz, uint ba = 0 ) pure nothrow; + extern (C) size_t gc_extend( void* p, size_t mx, size_t sz ); + extern (C) size_t gc_reserve( size_t sz ) nothrow; + extern (C) void gc_free( void* p ) pure nothrow; + + extern (C) void* gc_addrOf( in void* p ) pure nothrow; + extern (C) size_t gc_sizeOf( in void* p ) pure nothrow; + extern (C) BlkInfo gc_query( in void* p ) pure nothrow; extern (C) void onFinalizeError( ClassInfo c, Throwable e ); extern (C) void onOutOfMemoryError(); @@ -236,21 +238,31 @@ private class ArrayAllocLengthLock where elem0 starts 16 bytes after the first byte. */ -bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, size_t oldlength = ~0) +bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, size_t oldlength) pure { + mixin(__setArrayAllocLengthImpl); +} +/// ditto +bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool /+isshared+/) nothrow pure +{ + mixin(__setArrayAllocLengthImpl); +} + +enum __setArrayAllocLengthImpl = +q{ if(info.size <= 256) { if(newlength + SMALLPAD > info.size) // new size does not fit inside block return false; auto length = cast(ubyte *)(info.base + info.size - SMALLPAD); - if(oldlength != ~0) + static if(is(typeof(oldlength))) { if(isshared) { synchronized(typeid(ArrayAllocLengthLock)) { - if(*length == cast(ubyte)oldlength) + if(*length == oldlength) *length = cast(ubyte)newlength; else return false; @@ -258,7 +270,7 @@ bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, si } else { - if(*length == cast(ubyte)oldlength) + if(*length == oldlength) *length = cast(ubyte)newlength; else return false; @@ -276,7 +288,7 @@ bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, si // new size does not fit inside block return false; auto length = cast(ushort *)(info.base + info.size - MEDPAD); - if(oldlength != ~0) + static if(is(typeof(oldlength))) { if(isshared) { @@ -308,14 +320,14 @@ bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, si // new size does not fit inside block return false; auto length = cast(size_t *)(info.base); - if(oldlength != ~0) + static if(is(typeof(oldlength))) { if(isshared) { synchronized(typeid(ArrayAllocLengthLock)) { if(*length == oldlength) - *length = newlength; + *length = cast(size_t)newlength; else return false; } @@ -323,7 +335,7 @@ bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, si else { if(*length == oldlength) - *length = newlength; + *length = cast(size_t)newlength; else return false; } @@ -335,7 +347,7 @@ bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, si } } return true; // resize succeeded -} +}; /** get the start of the array for the given block @@ -549,7 +561,7 @@ void __insertBlkInfoCache(BlkInfo bi, BlkInfo *curpos) nothrow * It doesn't matter what the current allocated length of the array is, the * user is telling the runtime that he knows what he is doing. */ -extern(C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr) +extern(C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr) nothrow { // note, we do not care about shared. We are setting the length no matter // what, so no lock is required.