[Mono-bugs] [Bug 52397][Nor] New - DllImported libraries seems to be linked before they're first needed...

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sat, 20 Dec 2003 09:57:53 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by mark.easton@blinksoftware.co.uk.

http://bugzilla.ximian.com/show_bug.cgi?id=52397

--- shadow/52397	2003-12-20 09:57:52.000000000 -0500
+++ shadow/52397.tmp.14851	2003-12-20 09:57:52.000000000 -0500
@@ -0,0 +1,104 @@
+Bug#: 52397
+Product: Mono/Runtime
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: mark.easton@blinksoftware.co.uk               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: DllImported libraries seems to be linked before they're first needed...
+
+Description of Problem:
+
+Mono seems to link to external libs before they're first called and 
+instead when their containing class is first referenced.  As an aside 
+there's also a warning message being spewed to the console that needs 
+culling.
+
+Steps to reproduce the problem:
+Compile and execute the following code:
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Crossplatform.NET.Chapter08
+{
+    public class GetProcessId3
+    {
+        //Kick things off...
+	public static void Main()
+	{
+	    Console.WriteLine("Process ID: {0}", Platform.CreatePlatform
+().GetProcessId());
+	}
+    }
+        
+    public abstract class Platform
+    {
+        protected Platform(){}
+        
+        public static Platform CreatePlatform()
+        {
+            if(IsWindows())
+                return new WinPlatform();
+            else
+                return new UnixPlatform();
+        }
+        
+        public abstract int GetProcessId();
+        
+        //Provide a cheap way of seeing if we're on windows
+	private static bool IsWindows()
+	{
+	    PlatformID platform = Environment.OSVersion.Platform;
+	    
+	    return (platform == PlatformID.Win32NT | platform == 
+PlatformID.Win32Windows |
+	            platform == PlatformID.Win32S | platform == 
+PlatformID.WinCE);    
+	}
+    }
+        
+    public class WinPlatform : Platform
+    {
+        [DllImport("kernel32", EntryPoint="GetCurrentProcessId")]
+	private unsafe static extern int GetCurrentProcessId();
+               
+        public override int GetProcessId()
+        {
+               return GetCurrentProcessId(); 
+        }
+    }
+
+    public class UnixPlatform : Platform
+    {
+        [DllImport("libc", EntryPoint="getpid")]
+	private unsafe static extern int getpid();
+        
+        public UnixPlatform(){}
+        
+        public override int GetProcessId()
+        {
+               return getpid(); 
+        }
+    }
+}
+
+Actual Results:
+Functionally correct but warning messages displayed and I would think that 
+linking should wait until a funciton is first called.
+
+Expected Results:
+No warning messages and linking shoul donly occur when an external 
+function is first called
+
+How often does this happen? 
+Always