www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17035] New: extern(C) and extern(C++) module ctor/dtor should

https://issues.dlang.org/show_bug.cgi?id=17035

          Issue ID: 17035
           Summary: extern(C) and extern(C++) module ctor/dtor should
                    behave like the C init/fini functions
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andrei erdani.com

If a module ctor is declared as:

extern(C) static shared this() {}

or

extern(C++) static shared this() {}

then it should follow the C/C++ convention of library initialization: no
circularity checking, no guaranteed order of execution, no guarantee the GC is
initialized etc. The way this is done on Linux is by placing pointers to these
functions in a segment called "init_array". 
Similarly, if a module dtor is declared as:

extern(C) static shared ~this() {}

or

extern(C++) static shared ~this() {}

then it should follow the same regime as C++ static destructors. On Linux
pointers to these functions are placed in a segment called "fini_array".

For reference see gcc's __attribute__((constructor)),
__attribute__((destructor)).

This should make it easier to write library initialization code that does not
depend on druntime.

--
Dec 26 2016