[Issue 17035] New: extern(C) and extern(C++) module ctor/dtor should behave like the C init/fini functions

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Dec 26 17:33:27 PST 2016


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 at puremagic.com
          Reporter: andrei at 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.

--


More information about the Digitalmars-d-bugs mailing list