@@ -822,35 +822,35 @@ struct GC
822822 * $(LINK2 https://dlang.org/spec/function.html#pure-functions, D's rules for purity),
823823 * which allow for memory allocation under specific circumstances.
824824 */
825- void * pureMalloc (size_t size) @trusted pure @nogc nothrow
825+ void * pureMalloc ()( size_t size) @trusted pure @nogc nothrow
826826{
827- const errnosave = fakePureErrno() ;
827+ const errnosave = fakePureErrno;
828828 void * ret = fakePureMalloc(size);
829- fakePureErrno() = errnosave;
829+ fakePureErrno = errnosave;
830830 return ret;
831831}
832832// / ditto
833- void * pureCalloc (size_t nmemb, size_t size) @trusted pure @nogc nothrow
833+ void * pureCalloc ()( size_t nmemb, size_t size) @trusted pure @nogc nothrow
834834{
835- const errnosave = fakePureErrno() ;
835+ const errnosave = fakePureErrno;
836836 void * ret = fakePureCalloc(nmemb, size);
837- fakePureErrno() = errnosave;
837+ fakePureErrno = errnosave;
838838 return ret;
839839}
840840// / ditto
841- void * pureRealloc (void * ptr, size_t size) @system pure @nogc nothrow
841+ void * pureRealloc ()( void * ptr, size_t size) @system pure @nogc nothrow
842842{
843- const errnosave = fakePureErrno() ;
843+ const errnosave = fakePureErrno;
844844 void * ret = fakePureRealloc(ptr, size);
845- fakePureErrno() = errnosave;
845+ fakePureErrno = errnosave;
846846 return ret;
847847}
848848// / ditto
849- void pureFree (void * ptr) @system pure @nogc nothrow
849+ void pureFree ()( void * ptr) @system pure @nogc nothrow
850850{
851- const errnosave = fakePureErrno() ;
851+ const errnosave = fakePureErrno;
852852 fakePureFree(ptr);
853- fakePureErrno() = errnosave;
853+ fakePureErrno = errnosave;
854854}
855855
856856// /
@@ -900,6 +900,37 @@ void pureFree(void* ptr) @system pure @nogc nothrow
900900
901901// locally purified for internal use here only
902902
903+ static import core.stdc.errno ;
904+ static if (__traits(getOverloads, core.stdc.errno , " errno" ).length == 1
905+ && __traits(getLinkage, core.stdc.errno.errno ) == " C" )
906+ {
907+ extern (C ) pragma (mangle, __traits(identifier, core.stdc.errno.errno ))
908+ private ref int fakePureErrno () @nogc nothrow pure @system ;
909+ }
910+ else
911+ {
912+ extern (C ) private @nogc nothrow pure @system
913+ {
914+ pragma (mangle, __traits (identifier, core.stdc.errno.getErrno ))
915+ private int fakePureGetErrno ();
916+
917+ pragma (mangle, __traits (identifier, core.stdc.errno.setErrno ))
918+ private int fakePureSetErrno (int );
919+ }
920+
921+ private @property int fakePureErrno()() @nogc nothrow pure @system
922+ {
923+ return fakePureGetErrno ();
924+ }
925+
926+ private @property void fakePureErrno()(int newValue) @nogc nothrow pure @system
927+ {
928+ fakePureSetErrno(newValue);
929+ }
930+ }
931+
932+ version (D_BetterC ) {}
933+ else // TODO: remove this function after Phobos no longer needs it.
903934extern (C ) private @system @nogc nothrow
904935{
905936 ref int fakePureErrnoImpl ()
@@ -911,8 +942,6 @@ extern (C) private @system @nogc nothrow
911942
912943extern (C ) private pure @system @nogc nothrow
913944{
914- pragma (mangle, " fakePureErrnoImpl" ) ref int fakePureErrno();
915-
916945 pragma (mangle, " malloc" ) void * fakePureMalloc(size_t );
917946 pragma (mangle, " calloc" ) void * fakePureCalloc(size_t nmemb, size_t size);
918947 pragma (mangle, " realloc" ) void * fakePureRealloc(void * ptr, size_t size);
0 commit comments