@@ -822,35 +822,35 @@ struct GC
822
822
* $(LINK2 https://dlang.org/spec/function.html#pure-functions, D's rules for purity),
823
823
* which allow for memory allocation under specific circumstances.
824
824
*/
825
- void * pureMalloc (size_t size) @trusted pure @nogc nothrow
825
+ void * pureMalloc ()( size_t size) @trusted pure @nogc nothrow
826
826
{
827
- const errnosave = fakePureErrno() ;
827
+ const errnosave = fakePureErrno;
828
828
void * ret = fakePureMalloc(size);
829
- fakePureErrno() = errnosave;
829
+ fakePureErrno = errnosave;
830
830
return ret;
831
831
}
832
832
// / 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
834
834
{
835
- const errnosave = fakePureErrno() ;
835
+ const errnosave = fakePureErrno;
836
836
void * ret = fakePureCalloc(nmemb, size);
837
- fakePureErrno() = errnosave;
837
+ fakePureErrno = errnosave;
838
838
return ret;
839
839
}
840
840
// / 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
842
842
{
843
- const errnosave = fakePureErrno() ;
843
+ const errnosave = fakePureErrno;
844
844
void * ret = fakePureRealloc(ptr, size);
845
- fakePureErrno() = errnosave;
845
+ fakePureErrno = errnosave;
846
846
return ret;
847
847
}
848
848
// / ditto
849
- void pureFree (void * ptr) @system pure @nogc nothrow
849
+ void pureFree ()( void * ptr) @system pure @nogc nothrow
850
850
{
851
- const errnosave = fakePureErrno() ;
851
+ const errnosave = fakePureErrno;
852
852
fakePureFree(ptr);
853
- fakePureErrno() = errnosave;
853
+ fakePureErrno = errnosave;
854
854
}
855
855
856
856
// /
@@ -900,6 +900,37 @@ void pureFree(void* ptr) @system pure @nogc nothrow
900
900
901
901
// locally purified for internal use here only
902
902
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.
903
934
extern (C ) private @system @nogc nothrow
904
935
{
905
936
ref int fakePureErrnoImpl ()
@@ -911,8 +942,6 @@ extern (C) private @system @nogc nothrow
911
942
912
943
extern (C ) private pure @system @nogc nothrow
913
944
{
914
- pragma (mangle, " fakePureErrnoImpl" ) ref int fakePureErrno();
915
-
916
945
pragma (mangle, " malloc" ) void * fakePureMalloc(size_t );
917
946
pragma (mangle, " calloc" ) void * fakePureCalloc(size_t nmemb, size_t size);
918
947
pragma (mangle, " realloc" ) void * fakePureRealloc(void * ptr, size_t size);
0 commit comments