[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
Fri, 23 Jan 2004 09:07:44 -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 vargaz@freemail.hu.

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

--- shadow/52397	2004-01-23 09:07:44.000000000 -0500
+++ shadow/52397.tmp.24742	2004-01-23 09:07:44.000000000 -0500
@@ -0,0 +1,107 @@
+Bug#: 52397
+Product: Mono/Runtime
+Version: unspecified
+OS: unknown
+OS Details: 
+Status: RESOLVED   
+Resolution: FIXED
+Severity: Unknown
+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
+
+------- Additional Comments From vargaz@freemail.hu  2004-01-23 09:07 -------
+This was fixed by Bernie's patch.