Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Add explicit @system attribute to extern functions #3117

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/core/demangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -2400,10 +2400,10 @@ private template hasPlainMangling(FT) if (is(FT == function))

@safe pure nothrow unittest
{
static extern(D) void fooD();
static extern(C) void fooC();
static extern(Windows) void fooW();
static extern(C++) void fooCPP();
static extern(D) void fooD() @system;
static extern(C) void fooC() @system;
static extern(Windows) void fooW() @system;
static extern(C++) void fooCPP() @system;

bool check(FT)(bool isD, bool isCPP, bool isPlain)
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/internal/array/capacity.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
module core.internal.array.capacity;

// HACK: `nothrow` and `pure` is faked.
private extern (C) void[] _d_arraysetlengthT(const TypeInfo ti, size_t newlength, void[]* p) nothrow pure;
private extern (C) void[] _d_arraysetlengthiT(const TypeInfo ti, size_t newlength, void[]* p) nothrow pure;
private extern (C) void[] _d_arraysetlengthT(const TypeInfo ti, size_t newlength, void[]* p) nothrow pure @system;
private extern (C) void[] _d_arraysetlengthiT(const TypeInfo ti, size_t newlength, void[]* p) nothrow pure @system;

/*
* This template is needed because there need to be a `_d_arraysetlengthTTrace!Tarr` instance for every
Expand Down
2 changes: 1 addition & 1 deletion src/core/internal/array/concatenation.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module core.internal.array.concatenation;

/// See $(REF _d_arraycatnTX, rt,lifetime)
private extern (C) void[] _d_arraycatnTX(const TypeInfo ti, byte[][] arrs) pure nothrow;
private extern (C) void[] _d_arraycatnTX(const TypeInfo ti, byte[][] arrs) pure nothrow @system;

/// Implementation of `_d_arraycatnTX` and `_d_arraycatnTXTrace`
template _d_arraycatnTXImpl(Tarr : ResultArrT[], ResultArrT : T[], T)
Expand Down
2 changes: 1 addition & 1 deletion src/core/internal/entrypoint.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ this code into the module.
*/
template _d_cmain()
{
extern(C)
extern(C) @system
{
int _d_run_main(int argc, char **argv, void* mainFunc);

Expand Down
2 changes: 1 addition & 1 deletion src/core/internal/parseoptions.d
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ unittest
float heapSizeFactor = 2.0; // heap size to used memory ratio

@nogc nothrow:
void help();
void help() @system;
string errorName() @nogc nothrow { return "GC"; }
}
Config conf;
Expand Down
18 changes: 9 additions & 9 deletions src/core/internal/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ template staticIota(int beg, int end)

private struct __InoutWorkaroundStruct {}
@property T rvalueOf(T)(T val) { return val; }
@property T rvalueOf(T)(inout __InoutWorkaroundStruct = __InoutWorkaroundStruct.init);
@property ref T lvalueOf(T)(inout __InoutWorkaroundStruct = __InoutWorkaroundStruct.init);
@property T rvalueOf(T)(inout __InoutWorkaroundStruct = __InoutWorkaroundStruct.init) @system;
@property ref T lvalueOf(T)(inout __InoutWorkaroundStruct = __InoutWorkaroundStruct.init) @system;

// taken from std.traits.isAssignable
template isAssignable(Lhs, Rhs = Lhs)
Expand Down Expand Up @@ -557,9 +557,9 @@ if (func.length == 1 /*&& isCallable!func*/)

@system unittest
{
int test(int a);
int propGet() @property;
int propSet(int a) @property;
int test(int a) @system;
int propGet() @property @system;
int propSet(int a) @property @system;
int function(int) test_fp;
int delegate(int) test_dg;
static assert(is( typeof(test) == FunctionTypeOf!(typeof(test)) ));
Expand Down Expand Up @@ -628,7 +628,7 @@ if (func.length == 1 /*&& isCallable!func*/)
//
@safe unittest
{
int foo();
int foo() @system;
ReturnType!foo x; // x is declared as int
}

Expand Down Expand Up @@ -688,9 +688,9 @@ if (func.length == 1 /*&& isCallable!func*/)
//
@safe unittest
{
int foo(int, long);
void bar(Parameters!foo); // declares void bar(int, long);
void abc(Parameters!foo[1]); // declares void abc(long);
int foo(int, long) @system;
void bar(Parameters!foo) @system; // declares void bar(int, long);
void abc(Parameters!foo[1]) @system; // declares void abc(long);
}

@safe unittest
Expand Down
2 changes: 1 addition & 1 deletion src/core/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ T* emplace(T, Args...)(void[] chunk, auto ref Args args)

struct S2
{
void opAssign(S2);
void opAssign(S2) @system;
}

S1 s1 = void;
Expand Down
52 changes: 26 additions & 26 deletions src/core/memory.d
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,28 @@ else version (WatchOS)

private
{
extern (C) void gc_init();
extern (C) void gc_term();
extern (C) void gc_init() @system;
extern (C) void gc_term() @system;

extern (C) void gc_enable() nothrow;
extern (C) void gc_disable() nothrow;
extern (C) void gc_collect() nothrow;
extern (C) void gc_minimize() nothrow;
extern (C) void gc_enable() nothrow @system;
extern (C) void gc_disable() nothrow @system;
extern (C) void gc_collect() nothrow @system;
extern (C) void gc_minimize() nothrow @system;

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( void* p ) pure nothrow @system;
extern (C) uint gc_setAttr( void* p, uint a ) pure nothrow @system;
extern (C) uint gc_clrAttr( void* p, uint a ) pure nothrow @system;

extern (C) void* gc_malloc( size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow;
extern (C) void* gc_calloc( size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow;
extern (C) BlkInfo_ gc_qalloc( size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow;
extern (C) void* gc_realloc( void* p, size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow;
extern (C) size_t gc_extend( void* p, size_t mx, size_t sz, const TypeInfo = null ) pure nothrow;
extern (C) size_t gc_reserve( size_t sz ) nothrow;
extern (C) void gc_free( void* p ) pure nothrow @nogc;
extern (C) void* gc_malloc( size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow @system;
extern (C) void* gc_calloc( size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow @system;
extern (C) BlkInfo_ gc_qalloc( size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow @system;
extern (C) void* gc_realloc( void* p, size_t sz, uint ba = 0, const TypeInfo = null ) pure nothrow @system;
extern (C) size_t gc_extend( void* p, size_t mx, size_t sz, const TypeInfo = null ) pure nothrow @system;
extern (C) size_t gc_reserve( size_t sz ) nothrow @system;
extern (C) void gc_free( void* p ) pure nothrow @nogc @system;

extern (C) void* gc_addrOf( void* p ) pure nothrow @nogc;
extern (C) size_t gc_sizeOf( void* p ) pure nothrow @nogc;
extern (C) void* gc_addrOf( void* p ) pure nothrow @nogc @system;
extern (C) size_t gc_sizeOf( void* p ) pure nothrow @nogc @system;

struct BlkInfo_
{
Expand All @@ -148,16 +148,16 @@ private
uint attr;
}

extern (C) BlkInfo_ gc_query( void* p ) pure nothrow;
extern (C) GC.Stats gc_stats ( ) nothrow @nogc;
extern (C) BlkInfo_ gc_query( void* p ) pure nothrow @system;
extern (C) GC.Stats gc_stats ( ) nothrow @nogc @system;
extern (C) GC.ProfileStats gc_profileStats ( ) nothrow @nogc @safe;

extern (C) void gc_addRoot(const void* p ) nothrow @nogc;
extern (C) void gc_addRange(const void* p, size_t sz, const TypeInfo ti = null ) nothrow @nogc;
extern (C) void gc_addRoot(const void* p ) nothrow @nogc @system;
extern (C) void gc_addRange(const void* p, size_t sz, const TypeInfo ti = null ) nothrow @nogc @system;

extern (C) void gc_removeRoot(const void* p ) nothrow @nogc;
extern (C) void gc_removeRange(const void* p ) nothrow @nogc;
extern (C) void gc_runFinalizers( const scope void[] segment );
extern (C) void gc_removeRoot(const void* p ) nothrow @nogc @system;
extern (C) void gc_removeRange(const void* p ) nothrow @nogc @system;
extern (C) void gc_runFinalizers( const scope void[] segment ) @system;

package extern (C) bool gc_inFinalizer() nothrow @nogc @safe;
}
Expand Down Expand Up @@ -225,7 +225,7 @@ unittest
// * The extern function declaration also has the side effect of making it
// impossible to manually call the function with standard syntax. This is to
// make it more difficult to call the function again, manually.
private void initialize();
private void initialize() @system;
pragma(crt_constructor)
pragma(mangle, `_D` ~ initialize.mangleof)
private extern (C) void initialize() @system
Expand Down
36 changes: 18 additions & 18 deletions src/core/runtime.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ else version (WatchOS)
version = Darwin;

/// C interface for Runtime.loadLibrary
extern (C) void* rt_loadLibrary(const char* name);
extern (C) void* rt_loadLibrary(const char* name) @system;
/// ditto
version (Windows) extern (C) void* rt_loadLibraryW(const wchar* name);

/// C interface for Runtime.unloadLibrary, returns 1/0 instead of bool
extern (C) int rt_unloadLibrary(void* ptr);
extern (C) int rt_unloadLibrary(void* ptr) @system;

/// C interface for Runtime.initialize, returns 1/0 instead of bool
extern(C) int rt_init();
extern(C) int rt_init() @system;
/// C interface for Runtime.terminate, returns 1/0 instead of bool
extern(C) int rt_term();
extern(C) int rt_term() @system;

/**
* This type is returned by the module unit test handler to indicate testing
Expand Down Expand Up @@ -89,19 +89,19 @@ private
alias bool function(Object) CollectHandler;
alias Throwable.TraceInfo function( void* ptr ) TraceHandler;

extern (C) void rt_setCollectHandler( CollectHandler h );
extern (C) CollectHandler rt_getCollectHandler();
extern (C) void rt_setCollectHandler( CollectHandler h ) @system;
extern (C) CollectHandler rt_getCollectHandler() @system;

extern (C) void rt_setTraceHandler( TraceHandler h );
extern (C) TraceHandler rt_getTraceHandler();
extern (C) void rt_setTraceHandler( TraceHandler h ) @system;
extern (C) TraceHandler rt_getTraceHandler() @system;

alias void delegate( Throwable ) ExceptionHandler;
extern (C) void _d_print_throwable(Throwable t);
extern (C) void _d_print_throwable(Throwable t) @system;

extern (C) void* thread_stackBottom();
extern (C) void* thread_stackBottom() @system;

extern (C) string[] rt_args();
extern (C) CArgs rt_cArgs() @nogc;
extern (C) string[] rt_args() @system;
extern (C) CArgs rt_cArgs() @nogc @system;
}


Expand Down Expand Up @@ -461,7 +461,7 @@ private:
* Note:
* This is a dmd specific setting.
*/
extern (C) void dmd_coverSourcePath(string path);
extern (C) void dmd_coverSourcePath(string path) @system;

/**
* Set output path for coverage reports.
Expand All @@ -471,7 +471,7 @@ extern (C) void dmd_coverSourcePath(string path);
* Note:
* This is a dmd specific setting.
*/
extern (C) void dmd_coverDestPath(string path);
extern (C) void dmd_coverDestPath(string path) @system;

/**
* Enable merging of coverage reports with existing data.
Expand All @@ -481,7 +481,7 @@ extern (C) void dmd_coverDestPath(string path);
* Note:
* This is a dmd specific setting.
*/
extern (C) void dmd_coverSetMerge(bool flag);
extern (C) void dmd_coverSetMerge(bool flag) @system;

/**
* Set the output file name for profile reports (-profile switch).
Expand All @@ -492,7 +492,7 @@ extern (C) void dmd_coverSetMerge(bool flag);
* Note:
* This is a dmd specific setting.
*/
extern (C) void trace_setlogfilename(string name);
extern (C) void trace_setlogfilename(string name) @system;

/**
* Set the output file name for the optimized profile linker DEF file (-profile switch).
Expand All @@ -503,7 +503,7 @@ extern (C) void trace_setlogfilename(string name);
* Note:
* This is a dmd specific setting.
*/
extern (C) void trace_setdeffilename(string name);
extern (C) void trace_setdeffilename(string name) @system;

/**
* Set the output file name for memory profile reports (-profile=gc switch).
Expand All @@ -514,7 +514,7 @@ extern (C) void trace_setdeffilename(string name);
* Note:
* This is a dmd specific setting.
*/
extern (C) void profilegc_setlogfilename(string name);
extern (C) void profilegc_setlogfilename(string name) @system;

///////////////////////////////////////////////////////////////////////////////
// Overridable Callbacks
Expand Down
1 change: 1 addition & 0 deletions src/core/stdcpp/exception.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ version (CppRuntime_Clang)

extern (C++, "std"):
@nogc:
@system:

///
alias terminate_handler = void function() nothrow;
Expand Down
1 change: 1 addition & 0 deletions src/core/stdcpp/new_.d
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void cpp_delete(T)(T instance) if (is(T == class))

// raw C++ functions
extern(C++):
@system:

/// Binding for ::operator new(std::size_t count)
pragma(mangle, __new_mangle)
Expand Down
2 changes: 1 addition & 1 deletion src/core/sys/posix/arpa/inet.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ else version (WatchOS)
version = Darwin;

version (Posix):
extern (C) nothrow @nogc:
extern (C) nothrow @nogc @system:

//
// Required
Expand Down
4 changes: 2 additions & 2 deletions src/core/sys/posix/net/if_.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ else version (WatchOS)
version = Darwin;

version (Posix):
extern (C) nothrow @nogc:
extern (C) nothrow @nogc @system:

//
// Required
Expand Down Expand Up @@ -157,4 +157,4 @@ else version (CRuntime_UClibc)
char* if_indextoname(uint, char*);
if_nameindex_t* if_nameindex();
void if_freenameindex(if_nameindex_t*);
}
}
2 changes: 1 addition & 1 deletion src/core/sys/posix/signal.d
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ version (X86_64) version = X86_Any;
version (Posix):
extern (C):
//nothrow: // this causes http://issues.dlang.org/show_bug.cgi?id=12738 (which has been fixed)
//@system:
@system:

//
// Required
Expand Down
12 changes: 6 additions & 6 deletions src/core/thread/osthread.d
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ private
//
// exposed by compiler runtime
//
extern (C) void rt_moduleTlsCtor();
extern (C) void rt_moduleTlsDtor();
extern (C) void rt_moduleTlsCtor() @system;
extern (C) void rt_moduleTlsDtor() @system;

/**
* Hook for whatever EH implementation is used to save/restore some data
Expand All @@ -213,15 +213,15 @@ private
* where the stack was last swapped out, or null when a fiber stack
* is switched in for the first time.
*/
extern(C) void* _d_eh_swapContext(void* newContext) nothrow @nogc;
extern(C) void* _d_eh_swapContext(void* newContext) nothrow @nogc @system;

version (DigitalMars)
{
version (Windows)
alias swapContext = _d_eh_swapContext;
else
{
extern(C) void* _d_eh_swapContextDwarf(void* newContext) nothrow @nogc;
extern(C) void* _d_eh_swapContextDwarf(void* newContext) nothrow @nogc @system;

void* swapContext(void* newContext) nothrow @nogc
{
Expand Down Expand Up @@ -2156,7 +2156,7 @@ extern (C) void thread_init() @nogc

private __gshared align(Thread.alignof) void[__traits(classInstanceSize, Thread)] _mainThreadStore;

extern (C) void _d_monitordelete_nogc(Object h) @nogc;
extern (C) void _d_monitordelete_nogc(Object h) @nogc @system;

/**
* Terminates the thread module. No other thread routine may be called
Expand Down Expand Up @@ -3329,7 +3329,7 @@ extern(C) void thread_processGCMarks( scope IsMarkedDg isMarked ) nothrow
}


extern (C) @nogc nothrow
extern (C) @nogc nothrow @system
{
version (CRuntime_Glibc) version = PThread_Getattr_NP;
version (CRuntime_Bionic) version = PThread_Getattr_NP;
Expand Down
2 changes: 1 addition & 1 deletion src/gc/impl/conservative/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ulong bytesAllocated; // thread local counter

private
{
extern (C)
extern (C) @system
{
// to allow compilation of this module without access to the rt package,
// make these functions available from rt.lifetime
Expand Down
Loading