diff lphobos/std/moduleinit.d @ 117:56a21f3e5d3e trunk

[svn r121] Finished ModuleInfo implementation. Static ctors/dtors now work according to spec. Changed class vtable types slightly in some cases. Overridden functions now always take the the type of the first class declaring the method as this parameter. This helps when using headers (w. implementation somewhere else)
author lindquist
date Mon, 26 Nov 2007 04:49:23 +0100
parents fd7ad91fd713
children 373489eeaf90
line wrap: on
line diff
--- a/lphobos/std/moduleinit.d	Sun Nov 25 18:55:52 2007 +0100
+++ b/lphobos/std/moduleinit.d	Mon Nov 26 04:49:23 2007 +0100
@@ -30,22 +30,11 @@
 }
 
 
-// Win32: this gets initialized by minit.asm
-// linux: this gets initialized in _moduleCtor()
+// this gets initialized in _moduleCtor()
 extern (C) ModuleInfo[] _moduleinfo_array;
 
-version (linux)
-{
-    // This linked list is created by a compiler generated function inserted
-    // into the .ctor list by the compiler.
-    struct ModuleReference
-    {
-	ModuleReference* next;
-	ModuleInfo mod;
-    }
-
-    extern (C) ModuleReference *_Dmodule_ref;	// start of linked list
-}
+// this method returns the linker constructed, null terminated, array of moduleinfos
+extern (C) void** _d_get_moduleinfo_array();
 
 ModuleInfo[] _moduleinfo_dtors;
 uint _moduleinfo_dtors_i;
@@ -60,20 +49,20 @@
 extern (C) void _moduleCtor()
 {
     debug printf("_moduleCtor()\n");
-    version (linux)
-    {
 	int len = 0;
-	ModuleReference *mr;
 
-	for (mr = _Dmodule_ref; mr; mr = mr.next)
+    ModuleInfo* mrbegin = cast(ModuleInfo*)_d_get_moduleinfo_array();
+    assert(mrbegin !is null);
+
+    ModuleInfo* mr;
+	for (mr = mrbegin; *mr !is null; ++mr)
 	    len++;
 	_moduleinfo_array = new ModuleInfo[len];
 	len = 0;
-	for (mr = _Dmodule_ref; mr; mr = mr.next)
-	{   _moduleinfo_array[len] = mr.mod;
+	for (mr = mrbegin; *mr !is null; ++mr)
+	{   _moduleinfo_array[len] = *mr;
 	    len++;
 	}
-    }
 
     version (Win32)
     {
@@ -81,7 +70,7 @@
 	//_fatexit(&_STD_moduleDtor);
     }
 
-    _moduleinfo_dtors = new ModuleInfo[_moduleinfo_array.length];
+    _moduleinfo_dtors = new ModuleInfo[len];
     debug printf("_moduleinfo_dtors = x%x\n", cast(void *)_moduleinfo_dtors);
     _moduleCtor2(_moduleinfo_array, 0);