[Mono-dev] [Mono-patches] r107198 - trunk/mcs/class/corlib/System

Mirco Bauer meebey at meebey.net
Fri Jul 4 13:01:21 EDT 2008


On Fri, 2008-07-04 at 16:53 +0200, Andreas Nahr wrote:
> 
> > -----Ursprüngliche Nachricht-----
> > Von: mono-devel-list-bounces at lists.ximian.com [mailto:mono-devel-list-
> > bounces at lists.ximian.com] Im Auftrag von Mirco Bauer
> > Gesendet: Freitag, 4. Juli 2008 12:59
> > An: Andreas Nahr
> > Cc: mono-devel-list at lists.ximian.com
> > Betreff: Re: [Mono-dev] [Mono-patches] r107198 -
> > trunk/mcs/class/corlib/System
> > > > >
> > > > >  		public static readonly IntPtr Zero;
> > > > >
> > > > >  #if NET_2_0
> > > > >  		[ReliabilityContract (Consistency.MayCorruptInstance,
> > > > Cer.MayFail)]
> > > > >  #endif
> > > > > -		public IntPtr (int i32)
> > > > > +		public IntPtr (int value)
> > > > >  		{
> > > > > -			value = (void *) i32;
> > > > > +			m_value = (void *) value;
> > > >
> > > > afaik the goal can also be archived using this.value = value;
> > >
> > > Did you try that? I actually had it this way and it refused to
> > compile
> > > because the value was deemed not initialized. I've got to admit that
> > I
> > > wasn't exactly sure why it didn't. Potential issue with the compiler
> > maybe?
> > 
> > At least for me it works, using gmcs 1.9.1:
> > 
> > meebey at redbull:~$ cat test.cs
> > using System;
> > 
> > class Test
> > {
> > 	int value;
> > 
> > 	Test(int value)
> > 	{
> > 		this.value = value;
> > 	}
> > 
> > 	public static void Main ()
> > 	{
> > 		Test t = new Test(123);
> > 		Console.WriteLine(t.value);
> > 	}
> > }
> 
> Are you trying to make a joke? ;)
> Of course this works with "normal" types.

I didn't test exactly the same situation, but I prooved the way it
should work like.

>  This is used thousands of times throughout the class libraries.
> But in *THIS* case with void * it does not seem to work. So this was the easiest way to fix the problem.

Ok, I used a class and int as type. So here a test using an unsafe
struct and void* as member, just like IntPtr does:

meebey at redbull:~$ cat test.cs
using System;

unsafe class Test
{
	int value;

	Test(int value)
	{
		this.value = value;
	}

	public static void Main ()
	{
		Test t = new Test(123);
		Console.WriteLine(t.value);

		AnotherTest at = new AnotherTest(123);
		Console.WriteLine((int) at.value);
	}
}

public unsafe struct AnotherTest
{
	internal void* value;
	
	public AnotherTest(int value)
	{
		this.value = (void*) value;
	}
}

meebey at redbull:~$ mono test.exe
123
123

> 
> Greetings Andreas
> 
> P.S. If you want to make further "tests" maybe mail me private and not through the list to keep the noise low.

I don't think this is noise as you had issues with a possible compiler
bug, so allow other developers to join the discussion and comment on the
test-code.

-- 
Regards,

Mirco 'meebey' Bauer

PGP-Key ID: 0xEEF946C8

FOSS Developer    meebey at meebey.net  http://www.meebey.net/
PEAR Developer    meebey at php.net     http://pear.php.net/
Debian Developer  meebey at debian.org  http://www.debian.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: This is a digitally signed message part
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080704/02a96593/attachment.bin 


More information about the Mono-devel-list mailing list