Re: [Mono-dev] Mono Winforms on Mac

2010-10-30 Thread Carlos Alberto Cortez
Hello,

I will step up, since I have more experience on the code, but based on its
size, I may be giving feedback piece by piece.

Carlos.

2010/10/30 Miguel de Icaza mig...@novell.com

 Hello Ralph,

 Does the Mono Project have it's own format utility? It would be nice
 to make all the code consistent no matter what that format is.


 We do not.   And I do agree with you that some of the practices on
 Windows.Forms were less than ideal, reading your patch made me realize that
 the Windows.Forms team created their own rules that did not really match the
 Mono guidelines and that this needs to be fixed.

 I am willing to change the formatting on the Windows.Forms codebase in
 about half the cases that your code did, but this is secondary to getting
 your patches reviewed and merged.

 In general, in open source, there is an unspoken rule that you always adapt
 your code to the upstream coding style.   This means that reviewing patches
 can focus on the actual substance of the problem instead of having to chase
 down the changes line-by-line.   The patch that I posted to the mailing list
 contains the cleaned up version of your patch after I removed all
 the superfluous changes that were still on it.

 But we are left with a jumbo patch with large changes and no explanation of
 what the change does, why it does it.   Ideally, you could resubmit the
 patches on a feature-by-feature basis, this would accelerate the review.
 As you noticed by the lack of participation on the thread, nobody really has
 stepped up to review the jumbo patch after I cleaned it up.   The changes
 are just too big as they are now.

 If nobody steps up, I will add it to my own list of tasks to do, but right
 now I am tied up for the next two weeks.

 Miguel


 On 10/30/10, Miguel de Icaza mig...@novell.com wrote:
  Hello Ralph,
 
  Have you given any consideration to providing a roadmap to your
 changes
  so that they can be individually reviewed?
 
  Since you reformatted the source code, it is not possible to apply
 the
  patches directly, we still have to apply every change by hand and it
 would
  be useful to have the different patches and changes reviewed
 independently.
 
  Miguel
 
  On Sat, Oct 30, 2010 at 10:34 AM, Ralph Leckett rleck...@gmail.com
 wrote:
 
  Attached is another set of updates for Mac Mono Winforms. My .net
  applications now work quite nicely with my changes to Mono.
 
  NativeWindow has been simplified to using Hwnd to provide the
  Handle-Window lookup. I have found that storing handles in Hashtable
  sometimes results in the handle being lost with the result being
  zombie windows. Replacing Hashtable with a linked list solved the
  problem. Placing the most recently used link at the head of the linked
  list maintains efficiency.
 
  MS Windows places paint events at the lowest priority with all other
  events preempting WM_PAINT. A separate queue (linked list in my case)
  for paint events is required for Mono to duplicate this effect.
 
  I find the exposure of method variables to outside objects without
  using properties to be one of the poorer coding practices used in
  Mono. Apart from that, I found Mono to be quite well written and a
  pleasure to work on.
 
  Ralph
 
  On 10/20/10, Ralph Leckett rleck...@gmail.com wrote:
   The namespaces in the code caused compile errors in one of my test
   environments so I had to remove them.
  
   Attached is an update to my updates to fix this problem:
   https://bugzilla.novell.com/show_bug.cgi?id=438281
  
   Ralph
  
   On 10/19/10, Miguel de Icaza mig...@novell.com wrote:
   Hello,
  
   I have created a diff file from the formatted sources that
 removes
   some of the other automatic changes that probably came out of some
   refactoring tool.   The patch itself can not be used directly
 against
   Mono's source code since it is still a diff from formatted to
   formatted,
   not from Mono to formatted.This means that we are going to have
 to
   apply every patch by hand.
  
   I personally like the changes that were made by the tool, like
   dropping the gratuitous overuse of namespaces in the
 Managed.Winforms
   code, and would love to plug those changes back in the future.
  
   In terms of how to get the changes merged, ideally, Ralph could
   review the attached file and provide a roadmap of what each of the
   changes do.   There are some that I suspect wont be controversial,
 for
   example:
  
* There is a refactoring of the Clipboard code, this seems
  straightforward, but it still needs a review.
  
* Some look like simple bug fixes, but it would be good to
  know what were they fixing (for example the ListView.cs
  changes).
  
   There are other pieces that look like they went through a lot of
   work, and a more detailed explanation of the changes would be
 useful,
   in
   this group, I would include:
  
* Hwnd.cs
  
* XplatUICarbon.cs
  
   There are 

Re: [Mono-dev] SerialPort and OnDataReceived event

2010-07-30 Thread Carlos Alberto Cortez
Hey,

This event is indeed not implemented. I began to implement it some time ago,
but due to some technical reasons I don't remember now -it was something
related to poll/select functions, likely), I didn't commit it (and now I
can't seem to find that patch).

And yes, we would accept patches in such case :-)

Carlos.

2010/7/30 Marcus Obst marcus.o...@etit.tu-chemnitz.de

 Hi!

 I was trying to run a .NET assembly generated by Microsoft tools under
 Mono (Linux).

 The application accesses the serial port and installs an event handler
 for the DataReceived event.  Unfortunately, this handler is never
 called!

 Digging into the sources of Mono/MCS (from svn) showed that this event
 is never raised in SerialPort.cs.

 As far as I can see, this is addressed by the bug report  323892
 (SerialDataReceived events/callbacks are not implemented) from 2007.

 (Even moma does not report this incompatibility since the event handler
 is implemented but the event itself is never raised)

 My question is now: is there any (technical) reason why this
 functionality is not implemented in Mono?

 Are you interested in a patch which might fix this?

  Best regards from Chemnitz/Germany!
  Marcus
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Bug 494234: XplatUIX11.WorkingArea can segfault if the WM does not support _NET_WORKAREA

2010-04-08 Thread Carlos Alberto Cortez
Hey,

The change seems fine, but we need to test it. Will do that this weekend.

Thanks,
Carlos.

2010/4/3 Brian Pellin bpel...@gmail.com

 Is there anything I can do to encourage applying the patch in Bug
 494234? [1]  I get a segfault every time I run KeePass[2] in the
 xmonad[3] window manager, because it does not support _NET_WORKAREA.
 This patch fixes it for me.

 Thanks,
 Brian

 [1] https://bugzilla.novell.com/show_bug.cgi?id=494234
 [2] http://downloads.sourceforge.net/keepass/KeePass-2.10.zip
 [3] http://xmonad.org/
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Bug 575813] FileStream doesn't handle errors on Close (disk full, generic error, etc.)

2010-02-08 Thread Carlos Alberto Cortez
Hey!

I was taking a look and the issue is not reproducible in trunk, since
r145271 seems to fix it indirectly, by calling MonoIO.Write until *all* the
bytes have been written.

At least it fixes the very specific scenario described in the bug report,
and since that revision is expected to be backported, we should at least do
it.

Carlos.

2010/2/6 Miguel de Icaza mig...@novell.com

   I've filed a somewhat nasty bug a few days back (you may lose your data
   if you trigger it): https://bugzilla.novell.com/show_bug.cgi?id=575813
  
   I'd really appreciate if someone could take a look at this.
 
  BUMP!  Doesn't anyone think it's a critical bug?

 The fix is trivial, the side effects are far reaching and any fix will
 require a careful review of those side effects.

 I would not expect a resolution any time soon.

 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Bug 575813] FileStream doesn't handle errors on Close (disk full, generic error, etc.)

2010-02-05 Thread Carlos Alberto Cortez
I will take a look at it in the next days.

Carlos.

2010/2/5 Alex Shulgin alexander.shul...@yessoftware.com

 Alex Shulgin wrote:
  Hi,
 
  I've filed a somewhat nasty bug a few days back (you may lose your data
  if you trigger it): https://bugzilla.novell.com/show_bug.cgi?id=575813
 
  I'd really appreciate if someone could take a look at this.

 BUMP!  Doesn't anyone think it's a critical bug?

 --
 Alex

 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Mono 2.6.x

2010-02-02 Thread Carlos Alberto Cortez
#569535 has been already backported, so it should appear in the next
release.

Carlos.

2010/2/2 Kris Ray k...@landmarkdigital.com


 I would like to vote for backports of the following bugs, which are already
 fixed in trunk:

 https://bugzilla.novell.com/show_bug.cgi?id=565149
 https://bugzilla.novell.com/show_bug.cgi?id=569535

 Both of these bug fixes are critical for our needs.

 thanks,
 Kris



 On Tue, 2010-02-02 at 11:57 -0600, Andrew Jorgensen wrote:


 Hello Happy Coders,


 We are planning to make a new release from the 2.6 branch in the near
 future (probably before the end of the month?).  If there are bugs that
 you know ought to be backported (customer issues, regressions, and
 embarrassments especially) please do so in the next week or so.

 As you backport please keep in mind that we are trying to stabilize the
 2.6 branch.  Be conscientious and thorough and use your own best
 judgment in your area of expertise and consult your colleagues where you
 have doubts.  Also don't neglect other platforms like Mac, Windows, and
 Linux s390x.  2.6.x will eventually be used as a Novell-supported
 release for the Mono Extension for SLE and other products.

 We will be doing some testing of the 2.6 branch during this time.  If QA
 approaches you regarding a bug please remember that we will also need
 time to verify the fix after you check it in.  In other words: please
 give us any priority you can.  And don't forget to close bugs as you fix
 them and file them as you find them.

 Hmm, I should get someone to fix the booc crasher on x86_64...  Oh and
 thanks so much to those who pitched in to get our Xen x86_64 crasher
 fixed!


 Best Regards,

 Andrew Jorgensen
 Release / Packaging Guy
 Novell, Inc.

 __
 _
 Mono-devel-list mailing 
 listmono-devel-l...@lists.ximian.comhttp://lists.ximian.com/mailman/listinfo/mono-devel-list



 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Fwd: Could you please review/comment or approve?

2010-01-22 Thread Carlos Alberto Cortez
Hey!

Sorry for the late review, but these patches got lost among a bunch of other
patches to review. Anyway, the patches are fine.

Thanks for taking a look at that,
Carlos.


2010/1/22 Leszek Ciesielski skol...@gmail.com

 Both patches (Thad's and mine) commited.

 On Thu, Jan 21, 2010 at 6:32 PM, Miguel de Icaza mig...@novell.com
 wrote:
  Hello,
 
Let us get it in, ad if Carlos disapproves, he can comment/fix later.
 
  I'm pushing this patch for review once again... Or may I treat the
  silence as permission to commit? ;-)
 
 
  -- Forwarded message --
  From: Miguel de Icaza mig...@novell.com
  Date: Sun, Nov 22, 2009 at 10:46 PM
  Subject: Could you please review/comment or approve?
  To: Carlos Alberto Cortez calberto.cor...@gmail.com
  Cc: skol...@gmail.com
 
 
  Hello Carlos,
 
 Could you please review this patch that has been sitting on
  mono-devel-list?
 
 
 
 
  -- Forwarded message --
  From: Leszek Ciesielski skol...@gmail.com
  To: mono-devel-list mono-devel-l...@ximian.com
  Date: Mon, 12 Oct 2009 08:55:44 +0200
  Subject: [Mono-dev] Fwd: SerialPortStream patch
  I am mailing the patches again, because I got no response before (it
  was just before Mono 2.6 branching).
 
 
  -- Forwarded message --
  From: Leszek Ciesielski skol...@gmail.com
  Date: 2009/9/23
  Subject: Re: [Mono-dev] SerialPortStream patch
  To: mono-devel-list@lists.ximian.com
 
 
  Hi,
 
  here's another short patch for serial port, there were other native
  calls not checking for error conditions. May I commit?
 
  Regards,
 
  skolima
 
  ___
  Mono-devel-list mailing list
  Mono-devel-list@lists.ximian.com
  http://lists.ximian.com/mailman/listinfo/mono-devel-list
 
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] Support for exponents in Int32.Parse

2009-12-21 Thread Carlos Alberto Cortez
Hey!

I was going to commit the attached patch, in order to support exponent
notation in our Int32.Parse method (as declared in
NumberStyles.AllowExponent). But then I thought it would be a good idea to
throw the patch to the public, in case somebody is interested - specially in
the overflow handling.

Carlos.
Index: Int32.cs
===
--- Int32.cs	(revisión: 148618)
+++ Int32.cs	(copia de trabajo)
@@ -274,21 +274,52 @@
 			} 
 		}
 
-		internal static bool FindExponent (ref int pos, string s)
+		internal static bool FindExponent (ref int pos, string s, ref int exponent, bool tryParse, ref Exception exc)
 		{
+exponent = 0;
+long exp = 0; // temp long value
+
 int i = s.IndexOfAny(new char [] {'e', 'E'}, pos);
-if (i  0)
-		return false;
-if (++i == s.Length)
-		return false;
-if (s [i] == '+' || s [i] == '-')
-		if (++i == s.Length)
-return false;
-if (!Char.IsDigit (s [i]))
-		return false;
-for (; i  s.Length; ++i)
-		if (!Char.IsDigit (s [i])) 
-break;
+if (i  0) {
+	exc = null;
+	return false;
+}
+
+if (++i == s.Length) {
+	exc = tryParse ? null : GetFormatException ();
+	return true;
+}
+
+// negative exponent not valid for Int32
+if (s [i] == '-') {
+	exc = tryParse ? null : new OverflowException (Value too large or too small.);
+	return true;
+}
+
+if (s [i] == '+'  ++i == s.Length) {
+	exc = tryParse ? null : GetFormatException ();
+	return true;
+}
+
+for (; i  s.Length; i++) {
+	if (!Char.IsDigit (s [i]))  {
+		exc = tryParse ? null : GetFormatException ();
+		return true;
+	}
+
+	// Reduce the risk of throwing an overflow exc
+	exp = checked (exp * 10 - (int) (s [i] - '0'));
+	if (exp  Int32.MinValue || exp  Int32.MaxValue) {
+		exc = tryParse ? null : new OverflowException (Value too large or too small.);
+		return true;
+	}
+}
+
+// exp value saved as negative
+exp = -exp;
+
+exc = null;
+exponent = (int)exp;
 pos = i;
 return true;
 		}
@@ -430,6 +461,7 @@
 			bool decimalPointFound = false;
 			int digitValue;
 			char hexDigit;
+			int exponent = 0;
 
 			// Number stuff
 			do {
@@ -504,8 +536,9 @@
 return false;
 			}
 
-			if (AllowExponent) 
-	FindExponent(ref pos, s);
+			if (AllowExponent)
+if (FindExponent (ref pos, s, ref exponent, tryParse, ref exc)  exc != null)
+	return false;
 
 			if (AllowTrailingSign  !foundSign) {
 // Sign + Currency
@@ -561,6 +594,19 @@
 } else
 	number = checked (-number);
 			}
+
+			// result *= 10^exponent
+			if (exponent  0) {
+// Reduce the risk of throwing an overflow exc
+double res = checked (Math.Pow (10, exponent) * number);
+if (res  Int32.MinValue || res  Int32.MaxValue) {
+	if (!tryParse)
+		exc = new OverflowException (Value too large or too small.);
+	return false;
+}
+
+number = (int)res;
+			}
 			
 			result = number;
 
Index: Int32Test.cs
===
--- Int32Test.cs	(revisión: 148618)
+++ Int32Test.cs	(copia de trabajo)
@@ -235,6 +235,59 @@
 		Int32.Parse (123, new DateTimeFormatInfo ());
 	}
 
+	[Test]
+	public void TestParseExponent ()
+	{
+		Assert.AreEqual (2, Int32.Parse (2E0, NumberStyles.AllowExponent), A#1);
+		Assert.AreEqual (20, Int32.Parse (2E1, NumberStyles.AllowExponent), A#2);
+		Assert.AreEqual (200, Int32.Parse (2E2, NumberStyles.AllowExponent), A#3);
+		Assert.AreEqual (200, Int32.Parse (2E6, NumberStyles.AllowExponent), A#4);
+		Assert.AreEqual (200, Int32.Parse (2E+2, NumberStyles.AllowExponent), A#5);
+
+		try {
+			Int32.Parse (2E);
+			Assert.Fail (B#1);
+		} catch (FormatException) {
+		}
+
+		try {
+			Int32.Parse (2E3.0, NumberStyles.AllowExponent); // decimal notation for the exponent
+			Assert.Fail (B#2);
+		} catch (FormatException) {
+		}
+
+		try {
+			Int32.Parse (2E 2, NumberStyles.AllowExponent);
+			Assert.Fail (B#3);
+		} catch (FormatException) {
+		}
+
+		try {
+			Int32.Parse (2E2 , NumberStyles.AllowExponent);
+			Assert.Fail (B#4);
+		} catch (FormatException) {
+		}
+
+		try {
+			Int32.Parse (2E66, NumberStyles.AllowExponent); // final result overflow
+			Assert.Fail (B#5);
+		} catch (OverflowException) {
+		}
+
+		try {
+			long exponent = (long)Int32.MaxValue + 10;
+			Int32.Parse (2E + exponent.ToString (), NumberStyles.AllowExponent);
+			Assert.Fail (B#6);
+		} catch (OverflowException) {
+		}
+
+		try {
+			Int32.Parse (2E-1, NumberStyles.AllowExponent); // negative exponent
+			Assert.Fail (B#7);
+		} catch (OverflowException) {
+		}
+	}
+
 #if NET_2_0	
 	[Test]
 	public void TestTryParse()
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Announcing the release of Mono 2.4.3

2009-12-09 Thread Carlos Alberto Cortez
It was  indeed fixed. Sorry, I forgot to close that one.

Carlos.

2009/12/9 Oskar Berggren oskar.bergg...@gmail.com

 The release notes lists the following issue as fixed:
 467418 (https://bugzilla.novell.com/show_bug.cgi?id=467418) - ListView
 in VirtualMode uses too much memory and is slow

 But the bug report is still marked as NEW and there is no comment
 indicating that a fix has been checked in. What is the interpretation
 of this?

 /Oskar



 2009/12/9 Andrew Jorgensen ajorgen...@novell.com:
  Yesterday we released Mono 2.4.3.  This release contains a large number
  of bug fixes, including fixes for security bugs.
 
  The release notes are here:
 http://go-mono.com/archive/2.4.3
 
  and downloads are available here:
 http://go-mono.com/mono-downloads/
 
  We have not released LiveCD or Appliance images because we are working
  toward a 2.6 release in the near future.
 
  Thanks to all those who contributed to this release!
 
 
 
  ___
  Mono-devel-list mailing list
  Mono-devel-list@lists.ximian.com
  http://lists.ximian.com/mailman/listinfo/mono-devel-list
 
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Patch] Report an error if src and dest are the same in Copy

2009-11-27 Thread Carlos Alberto Cortez
Yes - sorry, I forgot to send it with the previous patch ;-)

Carlos.

2009/11/27 Rodrigo Kumpera kump...@gmail.com

 Do you have a test case for that?


 On Fri, Nov 27, 2009 at 12:09 AM, Carlos Alberto Cortez 
 calberto.cor...@gmail.com wrote:

 Hey,

 The attached patch on CopyFile on our io-layer -which is used by
 System.IO.File.Copy- check if the source and the destination are the same,
 and in that case, report that the file is currently in use, and proceed to
 throw an exception. I tried to add this check directly in our C# side, but
 then moved the check to our io-layer side so we could take advantage of our
 IOMAP capability.

 Could anybody with experience in the io-layer review?

 Thanks!


 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list



Index: FileTest.cs
===
--- FileTest.cs	(revisión: 147032)
+++ FileTest.cs	(copia de trabajo)
@@ -343,6 +343,27 @@
 		}
 
 		[Test]
+		public void Copy_SourceFileName_DestFileName_Same ()
+		{
+			string source = TempFolder + Path.DirectorySeparatorChar + SameFile.txt;
+			DeleteFile (source);
+			try {
+// new empty file
+File.Create (source).Close ();
+try {
+	File.Copy (source, source, true);
+	Assert.Fail (#1);
+} catch (IOException ex) {
+	// process cannot access file ... because it is being used by another process
+	Assert.IsNull (ex.InnerException, #2);
+	Assert.IsTrue (ex.Message.IndexOf (source) != -1, #3);
+}
+			} finally {
+DeleteFile (source);
+			}
+		}
+
+		[Test]
 		public void Copy ()
 		{
 			string path1 = TempFolder + Path.DirectorySeparatorChar + bar;
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] Report an error if src and dest are the same in Copy

2009-11-26 Thread Carlos Alberto Cortez
Hey,

The attached patch on CopyFile on our io-layer -which is used by
System.IO.File.Copy- check if the source and the destination are the same,
and in that case, report that the file is currently in use, and proceed to
throw an exception. I tried to add this check directly in our C# side, but
then moved the check to our io-layer side so we could take advantage of our
IOMAP capability.

Could anybody with experience in the io-layer review?

Thanks!
Index: io-layer/io.c
===
--- io-layer/io.c	(revisión: 146913)
+++ io-layer/io.c	(copia de trabajo)
@@ -1954,7 +1954,7 @@
 {
 	gchar *utf8_src, *utf8_dest;
 	int src_fd, dest_fd;
-	struct stat st;
+	struct stat st, dest_st;
 	gboolean ret = TRUE;
 	
 	if(name==NULL) {
@@ -2020,6 +2020,20 @@
 		
 		return(FALSE);
 	}
+
+	/* Before trying to open/create the dest, we need to report a 'file busy'
+	 * error if src and dest are actually the same file. We do the check here to take
+	 * advantage of the IOMAP capability */
+	if (!_wapi_stat (utf8_dest, dest_st)  st.st_dev == dest_st.st_dev  
+			st.st_ino == dest_st.st_ino) {
+
+		g_free (utf8_src);
+		g_free (utf8_dest);
+		close (src_fd);
+
+		SetLastError (ERROR_SHARING_VIOLATION);
+		return (FALSE);
+	}
 	
 	if (fail_if_exists) {
 		dest_fd = _wapi_open (utf8_dest, O_WRONLY | O_CREAT | O_EXCL, st.st_mode);
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Gtk depends on Winforms ¿?

2009-09-07 Thread Carlos Alberto Cortez
Hey,




 But since Mono's System.Windows.Forms is Open Source [1], why was it
 again that no one has found out what DoEvents does? ;-)

 Andreas

 [1]
 http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIWin32.cs?view=markup



We do know what Application.DoEvents do: process pending messages. What we
don't know is *how* is that affecting Gtk and the visual styles, and our
implementation of Windows.Forms has then nothing to see in that part.

Carlos.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] WinForms Control.Invoke Issue

2009-08-07 Thread Carlos Alberto Cortez
Hey!

I had been reviewing some patches we have in bugzilla - but I missed this
one. It's now reviewed - see bugzilla ;-)

Thanks!
Carlos.

2009/8/7 Tom Spink tsp...@gmail.com

 Hi Guys,

 I filed a bug a while ago about an issue with Control.Invoke in
 WinForms.  A guy said he'd take a look at a patch, if I posted one,
 which I did... but nothing has come of it.  I tried e-mailing the
 WinForms list, but haven't heard anything back.

 I was wondering if someone here could take a look at my proposed patch?

 Here's the BugZilla entry:
 https://bugzilla.novell.com/show_bug.cgi?id=497175

 Thanks!
 --
 Tom Spink
 Pablo Picasso  - Computers are useless. They can only give you answers.
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] current serialport status..

2009-07-13 Thread Carlos Alberto Cortez
As Atsushi said, nobody is working in the serial ports these days, but you
can still fill a bug report, and at some point we will try to fix it.

Carlos.

2009/7/13 Atsushi Eno atsushi...@veritas-vos-liberabit.com

 My understanding is that no one is working on serial port stack now.

 I haven't faced to any serial port issue on linux, but it won't
 work on OSX or windows for some cases (bugs filed and/or patch posted).
 A problem is that it very often needs the actual hardware to reproduce
 issues which is mostly impossible.

 Atsushi Eno


 buhochil...@gmail.com wrote:
  Hi,
 
  I wonder what is the serialport current status?, we at monoBOTICS
  (http://www.monobotics.ic.uach.cl) use intensely that component in our
  project without much problems till now. Now we have a 1mps speed and the
  incoming data events and we start to have some issues with it, so I
  wonder what is the actual current state of the serialport class on
  mono/linux...
 
  I think that some time ago I read a post from one of the Unity guys
  mention something about that they complete that class and they was going
  to bright those changes/updates back to the mono sources, but it seems
  that nothing about it happend?
 
  Cheers,
 
  Mauricio
 
  ___
  Mono-devel-list mailing list
  Mono-devel-list@lists.ximian.com
  http://lists.ximian.com/mailman/listinfo/mono-devel-list
 
 
 

 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Bug In Mono FTP System.Net.FtpWebRequest

2008-09-04 Thread Carlos Alberto Cortez
This is mostly an eror. Please fill a bug for it. See 
http://mono-project.com/Bugs

Carlos.

El mié, 03-09-2008 a las 05:23 -0700, Dieuzorro escribió:
 With my code I was able to download a file on the server
 ftp://ftp-developpez.com/konflor/Latex/formation/FormationLatex.pdf;
 anonymously. But on my local server when I want to download a file with a
 loggin and a password, my stream ResponceStream is empty and there is no
 error. On Windows everything works.
 
   Have you got an exemple on mono which connect on an private ftp
 server? But my code works on windows and ftp server!
 
 Thanks
 
 
 
 Dieuzorro wrote:
  
  
  
  The code below operates under windwos but not Linux file is created,
  but it is empty.
  
  I think that the bug is in 'Credentials' because I can download files
  on server without authentication(Login/Password). 
  
  Sorry for my English I am french 
  
  
  
  
  Sub dl(ByVal remoteFile As String, ByVal localFile As String, ByVal
  username As String, ByVal password As String)
  
  
  
  '1. Create a request: must be in ftp://hostname format, 
  
  '   not just ftp.myhost.com
  
  Dim URI As String = remoteFile
  
  Dim ftp As System.Net.FtpWebRequest = 
  CType(FtpWebRequest.Create(URI), FtpWebRequest)
  
  
  
  
  '3. Settings and action
  
  ftp.KeepAlive = False
  
  'we want a binary transfer, not textual data
  
  ftp.UseBinary = True
  
  'Define the action required (in this case, download a file)
  
  ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
  
  
  '2. Set credentials
  if not (username =  andalso password = ) then
  
  ftp.Credentials = New NetworkCredential( username, password)
  end if
  
  
  '4. If we were using a method that uploads data e.g. UploadFile
  
  '   we would open the ftp.GetRequestStream here an send the data
  
  
  
  '5. Get the response to the Ftp request and the associated stream
  
  Using response As System.Net.FtpWebResponse =
  CType(ftp.GetResponse, System.Net.FtpWebResponse)
  
  Using responseStream As IO.Stream = response.GetResponseStream
  
  'loop to read  write to file
  
  Using fs As New IO.FileStream(localFile,
  IO.FileMode.Create)
  
  Dim buffer(2047) As Byte
  
  Dim read As Integer = 0
  
  Do
  
  read = responseStream.Read(buffer, 0,
  buffer.Length)
  
  fs.Write(buffer, 0, read)
  
  Loop Until read = 0 'see Note(1)
  
  responseStream.Close()
  
  fs.Flush()
  
  fs.Close()
  
  End Using
  
  
  
  End Sub End Using
  
  responseStream.Close()
  
  End Using
  
  response.Close()
  
  End Using
  
  
  
  End Sub
  
  
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Mono 2.0 Preview 1 is out!!

2008-08-20 Thread Carlos Alberto Cortez

Hello,

 
 3) You asked post bug reports. OK. I looked in tracker - there are 171 
 bugs only in SWF (some of them are mine). Some bugs assigned to 
 developers. But most of them not assigned. What do you plan to do with 
 such bugs? Will you ignore them and make 2.0 release?
 

Developing the implementation of Windows.Forms has proven to be a tricky
thing - sometimes there are some undocumented behaviours and bits hidden
somewhere, that appear until a user follows a specific path.

Now, we try to prioritise the bugs we have, and fix them based on that.
We assign them as soon as somebody is done with some bugs and goes for
the next ones. What do we try with those bugs? Fix them, of course. We
can't ignore them, but it's not logical no stop the entire release for
only a part of the class library. We have an agenda, an we try to fix as
much bugs as possible, with the small team we have.

But this is free software after all, and sure you can help us if you
think it's a bad thing to have so many bugs opened.

And, btw, in general we feel we mwf is stable in general, but not
perfect (yet ;-D ).

Carlos.


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] DateTimePicker changes

2008-07-20 Thread Carlos Alberto Cortez
Hey,

While working on #, I found some small bits not matching .net. So
basically the attached patch:

* Doesn't change the DateTimePicker.Value property immediately when
editing -this means, when a user types a single digit-, but when the max
number of digits is reached *or* the selection moves to a different date
time section, or the checked state changes, or focus moves out of the
control, like .net does.

* Don't set at all the date entered by the user if is invalid. Just
ignore it and fallback to the current value.

* When painting, print the current editing text *if* we are actually
editing at the moment, or print the related Value otherwise.

* Use an enum to identify different date time parts (hour, minutes,
etc). This was done to avoid adding a new switch block when trying to
set the Value from a different part than KeyPress handler.

* Finally, infer the year when the user enters a two digit number, like
'99' or '34'. The behaviour I implemented is the one I observed in .Net,
but could not find something related to it in the docs.

Carlos.
Index: DateTimePicker.cs
===
--- DateTimePicker.cs	(revisión: 107947)
+++ DateTimePicker.cs	(copia de trabajo)
@@ -97,6 +97,9 @@
 
 		// variables for determining how to format the string
 		internal PartData[]	part_data;
+		internal int		editing_part_index = -1;
+		internal int 		editing_number = -1;
+		internal string		editing_text;
 
 		bool drop_down_button_entered;
 		#endregion	// Local variables
@@ -312,7 +315,7 @@
 	// invalidate the value inside this control
 	if (ShowCheckBox) {
 		for (int i = 0; i  part_data.Length; i++)
-			part_data [i].is_selected = false;
+			part_data [i].Selected = false;
 		Invalidate (date_area_rect);
 	}
 }
@@ -1145,7 +1148,7 @@
 	case 'g': // Spec says nothing about g, but it seems to be treated like spaces.
 		if (!(lastch == ch || lastch == 0)  literal.Length != 0)
 		{
-			formats.Add (new PartData(literal.ToString (), false));
+			formats.Add (new PartData(literal.ToString (), false, this));
 			literal.Length = 0;
 		}
 		literal.Append (ch);
@@ -1160,24 +1163,24 @@
 			is_literal = !is_literal;
 			break;
 		}
-		formats.Add (new PartData (literal.ToString (), is_literal));
+		formats.Add (new PartData (literal.ToString (), is_literal, this));
 		literal.Length = 0;
 		is_literal = !is_literal;
 		break;
 	default:
 		if (literal.Length != 0)
 		{
-			formats.Add (new PartData(literal.ToString (), false));
+			formats.Add (new PartData(literal.ToString (), false, this));
 			literal.Length = 0;
 		}
-		formats.Add (new PartData (ch.ToString(), true));
+		formats.Add (new PartData (ch.ToString(), true, this));
 		break;
 
 }
 lastch = ch;
 			}
 			if (literal.Length = 0)
-formats.Add (new PartData (literal.ToString (), is_literal));
+formats.Add (new PartData (literal.ToString (), is_literal, this));
 
 			part_data = new PartData [formats.Count];
 			formats.CopyTo (part_data);
@@ -1220,6 +1223,7 @@
 		// drop the calendar down
 		internal void DropDownMonthCalendar ()
 		{
+			EndDateEdit (true);
 			// ensure the right date is set for the month_calendar
 			month_calendar.SetDate (this.date_value);
 			// get a rectangle that has the dimensions of the text area,
@@ -1259,7 +1263,7 @@
 		{
 			for (int i = 0; i  part_data.Length; i++)
 			{
-if (part_data[i].is_selected  !part_data[i].is_literal)
+if (part_data[i].Selected  !part_data[i].is_literal)
 	return i;
 			}
 			return -1;
@@ -1273,55 +1277,42 @@
 return;
 			}
 			
-			switch (part_data[selected_index].value)
+			DateTimePart dt_part = part_data [selected_index].date_time_part;
+			switch (dt_part)
 			{
-case d:
-case dd: // number day formats
+case DateTimePart.Day:
 	if (delta  0) {
 		if (Value.Day == 1)
-			SetPart(DateTime.DaysInMonth(Value.Year, Value.Month), 'd');
+			SetPart(DateTime.DaysInMonth(Value.Year, Value.Month), dt_part);
 		else
-			SetPart(Value.Day + delta, 'd');
+			SetPart(Value.Day + delta, dt_part);
 	} else {
 		if (Value.Day == DateTime.DaysInMonth(Value.Year, Value.Month))
-			SetPart(1, 'd');
+			SetPart(1, dt_part);
 		else
-			SetPart(Value.Day + delta, 'd') ;
+			SetPart(Value.Day + delta, dt_part) ;
 	}
 	break;
-case ddd:
-case : // text day formats
+case DateTimePart.DayName:
 	Value = Value.AddDays(delta);
 	break;
-case h:
-case hh:
-case H:
-case HH: // hour formats
-	SetPart(Value.Hour + delta, 'h');
+case DateTimePart.Hour:
+	SetPart(Value.Hour + delta, dt_part);
 	break;
-case m:
-case mm: // minute formats
-	SetPart(Value.Minute + delta, 'm');
+case DateTimePart.Minutes:
+	SetPart(Value.Minute + delta, dt_part);
 	

[Mono-dev] [Patch] Implement basic AutoComplete support for ComboBox

2008-07-01 Thread Carlos Alberto Cortez
Hey!

Attached is a patch that implements support for ComboBox.

The idea is to use the available support in TextBox, so the TextBox has
direct access to our items. Since this is not the clearest approach,
it's the better in terms of performance, since otherwise we should
create a IList of item's text, and modifying or updating it as items are
modified in ComboBox.Items collection.

Observe that this patch only makes use of the basic properties of Auto
complete in TextBox. As soon as I check in the keyboard navigation in
TextBox for automplete, I will come with a second patch for ComboBox ;-)

Carlos.
Index: ComboBox.cs
===
--- ComboBox.cs	(revisión: 106985)
+++ ComboBox.cs	(copia de trabajo)
@@ -246,6 +246,8 @@
 
 if(auto_complete_custom_source != null)
 	auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
+
+SetTextBoxAutoCompleteData ();
 			}
 		}
 
@@ -263,6 +265,7 @@
 	throw new InvalidEnumArgumentException (Locale.GetText (Enum argument value '{0}' is not valid for AutoCompleteMode, value));
 
 auto_complete_mode = value;
+SetTextBoxAutoCompleteData ();
 			}
 		}
 
@@ -280,8 +283,27 @@
 	throw new InvalidEnumArgumentException (Locale.GetText (Enum argument value '{0}' is not valid for AutoCompleteSource, value));
 
 auto_complete_source = value;
+SetTextBoxAutoCompleteData ();
 			}
 		}
+
+		void SetTextBoxAutoCompleteData ()
+		{
+			if (textbox_ctrl == null)
+return;
+
+			textbox_ctrl.AutoCompleteMode = auto_complete_mode;
+
+			if (auto_complete_source == AutoCompleteSource.ListItems) {
+textbox_ctrl.AutoCompleteSource = AutoCompleteSource.CustomSource;
+textbox_ctrl.AutoCompleteCustomSource = null;
+textbox_ctrl.AutoCompleteInternalSource = this;
+			} else {
+textbox_ctrl.AutoCompleteSource = auto_complete_source;
+textbox_ctrl.AutoCompleteCustomSource = auto_complete_custom_source;
+textbox_ctrl.AutoCompleteInternalSource = null;
+			}
+		}
 #endif
 		public override Color BackColor {
 			get { return base.BackColor; }
@@ -433,6 +455,9 @@
 
 	if (IsHandleCreated == true)
 		Controls.AddImplicit (textbox_ctrl);
+#if NET_2_0
+	SetTextBoxAutoCompleteData ();
+#endif
 }
 
 ResumeLayout ();
Index: TextBox.cs
===
--- TextBox.cs	(revisión: 106985)
+++ TextBox.cs	(copia de trabajo)
@@ -27,6 +27,7 @@
 // NOT COMPLETE
 
 using System;
+using System.Collections;
 using System.ComponentModel;
 using System.ComponentModel.Design;
 using System.Drawing;
@@ -58,6 +59,7 @@
 		private AutoCompleteMode auto_complete_mode = AutoCompleteMode.None;
 		private AutoCompleteSource auto_complete_source = AutoCompleteSource.None;
 		private AutoCompleteListBox auto_complete_listbox;
+		private ComboBox auto_complete_cb_source;
 #endif
 		#endregion	// Variables
 
@@ -121,8 +123,14 @@
 return;
 
 			// We only support CustomSource by now
+			IList source;
+			if (auto_complete_cb_source == null)
+source = auto_complete_custom_source;
+			else
+source = auto_complete_cb_source.Items;
+
 			if (auto_complete_source != AutoCompleteSource.CustomSource ||
-auto_complete_custom_source == null || auto_complete_custom_source.Count == 0)
+source == null || source.Count == 0)
 return;
 
 			if (Text.Length == 0) {
@@ -142,10 +150,14 @@
 
 			string text = Text;
 			auto_complete_listbox.Items.Clear ();
-			foreach (string str in auto_complete_custom_source)
-if (str.StartsWith (text, StringComparison.CurrentCultureIgnoreCase))
-	auto_complete_listbox.Items.Add (str);
 
+			for (int i = 0; i  source.Count; i++) {
+string item_text = auto_complete_cb_source == null ? auto_complete_custom_source [i] :
+	auto_complete_cb_source.GetItemText (auto_complete_cb_source.Items [i]);
+if (item_text.StartsWith (text, StringComparison.CurrentCultureIgnoreCase))
+	auto_complete_listbox.Items.Add (item_text);
+			}
+
 			IListstring matches = auto_complete_listbox.Items;
 			if ((matches.Count == 0) ||
 (matches.Count == 1  matches [0].Equals (text, StringComparison.CurrentCultureIgnoreCase))) { // Exact single match
@@ -159,6 +171,15 @@
 			auto_complete_listbox.Location = PointToScreen (new Point (0, Height));
 			auto_complete_listbox.ShowListBox ();
 		}
+
+		internal ComboBox AutoCompleteInternalSource {
+			get {
+return auto_complete_cb_source;
+			}
+			set {
+auto_complete_cb_source = value;
+			}
+		}
 #endif
 
 		private void UpdateAlignment ()
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Mono C# Serial Port problem

2008-05-30 Thread Carlos Alberto Cortez
Would you mind filling a bug with the precise information?

Thanks,
Carlos.


El jue, 29-05-2008 a las 02:24 -0700, Bs360 escribió:
 
 
 Alan_Chun wrote:
  
  HI, currently I am porting a windows app to linux using Mono. I have some
  difficulties to get the serial port work. here is the code(based on mono
  website):
  
  
  I have also tried BytesToRead, Read, ReadByte, all of them are working
  fine under windows using .net2.0 framwork. But once I use the mono
  runtime, the nightmare begins.
  
  Any help will be really apprecaited!
  
  Thanks  
  
 
 I'm actually having the same problem. I'm using ubuntu 8.04.

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] ListBox.cs ownder draw variable size

2008-05-30 Thread Carlos Alberto Cortez
Hey, 

Two things for your next patch:

* Use the coding guidelines:
http://www.mono-project.com/Coding_Guidelines
* Send your patch as an attached file, not in the body of the message.

Committed your patch,
thanks for the correction!

Carlos.


El mié, 28-05-2008 a las 06:42 +0200, jkeymer escribió:
 Handles calculation if the listbox scroll area of variable high, owner
 draw boxes,
 
 Index: Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
 ===
 --- Managed.Windows.Forms/System.Windows.Forms/ListBox.cs(Revision
 103872)
 +++ Managed.Windows.Forms/System.Windows.Forms/ListBox.cs(Arbeitskopie)
 @@ -2145,9 +2145,20 @@
  last_visible_index = LastVisibleItem ();
 
  int diff = top_item - top_index;
 -
 +int delta = ItemHeight * diff;
 +if (DrawMode == DrawMode.OwnerDrawVariable) {
 +delta = 0;
 +if ( top_index  top_item ) {
 +for ( int i = top_index; i  top_item; i++ )
 +delta += GetItemHeight(i);
 +}
 +else {
 +for ( int i = top_item; i  top_index; i++ )
 +delta -= GetItemHeight(i);
 +}
 +}
  if (IsHandleCreated)
 -XplatUI.ScrollWindow (Handle, items_area, 0, ItemHeight
 * diff, false);
 +XplatUI.ScrollWindow (Handle, items_area, 0, delta, false);
  }
 
  #endregion Private Methods
 
 
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Mono C# Serial Port problem

2008-05-21 Thread Carlos Alberto Cortez
Hello,


 
 The issue with our code is that we call the Mono posix libraries, this
 is not cross platform.


Our implementation uses the Win32 api in windows and posix calls with a C 
helper layer in Unix platforms. 

Observe that we never tested it with Mac.

Since you are using the Mono.Posix library in Mac, it's likely possible
to use the same functionality using our C helper layer (it resides in
mono/support/serial.c). Probably we need to apply a pair of corrections
there, however.

Carlos.


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Mono C# Serial Port problem

2008-05-15 Thread Carlos Alberto Cortez
That's likely because 'mono test.exe' actually uses mono, and
'test.exe' runs .net instead.

This appears to be a bug.

Please fill a bug report with the attached repro.

Thanks!
Carlos


El jue, 15-05-2008 a las 12:01 -0700, Alan_Chun escribió:
 
 
 Panoramix wrote:
  
  In Linux to use a device the user who requires access should have the
  permission to use it. 
  So you must verify that the user starts the application is registered in
  the group owner of ttysN. 
  To find out the group owner of the device by a shell run the command
  below:
   
  ls-al / dev / ttyS *
  
  
 
 I haven't tried it under linux yet. What I meant is when I ran the
 exeutable, if I use mono test.exe through windows xp's command line, it
 will generate this error. However, if ran this exe directly (use test.exe
 only on the command line without mono), it worked fine.
 
 Any ideas?
 
 Thanks 
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Installing policy file in the GAC?

2008-03-05 Thread Carlos Alberto Cortez


 
 gacutil won't install a policy file in the GAC because the policy file isn't
 an assembly. So, obviously, I have to copy it there from the install script.
 But how can the install script find out where Mono is installed? Is there
 any command I can use to get at the Mono installation directory?
 

You don't copy the file directly - but use the assembly linker (al.exe)
to create an assembly based on the configuration file:


al /link:policy-file.config /out:policy.1.0.YourAssembly.dll 
/keyfile:YourAssemblyKey.snk

then you can just gacutil on the generated assembly:

gacutil -i policy.1.0.YourAssembly.dll

See http://msdn2.microsoft.com/en-us/library/dz32563a(vs.71).aspx

Carlos.

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Cache errno for serial port

2008-02-19 Thread Carlos Alberto Cortez
Hey Miguel,

Somehow I had this wrong idea that GetLastError would retrieve
windows-specific codes (not the ones errno gets).

Thanks,
Carlos.


El lun, 18-02-2008 a las 20:19 -0500, Miguel de Icaza escribió:
 Hello Carlos,
 
  The attached patch adds a 'serial_errno' variable in
  mono/support/serial.c, to cache the last error related to serial port
  functions.
  
  At first I tried to just create a function directly retrieving errno,
  but it was getting a different value from the original (probably some
  code modified it after the pinvoke call?).
  
  This is needed to a simple but better error reporting in the
  System.IO.Ports.SerialPort class.
 
 I think you can use DllImport's built-in SetLastError/GetLastError
 framework for this.
 
 Just add this to the DllImport definitions:
 
   [DllImport (something, SetLastError=true)]
 
 And then in the calling code, call:
 
   Marshal.GetLastWin32Error ()
 
 This will contain the errno value.

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [PATCH] Cache errno for serial port

2008-02-17 Thread Carlos Alberto Cortez
Hey,

The attached patch adds a 'serial_errno' variable in
mono/support/serial.c, to cache the last error related to serial port
functions.

At first I tried to just create a function directly retrieving errno,
but it was getting a different value from the original (probably some
code modified it after the pinvoke call?).

This is needed to a simple but better error reporting in the
System.IO.Ports.SerialPort class.
 1. 
Carlos.
Index: serial.c
===
--- serial.c	(revisión: 96026)
+++ serial.c	(copia de trabajo)
@@ -60,15 +60,16 @@
 	Rts = 16  /* Request to send */
 } MonoSerialSignal;
 
+/* Last error related to serial port */
+static int serial_errno;
+
 int
 open_serial (char* devfile)
 {
 	int fd;
 	fd = open (devfile, O_RDWR | O_NOCTTY | O_NONBLOCK);
+	serial_errno = errno;
 
-	if (fd == -1)
-		return -1;
-
 	return fd;
 }
 
@@ -79,11 +80,18 @@
 }
 
 guint32
-read_serial (int fd, guchar *buffer, int offset, int count)
+read_serial (int fd, guchar *buffer, int offset, int count, int timeout)
 {
 	guint32 n;
+	struct pollfd ufd;
+	ufd.events = POLLHUP | POLLIN | POLLERR;
+
+	poll (ufd, 1, timeout);
+	if ((ufd.revents  POLLIN) != POLLIN)
+		return -1;
  
 	n = read (fd, buffer + offset, count);
+	serial_errno = errno;
 
 	return (guint32) n;
 }
@@ -114,6 +122,7 @@
 		}		
 
  		t = write(fd, buffer + offset, count);
+		serial_errno = errno;
 		
 		if (timeout  0)
 		{
@@ -142,6 +151,7 @@
 	gint32 retval;
 
 	if (ioctl (fd, input ? FIONREAD : TIOCOUTQ, retval) == -1) {
+		serial_errno = errno;
 		return -1;
 	}
 
@@ -310,6 +320,7 @@
 	if (cfsetospeed (newtio, baud_rate)  0 || cfsetispeed (newtio, baud_rate)  0 ||
 	tcsetattr (fd, TCSANOW, newtio)  0)
 	{
+		serial_errno = errno;
 		return FALSE;
 	}
 	else
@@ -368,6 +379,7 @@
 	*error = 0;
 	
 	if (ioctl (fd, TIOCMGET, signals) == -1) {
+		serial_errno = errno;
 		*error = -1;
 		return NoneSignal;
 	}
@@ -393,8 +405,10 @@
 	else
 		signals = ~expected;
 	
-	if (ioctl (fd, TIOCMSET, signals) == -1)
+	if (ioctl (fd, TIOCMSET, signals) == -1) {
+		serial_errno = errno;
 		return -1;
+	}
 	
 	return 1;
 }
@@ -419,6 +433,7 @@
 	while (poll (pinfo, 1, timeout) == -1  errno == EINTR) {
 		/* EINTR is an OK condition, we should not throw in the upper layer an IOException */
 		if (errno != EINTR){
+			serial_errno = errno;
 			*error = -1;
 			return FALSE;
 		}
@@ -427,6 +442,12 @@
 	return (pinfo.revents  POLLIN) != 0 ? 1 : 0;
 }
 
+gint32
+get_last_serial_error ()
+{
+	return serial_errno;
+}
+
 /*
  * mono internals should not be used here.
  * this serial stuff needs to be implemented with icalls.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] SerialPort - patch waiting to apply

2007-07-01 Thread Carlos Alberto Cortez
El jue, 28-06-2007 a las 17:44 +0200, Leszek Ciesielski escribió:
 http://bugzilla.ximian.com/show_bug.cgi?id=78911
 
 There's a patch and Miguel's positive comment - can someone apply this, 
 please?

Sorry, I thought I had applied it already. This is now in SVN.

Thanks for the remainder.


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Bugzilla bugs needing attention

2007-03-05 Thread Carlos Alberto Cortez

  The others I'll verify the patches content and commit if no
 one objects in the next few hours. That if my networking troubles with
 access to Mono's SVN repository, doesn't forbid me. In that case I'll
 report in this thread.

It would be a good idea to also have some tests for those patches before
committing.

Carlos.

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Mono-list] serial port problem

2007-01-18 Thread Carlos Alberto Cortez
Hey,

Could you cook a test case? That way we can try to take a look at the
issue.

Carlos.

 
 First, I can succesfully read a text string, when I loopback a
 serial cable, connecting pins 2 and 3 I send the string and can
 read it immediatly, it worked fine for me in Linux (running mono as
 root, my mono version is 1.2.2). The code I used is the same found in
 http://www.mono-project.com/HowToSystemIOPorts
 
 But I cannot succeed in another mono application, where I try to
 communicate to an external device using modbus (binary protocol). The
 device correctly understands my query, and I know it responds (because
 a TX led blinks in the device), but mono can't get any data from the
 port. Depending on mono version, and whether I'm root or not, I can
 get two types of error... sometimes a timeout exception is raised,
 and sometimes i get a byte with a 255 value.
 
 I tryed other (non-mono) applications to communicate to the same
 external device, and they work ok in Linux, and also in Windows.
 
 I'm still debugging, but maybe there is something with DTR signals,
 etc., or maybe a bug with binary communications.
 
 i'll keep trying and will post if I find a solution
 
 if anyone got binary communications working OK, please inform what was
 the os distributon/ monon version used...eventually i could change my
 system set-up, if that fixed the problem
 
 thanks, Victor
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Patch] TreeView, TreeNode, TreeNodeCollection

2007-01-09 Thread Carlos Alberto Cortez

 
  +   public virtual void RemoveByKey(string key)
  +   {
  +   int index = -1;
  +   for (int i = 0; i  nodes.Count; i++)
  +   {
  +   if (!string.Equals(nodes[i].Name,key, 
  StringComparison.CurrentCultureIgnoreCase))
  +   continue;
  +
  +   index = i;
  +   break;
  +   }
 
 Ditto. Additionally, what happens on MS.NET if you remove the
 String.Empty key? What happens if the collection has duplicate keys?
 Will be the keys deleted all together or just the first/last/random
 occurrence?

As far as I can tell, RemoveByKey behaves just like the other
Key-related methods, so when passing a null or empty string it should do
nothing.

Also, when having duplicate keys, the method should remove the first
occurrence (at least that happens with ListView related collections, for
example).

Anyway, the best thing do do, as Robert said, is to write tests.

Carlos.




___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Generate Consts.vb from Consts.cs (new patch)

2006-08-24 Thread Carlos Alberto Cortez

 I might be wrong but I am wondering if it is consistent to use Perl for 
 this kind of things, inside the mono project. It would be more logical 
 to use Mono itself, and then not having another external dependency 
 (Mono depending on Perl??), right?

Just for the record: we already have perl scripts in the build system,
as well in gtk-sharp, for example.

Carlos.

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Use the correct type for S.D.Printing.PrintDocument.PrintController

2006-08-04 Thread Carlos Alberto Cortez
Hey,

I tried your sample with .Net 2.0, and got:

controller = System.Windows.Forms.PrintControllerWithStatusDialog

Probably in .Net 1.1 it's handled different (if you are using that
version, of course).

Carlos.

El mié, 02-08-2006 a las 07:45 -0400, Chris Toshok escribió:
 this doesn't work unless System.Windows.Forms is being used, it appears.
 
 The following test:
 
 using System;
 using System.Drawing;
 using System.Drawing.Printing;
 
 public class Foo {
   public static void Main (string[] args) {
 PrintDocument doc = new PrintDocument ();
 
 Console.WriteLine (controller = {0},
 doc.PrintController.GetType());
   }
 }
 
 outputs:
 
   controller = System.Drawing.Printing.StandardPrintController
 
 Chris
 
 On Wed, 2006-08-02 at 04:30 -0500, Carlos Alberto Cortez wrote:
  Hey,
  
  S.D.Printing.PrintDocument.PrintController has as default a new instance
  of S.W.F.PrintControllerWithStatusDialog, which is in SWF assembly. 
  
  The current code assigns a new instance of S.D.P.StandardPrintController
  to PrintDocument.PrintController, which isn't the right behaviour.
  
  The problem is that it's not a good idea to add System.Windows.Forms as
  a reference to the System.Drawing assembly IMHO. So, the approach is to
  load the SWD assembly using reflection and then cache the type .ctor.
  
  
  Also, PrintDocument.PrintController should be never null, and should get
  a new PrintControllerWithStatusDialog instance, just like .Net does.
  
  Carlos. 
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [PATCH] Use the correct type for S.D.Printing.PrintDocument.PrintController

2006-08-02 Thread Carlos Alberto Cortez
Hey,

S.D.Printing.PrintDocument.PrintController has as default a new instance
of S.W.F.PrintControllerWithStatusDialog, which is in SWF assembly. 

The current code assigns a new instance of S.D.P.StandardPrintController
to PrintDocument.PrintController, which isn't the right behaviour.

The problem is that it's not a good idea to add System.Windows.Forms as
a reference to the System.Drawing assembly IMHO. So, the approach is to
load the SWD assembly using reflection and then cache the type .ctor.


Also, PrintDocument.PrintController should be never null, and should get
a new PrintControllerWithStatusDialog instance, just like .Net does.

Carlos. 
Index: PrintDocument.cs
===
--- PrintDocument.cs	(revisión: 63154)
+++ PrintDocument.cs	(copia de trabajo)
@@ -34,6 +34,7 @@
 
 using System;
 using System.ComponentModel;
+using System.Reflection;
 
 namespace System.Drawing.Printing
 {
@@ -45,6 +46,8 @@
 		private PrinterSettings printersettings;
 		private PrintController printcontroller;
 		private string documentname;
+
+		static ConstructorInfo pcontroller_with_status_ctor;
 #if !(NET_1_0)
 		private bool originAtMargins = false; // .NET V1.1 Beta
 #endif
@@ -53,8 +56,20 @@
 			documentname = document; //offical default.
 			defaultpagesettings = new PageSettings(); // use default values of default printer
 			printersettings = new PrinterSettings(); // use default values
-			printcontroller = new StandardPrintController();
+			printcontroller = CreatePrintControllerWithStatusDialog (new StandardPrintController ());
 		}
+
+		PrintController CreatePrintControllerWithStatusDialog (PrintController underlying_pc)
+		{
+			if (pcontroller_with_status_ctor == null) {
+Assembly wf_assembly = Assembly.Load (System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089);
+Type pcontroller_with_status_type = wf_assembly.GetType (System.Windows.Forms.PrintControllerWithStatusDialog);
+pcontroller_with_status_ctor = pcontroller_with_status_type.GetConstructor (new Type [] {typeof (PrintController)});
+			}
+
+			PrintController retval = (PrintController) pcontroller_with_status_ctor.Invoke (new object [] {underlying_pc});
+			return retval;
+		}
 		
 		// properties
 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
@@ -89,7 +104,8 @@
 return printcontroller;
 			}
 			set{
-printcontroller = value;
+printcontroller = value == null ? 
+	CreatePrintControllerWithStatusDialog (new StandardPrintController ()) : value;
 			}
 		}
 
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Use the correct type for S.D.Printing.PrintDocument.PrintController

2006-08-02 Thread Carlos Alberto Cortez
Oh, that's perfect (I wasn't aware of that constant). 

Carlos.

El mié, 02-08-2006 a las 14:00 +0200, Robert Jordan escribió:
 Hey,
 
 Carlos Alberto Cortez wrote:
  +   Assembly wf_assembly = Assembly.Load 
  (System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, 
  PublicKeyToken=b77a5c561934e089);
 
 The version of the assembly is wrong.
 
 Please use the constant `Consts.AssemblySystem_Windows_Forms' instead
 of the hard coded assembly name.
 
 
 Robert
 
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] SerialPort and Ring Indicator signal

2006-05-23 Thread Carlos Alberto Cortez
Hey,

The functionality for serial port inside kernel32.dll allows to access
the RING signal (the wrapper class makes public the access to it), but
it's only available on Windows (kernel32.dll is a core windows library).
Of course you could try to wrap some functionality in Unix systems
-using termios and ioctl interfaces- in a new class.

But from the System.IO.Ports.SerialPort is not possible to access that
pin signal -because of the api compatibility-.

For monitoring the RING signal -only checking its state-, take a look at
SerialPort.SerialPinChange event (observe that RING signal is not yet
monitored, although doing it is a matter of adding some constants in a
pair of places). I will take a look at it on the weekend.

Carlos.

El mar, 23-05-2006 a las 09:53 +0200, jfm escribió:
 Thank you Carlos for your answer
 I'm not sure I've well undestound but here are some information about
 the app I'm porting.
 As serial port are not supported in .Net 1, the app was using the
 Rs232.vb class that is wide spread accros the internet... This class
 is some kind of wrapper upon the kernel32.dll... I'm not sure these
 informations are of any help...
 In you mail you said that RI can be monotored with events ?? please
 could you give mon hints about this ??? this could be a solution for
 me !
 Thank you.
 
 Jean-François
 
 PS : please forget my English ;)
 
 Carlos Alberto Cortez wrote: 
  Well, RING indicator can't be directly used (as opossed to Cts, Dsr, CD,
  Rts and Dtr). The public API in .Net does not expose this indicator
  directly (you can only monitor it based on the events).
  
  Of course we could add it to the get_signal_code () function and
  retrieve it. But the real problem is that we can't add it - we must keep
  compatibility with .Net API.
  
  Probably this is achieved in some way - since you mentioned that you are
  porting a .Net app-. But in that case, we must have additional info -and
  some code-.
  
  Carlos.
  
  El lun, 22-05-2006 a las 18:58 +0200, jfm escribió:

   Hi,
   I'm porting a program running on microsoft .net to mono. This program 
   uses modem information like Dsr and Cts but it also uses RI (ring 
   indicator).
   My problem is that RI doesn't seem to be supported (see enum 
   MonoSerialSignal in the get_signal_code function in serial.c), am I right 
   ?
   If yes, I could make the modification, I think it is only few lines 
   (adding a new entry to the enum and a if with TIOCM_RI (defined in 
   ioctl-type.h) in the function but it might involve recompiling a lots of 
   thing and I don't know how to do.
   
   Best regards
   
   Jean-François
   ___
   Mono-devel-list mailing list
   Mono-devel-list@lists.ximian.com
   http://lists.ximian.com/mailman/listinfo/mono-devel-list
   
  
  

 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] SerialPort and Ring Indicator signal

2006-05-22 Thread Carlos Alberto Cortez
Well, RING indicator can't be directly used (as opossed to Cts, Dsr, CD,
Rts and Dtr). The public API in .Net does not expose this indicator
directly (you can only monitor it based on the events).

Of course we could add it to the get_signal_code () function and
retrieve it. But the real problem is that we can't add it - we must keep
compatibility with .Net API.

Probably this is achieved in some way - since you mentioned that you are
porting a .Net app-. But in that case, we must have additional info -and
some code-.

Carlos.

El lun, 22-05-2006 a las 18:58 +0200, jfm escribió:
 Hi,
 I'm porting a program running on microsoft .net to mono. This program 
 uses modem information like Dsr and Cts but it also uses RI (ring 
 indicator).
 My problem is that RI doesn't seem to be supported (see enum 
 MonoSerialSignal in the get_signal_code function in serial.c), am I right ?
 If yes, I could make the modification, I think it is only few lines 
 (adding a new entry to the enum and a if with TIOCM_RI (defined in 
 ioctl-type.h) in the function but it might involve recompiling a lots of 
 thing and I don't know how to do.
 
 Best regards
 
 Jean-François
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] mono/support/serial.c

2006-04-07 Thread Carlos Alberto Cortez
Hello,

The attached patch has some changed that I need to apply some others in
the C# side in the class library.

Is it ok to commit?

Carlos.
Index: serial.c
===
--- serial.c	(revisión: 59128)
+++ serial.c	(copia de trabajo)
@@ -41,11 +41,12 @@
 
 /* This is a copy of System.IO.Ports.SerialSignal */
 typedef enum {
-	Cd = 0, /* Carrier detect */
-	Cts = 1, /* Clear to send */
-	Dsr = 2, /* Data set ready */
-	Dtr = 3, /* Data terminal ready */
-	Rts = 4  /* Request to send */
+	NoneSignal,
+	Cd = 1, /* Carrier detect */
+	Cts = 2, /* Clear to send */
+	Dsr = 4, /* Data set ready */
+	Dtr = 8, /* Data terminal ready */
+	Rts = 16  /* Request to send */
 } MonoSerialSignal;
 
 int
@@ -67,8 +68,6 @@
 	tcflush(fd, TCIOFLUSH);
 	tcsetattr(fd,TCSANOW,newtio);
 
-	fcntl (fd, F_SETFL, O_NONBLOCK);
-
 	return fd;
 }
 
@@ -79,19 +78,9 @@
 }
 
 guint32
-read_serial (int fd, guchar *buffer, int offset, int count, int timeout)
+read_serial (int fd, guchar *buffer, int offset, int count)
 {
 	guint32 n;
-	struct pollfd ufd;
-
-	ufd.fd = fd;
-	ufd.events = POLLHUP | POLLIN | POLLERR;
-
-	poll (ufd, 1, timeout);
-
-	if ((ufd.revents  POLLIN) != POLLIN) {
-		return -1;
-	}
  
 	n = read (fd, buffer + offset, count);
 
@@ -123,6 +112,20 @@
 	tcflush(fd, input ? TCIFLUSH : TCOFLUSH);
 }
 
+gint32
+get_bytes_in_buffer (int fd, gboolean input, gint32 *error)
+{
+	gint32 retval;
+
+	*error = 0;
+	if (ioctl (fd, input ? TIOCINQ : TIOCOUTQ, retval) == -1) {
+		*error = -1;
+		return -1;
+	}
+
+	return retval;
+}
+
 gboolean
 set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake)
 {
@@ -249,22 +252,42 @@
 			return TIOCM_DTR;
 		case Rts:
 			return TIOCM_RTS;
+		default:
+			return 0;
 	}
 
 	/* Not reached */
 	return 0;
 }
 
+static MonoSerialSignal
+get_mono_signal_codes (int signals)
+{
+	MonoSerialSignal retval = NoneSignal;
+
+	if ((signals  TIOCM_CAR) != 0)
+		retval |= Cd;
+	if ((signals  TIOCM_CTS) != 0)
+		retval |= Cts;
+	if ((signals  TIOCM_DSR) != 0)
+		retval |= Dsr;
+	if ((signals  TIOCM_DTR) != 0)
+		retval |= Dtr;
+	if ((signals  TIOCM_RTS) != 0)
+		retval |= Rts;
+
+	return retval;
+}
+
 gint32
-get_signal (int fd, MonoSerialSignal signal)
+get_signals (int fd)
 {
-	int signals, expected;
+	int signals;
 
-	expected = get_signal_code (signal);
 	if (ioctl (fd, TIOCMGET, signals) == -1)
 		return -1;
 	
-	return (expected  signals) != 0;
+	return get_mono_signal_codes (signals);
 }
 
 gint32
@@ -291,6 +314,21 @@
 	return 1;
 }
 
+gint32
+poll_serial (int fd)
+{
+	struct pollfd pinfo;
+	
+	pinfo.fd = fd;
+	pinfo.events = POLLIN;
+	pinfo.revents = 0;
+
+	if (poll (pinfo, 1, 0) == -1)
+		return -1;
+
+	return (pinfo.revents  POLLIN) != 0 ? 1 : 0;
+}
+
 /*
  * mono internals should not be used here.
  * this serial stuff needs to be implemented with icalls.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Re: Profiling output

2006-03-24 Thread Carlos Alberto Cortez
Hello,

A pair of years ago I wrote a small patch for saving the profile output
to a xml file. It's almost sure that you won't be able to apply this
patch to the current sources, but it could help you to write a custom
profiler or just 'catch' the info.

Carlos.

El vie, 24-03-2006 a las 07:44 +0100, Jacob Ilsø Christensen escribió:
 Hi.
 
 On 3/23/06, Robert Jordan [EMAIL PROTECTED] wrote:
  Hey,
 
  Jacob Ilsø Christensen wrote:
   Hi.
  
   I have been experimenting a bit with monos profiling option. I run
   mono like this:
  
   mono --profile=default:time A.exe
  
   This results in the profiling information being printed to stdout. Is
   there a way to redirect this information to e.g. a file to prevent it
   from being mixed with the output from the program (A.exe) itself?
 
  It depends on your shell. With sh/bash you can redirect both
  output streams to different files:
 
  mono --profile=default:time A.exe  2 errors  1 output
 
 That's not exactly what I meant. What I want is a way to prevent the
 output from the profiler from being mingled with the output from the
 application being profiled.
 
 Any ideas?
 
 /Jacob
 
 
  Robert
 
  ___
  Mono-devel-list mailing list
  Mono-devel-list@lists.ximian.com
  http://lists.ximian.com/mailman/listinfo/mono-devel-list
 
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list
? xml_profile.diff
Index: profiler.c
===
RCS file: /cvs/public/mono/mono/metadata/profiler.c,v
retrieving revision 1.20
diff -u -r1.20 profiler.c
--- profiler.c	22 Mar 2004 17:48:46 -	1.20
+++ profiler.c	24 Mar 2004 02:45:20 -
@@ -7,6 +7,8 @@
 #include gmodule.h
 
 static MonoProfiler * current_profiler = NULL;
+static const char *profiler_xml_file = NULL;
+static FILE *xml_file = NULL;
 
 static MonoProfileAppDomainFunc   domain_start_load;
 static MonoProfileAppDomainResult domain_end_load;
@@ -682,6 +684,61 @@
 	printf (Total number of calls: %lld\n, total_calls);
 }
 
+static guint64
+total_number_calls (GList *funcs)
+{
+	GList *tmp;
+	MethodProfile *mp;
+	guint64 total_calls = 0;
+
+	for (tmp = funcs; tmp; tmp = tmp-next) {
+		mp = tmp-data;
+		total_calls += mp-count;
+	}
+
+	return total_calls;
+}
+
+static gboolean output_callers_xml (MethodProfile *p);
+
+static gboolean
+output_profile_xml (GList *funcs)
+{
+	char *m;
+	GList *tmp;
+	guint64 total_calls;
+	int length;
+	MethodProfile *p;
+
+	total_calls = total_number_calls (funcs);
+	length = fprintf (xml_file, \ttime calls=\%lld\\n, total_calls);
+	if (length  0)
+		return FALSE;
+
+	for (tmp = funcs; tmp; tmp = tmp-next) {
+		p = tmp-data;
+
+		if (!(gint)(p-total*1000))
+			continue;
+
+		m = method_get_name (p-method);
+		length = fprintf (xml_file, \t\tmethod count=\%llu\ name=\%s\ time=\%f\ total=\%f\\n,
+p-count, m, (double) (p-total * 1000)/(double) p-count, (double) p-total * 1000);
+		
+		if (length  0 || !output_callers_xml (p))
+			return FALSE;
+
+		length = fprintf (xml_file, \t\t/method\n);
+		g_free (m);
+
+		if (length  0)
+			return FALSE;
+	}
+	length = fprintf (xml_file, \t/time\n);
+	
+	return (length  0)?TRUE:FALSE;
+}
+
 typedef struct {
 	MethodProfile *mp;
 	guint count;
@@ -766,6 +823,106 @@
 	}
 }
 
+static gboolean
+output_callers_xml (MethodProfile *p) {
+	char *m;
+	guint total_callers, percent;
+	int length;
+	CallerInfo *cinfo;
+	GSList *sorted, *tmps;
+
+	total_callers = 0;
+	for (cinfo = p-caller_info; cinfo; cinfo = cinfo-next)
+		total_callers += cinfo-count;
+	sorted = sort_caller_list (p-caller_info);
+	for (tmps = sorted; tmps; tmps = tmps-next) {
+		cinfo = tmps-data;
+		percent = (cinfo-count * 100)/total_callers;
+		if (percent  1)
+			continue;
+		m = method_get_name (cinfo-caller);
+		length = fprintf (xml_file, \t\t\tcaller count=\%d\ name=\%s\ percent=\%d\/\n,
+cinfo-count, m, percent);
+		g_free (m);
+		if (length  0)
+			return FALSE;
+	}
+
+	return TRUE;
+}
+
+static guint
+total_allocated_mem (GList *proflist)
+{
+	GList *tmp;
+	NewobjProfile *p;
+	guint total = 0;
+
+	for (tmp = proflist; tmp; tmp = tmp-next) {
+		p = tmp-data;
+		total += p-count;
+	}
+
+	return total;
+}
+
+static gboolean
+output_newobj_profile_xml (GList *proflist)
+{
+	AllocInfo *ainfo;
+	GList *tmp;
+	GSList *sorted, *tmps;
+	MethodProfile *mp;
+	MonoClass *klass;
+	NewobjProfile *p;
+	const char *isarray;
+	char *m;
+	char buf [256];
+	guint total;
+	int length;
+
+	total = total_allocated_mem (proflist);
+	length = fprintf (xml_file, \tallocation mem=\%d\\n, total / 1024);
+	if (length  0)
+		return FALSE;
+	for (tmp = proflist; tmp; tmp = tmp-next) {
+		p = tmp-data;
+		if (p-count  5)
+			continue;
+		mp = p-mp;
+		m = method_get_name (mp-method);
+		length = fprintf (xml_file, \t\tmethod size=\%d\ name=\%s\\n, p-count / 1024, m);
+		g_free (m);
+		if 

[Mono-dev] [Patch] Signals access in mono/support/serial

2006-03-14 Thread Carlos Alberto Cortez
Hello,

The attached patch adds a pair of small functions to access signals
information for the serial port. 

Carlos.
Index: serial.c
===
--- serial.c	(revisión: 57943)
+++ serial.c	(copia de trabajo)
@@ -10,6 +10,7 @@
 #include fcntl.h
 #include string.h
 #include sys/poll.h
+#include sys/ioctl.h
 
 #include glib.h
 
@@ -202,6 +203,62 @@
 	return TRUE;
 }
 
+static gint32
+get_signal_code (MonoSerialSignal signal)
+{
+	switch (signal) {
+		case Cd:
+			return TIOCM_CAR;
+		case Cts:
+			return TIOCM_CTS;
+		case Dsr:
+			return TIOCM_DSR;
+		case Dtr:
+			return TIOCM_DTR;
+		case Rts:
+			return TIOCM_RTS;
+	}
+
+	/* Not reached */
+	return 0;
+}
+
+gint32
+get_signal (int fd, MonoSerialSignal signal)
+{
+	int signals, expected;
+
+	expected = get_signal_code (signal);
+	if (ioctl (fd, TIOCMGET, signals) == -1)
+		return -1;
+	
+	return (expected  signals) != 0;
+}
+
+gint32
+set_signal (int fd, MonoSerialSignal signal, gboolean value)
+{
+	int signals, expected, activated;
+
+	expected = get_signal_code (signal);
+	if (ioctl (fd, TIOCMGET, signals) == -1)
+		return -1;
+	
+	activated = (signals  expected) != 0;
+	if (activated == value) /* Already set */
+		return 1;
+	
+	if (value)
+		signals |= expected;
+	else
+		signals = ~expected;
+	
+	if (ioctl (fd, TIOCMSET, signals) == -1)
+		return -1;
+	
+	return 1;
+}
+
 /*
  * mono internals should not be used here.
  * this serial stuff needs to be implemented with icalls.
Index: serial.h
===
--- serial.h	(revisión: 57943)
+++ serial.h	(copia de trabajo)
@@ -27,5 +27,14 @@
 	OnePointFive = 3
 } MonoStopBits;
 
+/* This is a copy of System.IO.Ports.SerialSignal */
+typedef enum {
+	Cd = 0, /* Carrier detect */
+	Cts = 1, /* Clear to send */
+	Dsr = 2, /* Data set ready */
+	Dtr = 3, /* Data terminal ready */
+	Rts = 4  /* Request to send */
+} MonoSerialSignal;
+
 #endif
 
Index: ChangeLog
===
--- ChangeLog	(revisión: 57943)
+++ ChangeLog	(copia de trabajo)
@@ -1,3 +1,7 @@
+2006-03-14  Carlos Alberto Cortez [EMAIL PROTECTED]
+
+	* serial.c: Add functions to handle signals access.
+
 2006-03-09  Carlos Alberto Cortez [EMAIL PROTECTED]
 
 	* serial.c: Fix a pair of wrong or incomplete assignations
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] Stream 2.0 updates

2006-02-28 Thread Carlos Alberto Cortez
Hey,

This patch adds some of the new 2.0 members to System.IO.Stream. No
problems appeared when building, and only got some warnings (they can be
removed adding 'override' to the child streams).

Carlos.
Index: Stream.cs
===
--- Stream.cs	(revisión: 57384)
+++ Stream.cs	(copia de trabajo)
@@ -63,6 +63,14 @@
 			get;
 		}
 
+#if NET_2_0
+		public virtual bool CanTimeout {
+			get {
+return false;
+			}
+		}
+#endif
+
 		public abstract long Length
 		{
 			get;
@@ -94,6 +102,24 @@
 		{
 			Close ();
 		}
+
+		public virtual int ReadTimeout {
+			get {
+throw new InvalidOperationException (Timeouts are not supported on this stream.);
+			}
+			set {
+throw new InvalidOperationException (Timeouts are not supported on this stream.);
+			}
+		}
+
+		public virtual int WriteTimeout {
+			get {
+throw new InvalidOperationException (Timeouts are not supported on this stream.);
+			}
+			set {
+throw new InvalidOperationException (Timeouts are not supported on this stream.);
+			}
+		}
 #endif
 
 		protected virtual WaitHandle CreateWaitHandle()
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] Constant changes in mono/support/serial.c

2006-02-22 Thread Carlos Alberto Cortez
Hello,

The attached patch updates some comparisons in mono/support/serial.c
(some values inside System.IO.Ports changed and need to be taken in
count).

May I proceed?

Carlos.
Index: serial.c
===
--- serial.c	(revisión: 56687)
+++ serial.c	(copia de trabajo)
@@ -121,21 +121,21 @@
 	}
 
 	switch (parity) {
-	case 0: /* Even */
-		newtio.c_iflag = ~IGNPAR;
-		newtio.c_cflag |= PARENB;
-		break;
-	case 1: /* Mark */
-		/* XXX unhandled */
-		break;
-	case 2: /* None */
+	case 0: /* None */
 		newtio.c_iflag |= IGNPAR;
 		newtio.c_cflag = ~(PARENB | PARODD);
 		break;
-	case 3: /* Odd */
+	case 1: /* Odd */
 		newtio.c_iflag = ~IGNPAR;
 		newtio.c_cflag |= PARENB | PARODD;
 		break;
+	case 2: /* Even */
+		newtio.c_iflag = ~IGNPAR;
+		newtio.c_cflag |= PARENB;
+		break;
+	case 3: /* Mark */
+		/* XXX unhandled */
+		break;
 	case 4: /* Space */
 		/* XXX unhandled */
 		break;
@@ -154,10 +154,10 @@
 
 	newtio.c_cflag = ~CSTOPB;
 	switch (stopBits) {
-	case 0: /* One */
+	case 1: /* One */
 		/* do nothing, the default is one stop bit */
 		break;
-	case 1: /* OnePointFive */
+	case 3: /* OnePointFive */
 		/* XXX unhandled */
 		break;
 	case 2: /* Two */
@@ -174,27 +174,26 @@
 	case 0: /* None */
 		/* do nothing */
 		break;
-	case 1: /* RequestToSend (RTS) */
+	case 2: /* RequestToSend (RTS) */
 #ifdef CRTSCTS
 		newtio.c_cflag |= CRTSCTS;
 #endif /* def CRTSCTS */
 		break;
-	case 2: /* RequestToSendXOnXOff (RTS + XON/XOFF) */
+	case 3: /* RequestToSendXOnXOff (RTS + XON/XOFF) */
 #ifdef CRTSCTS
 		newtio.c_cflag |= CRTSCTS;
 #endif /* def CRTSCTS */
 		/* fall through */
-	case 3: /* XOnXOff */
+	case 1: /* XOnXOff */
 		newtio.c_iflag |= IXOFF;
 		//		newtio.c_oflag |= IXON;
 		break;
 	}
 	
-	cfsetospeed (newtio, baud_rate);
-	cfsetispeed (newtio, baud_rate);
+	if (cfsetospeed (newtio, baud_rate)  0 || cfsetispeed (newtio, baud_rate)  0 ||
+			tcsetattr (fd, TCSADRAIN, newtio)  0)
+		return FALSE;
 
-	tcsetattr(fd,TCSADRAIN,newtio);
-
 	return TRUE;
 }
 
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Assembly Mono.Cecil not found while compiling

2006-02-21 Thread Carlos Alberto Cortez
Yes, tha's the way it works: you install the assembly in the GAC, and
_optionally_ set pkg info for the assembly. So, yes, you need to have
the assembly in GAC even when using the pkg option.

El dom, 19-02-2006 a las 17:33 +0530, vijaya raghava mutharaju escribió:
 
Hi,
 
  Thank you Robert and Carlos. I compiled with the -pkg option
 and did it successfully. But when I remove the Mono.Cecil.dll assembly
 from the GAC, it is still giving complaints. I have to do both. Use
 -pkg option as well as keep it in GAC. Thanks once again.
 
 
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Assembly Mono.Cecil not found while compiling

2006-02-17 Thread Carlos Alberto Cortez
Hello, 

I would like to add something that could be of help:

Installing assemblies in tha GAC doesn't mean you can reference them
using the '-r' option (this -r option applies to the assembly path, such
MyAssembly.dll or ../Something/MyAssembly.dll
or /fullpath/MyAssembly.dll). The exceptions to the rule are mscorlib,
System and System.Xml assemblies.

Installing the assemblies in GAC means that after you _compiled_ your
app, the referenced assemblies will be looked up inside it (so basically
GAC is used rather for deployment than for development). Of course you
can pass the full path of the assembly inside the GAC to -r option, or
copy it to your current directory, for example.

Note that some assemblies include some additional info, which is used
with -pkg option, as Robert pointed out (so you don't need to copy the
assembly or pass the full path to -r option, and basically mess with the
GAC).

Hope it helps.
Carlos.

El sáb, 18-02-2006 a las 02:15 +0100, Robert Jordan escribió:
 Hey,
 
  I installed Mono and Cecil. Tried to compile a sample application
  using Mono.Cecil. But the mcs compiler is giving error messages that it
  cannot find Mono.Cecil.
  
  I installed Mono.Cecil.dll into the GAC successfully. Generated a
  key and recompiled Mono.Cecil.dll.sources with the -keyfile:mykey.snkoption.
 
 Since Cecil is a package, you don't need to mess with the GAC. Just
 apply the -pkg option to mcs:
 
 mcs -pkg:mono-cecil ...
 
 Robert
 
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] Re: [Fwd: [Mono-patches] r56693 - trunk/mcs/class/System/System.Net]

2006-02-09 Thread Carlos Alberto Cortez
Hey,

thanks for the report, I think I've been messing the things the latest
days with small things :-(

Carlos.

El jue, 09-02-2006 a las 17:13 +0900, Atsushi Eno escribió:
 
 svn up -r 56692 in 


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Remove version numbers from MonoReflectionAssemblyName

2005-12-14 Thread Carlos Alberto Cortez
Anything else?

Is it ok to commit it?

Carlos.

El lun, 12-12-2005 a las 19:36 -0500, Ben Maurer escribió:
 On Mon, 2005-12-12 at 15:33 -0600, Carlos Alberto Cortez wrote:
  Hey,
  
  This small patch removes the versions numbers from
  MonoReflectionAssemblyName, which are unnecessary since we have a
  Version field inside it.
  
  May I commit?
 
 This needs a corlib version bump.
 
 -- Ben
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [PATCH] Remove version numbers from MonoReflectionAssemblyName

2005-12-12 Thread Carlos Alberto Cortez
Hey,

This small patch removes the versions numbers from
MonoReflectionAssemblyName, which are unnecessary since we have a
Version field inside it.

May I commit?
Index: icall.c
===
--- icall.c	(revisión: 54166)
+++ icall.c	(copia de trabajo)
@@ -3730,6 +3730,7 @@
 	for (i = 0; i  count; i++) {
 		MonoReflectionAssemblyName *aname;
 		guint32 cols [MONO_ASSEMBLYREF_SIZE];
+		int major, minor, build, revision;
 
 		mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
 
@@ -3738,14 +3739,15 @@
 
 		aname-name = mono_string_new (domain, mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_NAME]));
 
-		aname-major = cols [MONO_ASSEMBLYREF_MAJOR_VERSION];
-		aname-minor = cols [MONO_ASSEMBLYREF_MINOR_VERSION];
-		aname-build = cols [MONO_ASSEMBLYREF_BUILD_NUMBER];
-		aname-revision = cols [MONO_ASSEMBLYREF_REV_NUMBER];
 		aname-flags = cols [MONO_ASSEMBLYREF_FLAGS];
 		aname-versioncompat = 1; /* SameMachine (default) */
 		aname-hashalg = ASSEMBLY_HASH_SHA1; /* SHA1 (default) */
-		aname-version = create_version (domain, aname-major, aname-minor, aname-build, aname-revision);
+		
+		major = cols [MONO_ASSEMBLYREF_MAJOR_VERSION];
+		minor = cols [MONO_ASSEMBLYREF_MINOR_VERSION];
+		build = cols [MONO_ASSEMBLYREF_BUILD_NUMBER];
+		revision = cols [MONO_ASSEMBLYREF_REV_NUMBER];
+		aname-version = create_version (domain, major, minor, build, revision);
 
 		if (create_culture) {
 			gpointer args [1];
@@ -4166,10 +4168,6 @@
 	MONO_ARCH_SAVE_REGS;
 
 	aname-name = mono_string_new (domain, name-name);
-	aname-major = name-major;
-	aname-minor = name-minor;
-	aname-build = name-build;
-	aname-revision = name-revision;
 	aname-hashalg = name-hash_alg;
 	if (by_default_version)
 		aname-version = create_version (domain, name-major, name-minor, name-build, name-revision);
Index: object-internals.h
===
--- object-internals.h	(revisión: 54166)
+++ object-internals.h	(copia de trabajo)
@@ -902,7 +902,6 @@
 	MonoObject  obj;
 	MonoString *name;
 	MonoString *codebase;
-	gint32 major, minor, build, revision;
 	MonoObject  *cultureInfo;
 	guint32 flags;
 	guint32 hashalg;
Index: AssemblyName.cs
===
--- AssemblyName.cs	(revisión: 54166)
+++ AssemblyName.cs	(copia de trabajo)
@@ -59,7 +59,6 @@
 		#region Synch with object-internals.h
 		string name;
 		string codebase;
-		int major, minor, build, revision;
 		CultureInfo cultureinfo;
 		AssemblyNameFlags flags;
 		AssemblyHashAlgorithm hashalg;
@@ -200,6 +199,7 @@
 
 			set {
 version = value;
+/*
 if (value == null)
 	major = minor = build = revision = 0;
 else {
@@ -207,7 +207,7 @@
 	minor = value.Minor;
 	build = value.Build;
 	revision = value.Revision;
-}
+}*/
 			}
 		}
 
@@ -291,10 +291,6 @@
 			AssemblyName an = new AssemblyName ();
 			an.name = name;
 			an.codebase = codebase;
-			an.major = major;
-			an.minor = minor;
-			an.build = build;
-			an.revision = revision;
 			an.version = version;
 			an.cultureinfo = cultureinfo;
 			an.flags = flags;
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [PATCH] Update InternalsVisibleTo check

2005-11-12 Thread Carlos Alberto Cortez
Hey,

The attached patch updates the check when using
InternalsVisibleToAttribute, to have the same behaviour of release
of .Net 2.0 (to include the entire key, not the key token).

Carlos.
Index: codegen.cs
===
--- codegen.cs	(revisión: 52934)
+++ codegen.cs	(copia de trabajo)
@@ -1242,9 +1242,9 @@
 			else if (aname.Version != null || aname.CultureInfo != null)
 throw new Exception (Friend assembly ` + a.GetString () + 
 		' is invalid. InternalsVisibleTo cannot have version or culture specified.);
-			else if (aname.GetPublicKeyToken () == null  Name.GetPublicKeyToken () != null) {
+			else if (aname.GetPublicKey () == null  Name.GetPublicKey () != null) {
 Report.Error (1726, a.Location, Friend assembly reference ` + aname.FullName + ' is invalid. +
-		 Strong named assemblies must specify a public key token in their InternalsVisibleTo declarations);
+		 Strong named assemblies must specify a public key in their InternalsVisibleTo declarations);
 return false;
 			}
 
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Friend access for class members

2005-11-01 Thread Carlos Alberto Cortez
Hey,

Sorry for answering this late, I was working on other things and forgot
this patch ;-)

I've been profiling the consumed memory before and after this patch with
heap-buddy, and everything looks to be working fine (no memory
regression, at least in managed world).

I got the next summaries building corlib 2.0 when profiling with
heap-buddy:

Before the patch:
-
   SUMMARY

 Filename: outfile
  Allocated Bytes: 146,8M
Allocated Objects: 3836366
  GCs: 32
  Resizes: 25
  Final heap size: 74,7M

   Distinct Types: 485
   Backtraces: 214225


After the patch:
-

   SUMMARY

 Filename: outfile2
  Allocated Bytes: 146,8M
Allocated Objects: 3836368
  GCs: 31
  Resizes: 25
  Final heap size: 74,7M

   Distinct Types: 485
   Backtraces: 214226


So I think no important issues appear applying the patch.

Any comment?

Carlos.

El vie, 28-10-2005 a las 11:01 -0400, Miguel de Icaza escribió:
 Hello,
 
 One final comment: please profile the code before and after, and
 lets explore if there are any  regressions memory-allocation wise.
 
 Miguel.
 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [PATCH] Friend access for class members

2005-10-28 Thread Carlos Alberto Cortez
Hey,

The attached patch implements friend access for class members (methods,
properties, fields). 

I'm not including the type-check section, since that part will be
modified (next merge to gmcs) and I'm waiting for that to happen.
However, that change should be small (I will send the patch).

I'm also attaching the error reported when using it (cs0281) and some
tests for various scenarios.

Thanks in advance for the comments.
Carlos.
Index: typemanager.cs
===
--- typemanager.cs	(revisión: 52299)
+++ typemanager.cs	(copia de trabajo)
@@ -265,6 +265,8 @@
 	static Hashtable fieldbuilders_to_fields;
 	static Hashtable fields;
 
+	static PtrHashtable assembly_internals_vis_attrs;
+
 	struct Signature {
 		public string name;
 		public Type [] args;
@@ -289,6 +291,8 @@
 		priv_fields_events = null;
 
 		type_hash = null;
+
+		assembly_internals_vis_attrs = null;
 		
 		CleanUpGenerics ();
 		TypeHandle.CleanUp ();
@@ -393,6 +397,8 @@
 		fieldbuilders_to_fields = new Hashtable ();
 		fields = new Hashtable ();
 		type_hash = new DoubleHash ();
+
+		assembly_internals_vis_attrs = new PtrHashtable ();
 		
 		InitGenerics ();
 	}
@@ -1822,6 +1828,80 @@
 		return false;
 	}
 
+	//
+	// Checks whether `extern_type' is friend of the output assembly
+	//
+	public static bool IsFriendAssembly (Assembly assembly)
+	{
+		if (assembly_internals_vis_attrs.Contains (assembly))
+			return (bool)(assembly_internals_vis_attrs [assembly]);
+		
+		object [] attrs = assembly.GetCustomAttributes (internals_visible_attr_type, false);
+		if (attrs.Length == 0) {
+			AddFriendAssembly (assembly, false);
+			return false;
+		}
+
+		AssemblyName this_name = CodeGen.Assembly.Name;
+		byte [] this_token = this_name.GetPublicKeyToken ();
+		bool is_friend = false;
+		foreach (object o in attrs) {
+			InternalsVisibleToAttribute attr = o as InternalsVisibleToAttribute;
+			if (attr.AssemblyName == null || attr.AssemblyName.Length == 0)
+continue;
+			
+			AssemblyName aname = null;
+			try {
+aname = new AssemblyName (attr.AssemblyName);
+			} catch (FileLoadException) {
+			} catch (ArgumentException) {
+			}
+
+			if (aname == null || aname.Name != this_name.Name)
+continue;
+			
+			byte [] key_token = aname.GetPublicKeyToken ();
+			if (key_token != null) {
+if (this_token == null) {
+	// Same name, but key token is null
+	Error_FriendAccessNameNotMatching (aname.FullName);
+	break;
+}
+
+if (!CompareKeyTokens (this_token, key_token))
+	continue;
+			}
+
+			is_friend = true;
+			break;
+		}
+
+		AddFriendAssembly (assembly, is_friend);
+		return is_friend;
+	}
+
+	static bool CompareKeyTokens (byte [] token1, byte [] token2)
+	{
+		for (int i = 0; i  token1.Length; i++)
+			if (token1 [i] != token2 [i])
+return false;
+
+		return true;
+	}
+
+	static string this_fullname;
+	
+	static void Error_FriendAccessNameNotMatching (string other_name)
+	{
+		if (this_fullname == null)
+			this_fullname = CodeGen.Assembly.Name.FullName;
+		
+		Report.Error (281, Friend access was granted to ` + other_name + 
+', but the output assembly is named ` + this_fullname +
+'. Try adding a reference to ` + other_name + 
+' or change the output assembly name to match it.);
+	}
+	
 //
 // Do the right thing when returning the element type of an
 // array type based on whether we are compiling corlib or not
@@ -2646,25 +2726,38 @@
 MethodBase mb = (MethodBase) m;
 MethodAttributes ma = mb.Attributes  MethodAttributes.MemberAccessMask;
 
+if (ma == MethodAttributes.Public)
+	return true;
+
 if (ma == MethodAttributes.Private)
 	return private_ok ||
 		IsPrivateAccessible (invocation_type, m.DeclaringType) ||
 		IsNestedChildOf (invocation_type, m.DeclaringType);
 
-if (invocation_assembly == mb.DeclaringType.Assembly) {
+if (invocation_assembly == mb.DeclaringType.Assembly)
 	if (ma == MethodAttributes.Assembly || ma == MethodAttributes.FamORAssem)
 		return true;
-} else {
-	if (ma == MethodAttributes.Assembly || ma == MethodAttributes.FamANDAssem)
-		return false;
+	
+if (ma == MethodAttributes.Family ||
+ma == MethodAttributes.FamANDAssem ||
+ma == MethodAttributes.FamORAssem) {
+	if (!CheckValidFamilyAccess (mb.IsStatic, m)) {
+		if (ma == MethodAttributes.Family || ma == MethodAttributes.FamANDAssem)
+			return false;
+	} else {
+		// We are valid
+		if (ma == MethodAttributes.Family || ma == MethodAttributes.FamORAssem)
+			return true;
+		
+		// Check for FamANDAssem
+		if (invocation_assembly == mb.DeclaringType.Assembly)
+			return true;
+	}
 }
 
-if (ma == MethodAttributes.Family ||
-ma == MethodAttributes.FamANDAssem ||
-ma == MethodAttributes.FamORAssem)
-	return CheckValidFamilyAccess (mb.IsStatic, m);
+if (!IsFriendAssembly 

Re: [Mono-dev] [PATCH] Friend access for class members

2005-10-28 Thread Carlos Alberto Cortez
Hey,

I applied your suggestion and also removed some redundant comparations
in the same place (for family, famor and famand). Also I've applied the
changes to access friend internal classes. 

Finally, more tests are added, so I'm attaching them.

Carlos.

BTW, the tests are running just fine.


El vie, 28-10-2005 a las 16:23 +0530, Raja R Harinath escribió:
 Hi,
 
 Carlos Alberto Cortez [EMAIL PROTECTED] writes:
 
  The attached patch implements friend access for class members (methods,
  properties, fields). 
 
  I'm not including the type-check section, since that part will be
  modified (next merge to gmcs) and I'm waiting for that to happen.
  However, that change should be small (I will send the patch).
 
 I have completed the merge of the relevant parts.  Please post an
 updated patch.
 
 Meanwhile, I have some comments:
 
 [snip]
  @@ -2646,25 +2726,38 @@
  MethodBase mb = (MethodBase) m;
  MethodAttributes ma = mb.Attributes  
  MethodAttributes.MemberAccessMask;
   
  +   if (ma == MethodAttributes.Public)
  +   return true;
 
 Ok.
 
  if (ma == MethodAttributes.Private)
  return private_ok ||
  IsPrivateAccessible 
  (invocation_type, m.DeclaringType) ||
  IsNestedChildOf 
  (invocation_type, m.DeclaringType);
   
  -   if (invocation_assembly == 
  mb.DeclaringType.Assembly) {
  +   if (invocation_assembly == 
  mb.DeclaringType.Assembly)
  if (ma == MethodAttributes.Assembly || 
  ma == MethodAttributes.FamORAssem)
  return true;
  -   } else {
  -   if (ma == MethodAttributes.Assembly || 
  ma == MethodAttributes.FamANDAssem)
  -   return false;
 
 I would retain the old code, and change the check to:
 
   if (invocation_assembly == mb.DeclaringType.Assembly ||
   TypeManager.InternalsVisibleTo (invocation_assembly, 
 mb.DeclaringType.Assembly)) 
 
  +   
  +   if (ma == MethodAttributes.Family ||
  +   ma == MethodAttributes.FamANDAssem ||
  +   ma == MethodAttributes.FamORAssem) {
  +   if (!CheckValidFamilyAccess 
  (mb.IsStatic, m)) {
  +   if (ma == 
  MethodAttributes.Family || ma == MethodAttributes.FamANDAssem)
  +   return false;
  +   } else {
  +   // We are valid
  +   if (ma == 
  MethodAttributes.Family || ma == MethodAttributes.FamORAssem)
  +   return true;
  +   
  +   // Check for FamANDAssem
  +   if (invocation_assembly == 
  mb.DeclaringType.Assembly)
  +   return true;
  +   }
  }
  -   if (ma == MethodAttributes.Family ||
  -   ma == MethodAttributes.FamANDAssem ||
  -   ma == MethodAttributes.FamORAssem)
  -   return CheckValidFamilyAccess 
  (mb.IsStatic, m);
 
 I don't like this too much.  I'd much rather keep the old code.
 
 - Hari

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Friend access for class members

2005-10-28 Thread Carlos Alberto Cortez
I forgot to attach the patch ;-)

Carlos.


El vie, 28-10-2005 a las 16:23 +0530, Raja R Harinath escribió:
 Hi,
 
 Carlos Alberto Cortez [EMAIL PROTECTED] writes:
 
  The attached patch implements friend access for class members (methods,
  properties, fields). 
 
  I'm not including the type-check section, since that part will be
  modified (next merge to gmcs) and I'm waiting for that to happen.
  However, that change should be small (I will send the patch).
 
 I have completed the merge of the relevant parts.  Please post an
 updated patch.
 
 Meanwhile, I have some comments:
 
 [snip]
  @@ -2646,25 +2726,38 @@
  MethodBase mb = (MethodBase) m;
  MethodAttributes ma = mb.Attributes  
  MethodAttributes.MemberAccessMask;
   
  +   if (ma == MethodAttributes.Public)
  +   return true;
 
 Ok.
 
  if (ma == MethodAttributes.Private)
  return private_ok ||
  IsPrivateAccessible 
  (invocation_type, m.DeclaringType) ||
  IsNestedChildOf 
  (invocation_type, m.DeclaringType);
   
  -   if (invocation_assembly == 
  mb.DeclaringType.Assembly) {
  +   if (invocation_assembly == 
  mb.DeclaringType.Assembly)
  if (ma == MethodAttributes.Assembly || 
  ma == MethodAttributes.FamORAssem)
  return true;
  -   } else {
  -   if (ma == MethodAttributes.Assembly || 
  ma == MethodAttributes.FamANDAssem)
  -   return false;
 
 I would retain the old code, and change the check to:
 
   if (invocation_assembly == mb.DeclaringType.Assembly ||
   TypeManager.InternalsVisibleTo (invocation_assembly, 
 mb.DeclaringType.Assembly)) 
 
  +   
  +   if (ma == MethodAttributes.Family ||
  +   ma == MethodAttributes.FamANDAssem ||
  +   ma == MethodAttributes.FamORAssem) {
  +   if (!CheckValidFamilyAccess 
  (mb.IsStatic, m)) {
  +   if (ma == 
  MethodAttributes.Family || ma == MethodAttributes.FamANDAssem)
  +   return false;
  +   } else {
  +   // We are valid
  +   if (ma == 
  MethodAttributes.Family || ma == MethodAttributes.FamORAssem)
  +   return true;
  +   
  +   // Check for FamANDAssem
  +   if (invocation_assembly == 
  mb.DeclaringType.Assembly)
  +   return true;
  +   }
  }
  -   if (ma == MethodAttributes.Family ||
  -   ma == MethodAttributes.FamANDAssem ||
  -   ma == MethodAttributes.FamORAssem)
  -   return CheckValidFamilyAccess 
  (mb.IsStatic, m);
 
 I don't like this too much.  I'd much rather keep the old code.
 
 - Hari
Index: typemanager.cs
===
--- typemanager.cs	(revisión: 52315)
+++ typemanager.cs	(copia de trabajo)
@@ -252,6 +252,8 @@
 	static Hashtable fieldbuilders_to_fields;
 	static Hashtable fields;
 
+	static PtrHashtable assembly_internals_vis_attrs;
+
 	struct Signature {
 		public string name;
 		public Type [] args;
@@ -274,6 +276,8 @@
 		priv_fields_events = null;
 
 		type_hash = null;
+
+		assembly_internals_vis_attrs = null;
 		
 		CleanUpGenerics ();
 		TypeHandle.CleanUp ();
@@ -375,6 +379,8 @@
 		fieldbuilders_to_fields = new Hashtable ();
 		fields = new Hashtable ();
 		type_hash = new DoubleHash ();
+
+		assembly_internals_vis_attrs = new PtrHashtable ();
 		
 		InitGenerics ();
 	}
@@ -1654,6 +1660,80 @@
 		return false;
 	}
 
+	//
+	// Checks whether `extern_type' is friend of the output assembly
+	//
+	public static bool IsFriendAssembly (Assembly assembly)
+	{
+		if (assembly_internals_vis_attrs.Contains (assembly))
+			return (bool)(assembly_internals_vis_attrs [assembly]);
+		
+		object [] attrs = assembly.GetCustomAttributes (internals_visible_attr_type, false);
+		if (attrs.Length == 0) {
+			AddFriendAssembly (assembly, false);
+			return false;
+		}
+
+		AssemblyName this_name = CodeGen.Assembly.Name;
+		byte [] this_token = this_name.GetPublicKeyToken ();
+		bool is_friend = false;
+		foreach (object o

Re: [Mono-dev] [PATCH] Friend access for class members

2005-10-28 Thread Carlos Alberto Cortez
Hey Marek,

Comments below:

El vie, 28-10-2005 a las 14:51 +0100, Marek Safar escribió:
 Hello Carlos,
 
 My comments.
 
 +foreach (object o in attrs) {
 +InternalsVisibleToAttribute attr = o as 
 InternalsVisibleToAttribute;
 
 I think you can use InternalsVisibleToAttribute directly in foreach
 
 +static string this_fullname;
 +   
 +static void Error_FriendAccessNameNotMatching (string other_name)
 +{
 +if (this_fullname == null)
 +this_fullname = CodeGen.Assembly.Name.FullName;
 +   
 +Report.Error (281, Friend access was granted to ` + other_name +
 +', but the output assembly is named ` + this_fullname +
 +'. Try adding a reference to ` + other_name +
 +' or change the output assembly name to match it.);
 +}
 
 1. Do you really need this `string this_fullname'

Well, every time we access to AssemblyName.FullName, a new string is
created. I know keeping this temporary string could be a little ugly, so
I created this method.

 2. Please don't end error message with '.'
 3. Please use bla `{0}' bla syntax, it is easier to read.

Ok, fixed the styles of the error messages.

Carlos.

 
 Marek
 
 
 I forgot to attach the patch ;-)
 
 Carlos.
 
 
 El vie, 28-10-2005 a las 16:23 +0530, Raja R Harinath escribió:
   
 
 Hi,
 
 Carlos Alberto Cortez [EMAIL PROTECTED] writes:
 
 
 
 The attached patch implements friend access for class members (methods,
 properties, fields). 
 
 I'm not including the type-check section, since that part will be
 modified (next merge to gmcs) and I'm waiting for that to happen.
 However, that change should be small (I will send the patch).
   
 
 I have completed the merge of the relevant parts.  Please post an
 updated patch.
 
 Meanwhile, I have some comments:
 
 [snip]
 
 
 @@ -2646,25 +2726,38 @@
MethodBase mb = (MethodBase) m;
MethodAttributes ma = mb.Attributes  
  MethodAttributes.MemberAccessMask;
  
 +  if (ma == MethodAttributes.Public)
 +  return true;
   
 
 Ok.
 
 
 
if (ma == MethodAttributes.Private)
return private_ok ||
IsPrivateAccessible 
  (invocation_type, m.DeclaringType) ||
IsNestedChildOf 
  (invocation_type, m.DeclaringType);
  
 -  if (invocation_assembly == 
 mb.DeclaringType.Assembly) {
 +  if (invocation_assembly == 
 mb.DeclaringType.Assembly)
if (ma == MethodAttributes.Assembly || 
  ma == MethodAttributes.FamORAssem)
return true;
 -  } else {
 -  if (ma == MethodAttributes.Assembly || 
 ma == MethodAttributes.FamANDAssem)
 -  return false;
   
 
 I would retain the old code, and change the check to:
 
   if (invocation_assembly == mb.DeclaringType.Assembly ||
   TypeManager.InternalsVisibleTo (invocation_assembly, 
  mb.DeclaringType.Assembly)) 
 
 
 
 +  
 +  if (ma == MethodAttributes.Family ||
 +  ma == MethodAttributes.FamANDAssem ||
 +  ma == MethodAttributes.FamORAssem) {
 +  if (!CheckValidFamilyAccess 
 (mb.IsStatic, m)) {
 +  if (ma == 
 MethodAttributes.Family || ma == MethodAttributes.FamANDAssem)
 +  return false;
 +  } else {
 +  // We are valid
 +  if (ma == 
 MethodAttributes.Family || ma == MethodAttributes.FamORAssem)
 +  return true;
 +  
 +  // Check for FamANDAssem
 +  if (invocation_assembly == 
 mb.DeclaringType.Assembly)
 +  return true;
 +  }
}
 -  if (ma == MethodAttributes.Family ||
 -  ma == MethodAttributes.FamANDAssem ||
 -  ma == MethodAttributes.FamORAssem)
 -  return CheckValidFamilyAccess 
 (mb.IsStatic, m);
   
 
 I don't like this too much.  I'd much rather keep the old code.
 
 - Hari
 
 
 
 
 Index: typemanager.cs

Re: [Mono-dev] [PATCH] Friend access for class members

2005-10-28 Thread Carlos Alberto Cortez
Hey

 
 +foreach (object o in attrs) {
 +InternalsVisibleToAttribute attr = o as 
 InternalsVisibleToAttribute;
 
 I think you can use InternalsVisibleToAttribute directly in foreach
 
 +static string this_fullname;
 +   
 +static void Error_FriendAccessNameNotMatching (string other_name)
 +{
 +if (this_fullname == null)
 +this_fullname = CodeGen.Assembly.Name.FullName;
 +   
 +Report.Error (281, Friend access was granted to ` + other_name +
 +', but the output assembly is named ` + this_fullname +
 +'. Try adding a reference to ` + other_name +
 +' or change the output assembly name to match it.);
 +}
 
 1. Do you really need this `string this_fullname'
 
 
 
 Well, every time we access to AssemblyName.FullName, a new string is
 created. I know keeping this temporary string could be a little ugly, so
 I created this method.
   
 
 I think it is not worthwhile as this is used only when multiple errors 
 occur.
 It would be nice to implement errors 1725 and 1726 as well.

Ok, then lemme remove that static element. BTW, 1726 is being reported
already ;-)

I will commit if you don't mind (I will add the test for 1725 as soon as
I find it ;-) )

Carlos.

 Marek
 
   
 
 2. Please don't end error message with '.'
 3. Please use bla `{0}' bla syntax, it is easier to read.
 
 
 
 Ok, fixed the styles of the error messages.
 
 Carlos.
 
   
 
 Marek
 
 
 
 
 I forgot to attach the patch ;-)
 
 Carlos.
 
 
 El vie, 28-10-2005 a las 16:23 +0530, Raja R Harinath escribió:
  
 
   
 
 Hi,
 
 Carlos Alberto Cortez [EMAIL PROTECTED] writes:
 

 
 
 
 The attached patch implements friend access for class members (methods,
 properties, fields). 
 
 I'm not including the type-check section, since that part will be
 modified (next merge to gmcs) and I'm waiting for that to happen.
 However, that change should be small (I will send the patch).
  
 
   
 
 I have completed the merge of the relevant parts.  Please post an
 updated patch.
 
 Meanwhile, I have some comments:
 
 [snip]

 
 
 
 @@ -2646,25 +2726,38 @@
  MethodBase mb = (MethodBase) m;
  MethodAttributes ma = mb.Attributes  
  MethodAttributes.MemberAccessMask;
 
 +if (ma == MethodAttributes.Public)
 +return true;
  
 
   
 
 Ok.
 

 
 
 
  if (ma == MethodAttributes.Private)
  return private_ok ||
  IsPrivateAccessible 
  (invocation_type, m.DeclaringType) ||
  IsNestedChildOf 
  (invocation_type, m.DeclaringType);
 
 -if (invocation_assembly == 
 mb.DeclaringType.Assembly) {
 +if (invocation_assembly == 
 mb.DeclaringType.Assembly)
  if (ma == MethodAttributes.Assembly || 
  ma == MethodAttributes.FamORAssem)
  return true;
 -} else {
 -if (ma == 
 MethodAttributes.Assembly || ma == MethodAttributes.FamANDAssem)
 -return false;
  
 
   
 
 I would retain the old code, and change the check to:
 
  if (invocation_assembly == mb.DeclaringType.Assembly ||
  TypeManager.InternalsVisibleTo (invocation_assembly, 
  mb.DeclaringType.Assembly)) 
 

 
 
 
 +
 +if (ma == MethodAttributes.Family ||
 +ma == MethodAttributes.FamANDAssem 
 ||
 +ma == MethodAttributes.FamORAssem) {
 +if (!CheckValidFamilyAccess 
 (mb.IsStatic, m)) {
 +if (ma == 
 MethodAttributes.Family || ma == MethodAttributes.FamANDAssem)
 +return false;
 +} else {
 +// We are valid
 +if (ma == 
 MethodAttributes.Family || ma == MethodAttributes.FamORAssem)
 +return true;
 +
 +// Check for FamANDAssem
 +if (invocation_assembly 
 == mb.DeclaringType.Assembly)
 +return true;
 +}
  }
 -if (ma == MethodAttributes.Family

Re: [Mono-dev] [PATCH] Int32.Parse

2005-10-21 Thread Carlos Alberto Cortez
Hello,

Ok, then let's keep as you said. The attached patch applies what you
suggested, and also added a method to retrieve the so-often-used
FormatException (I think it was kind of insane to have the exception
being thrown from different places with exactly the same message).

Carlos.

El jue, 20-10-2005 a las 13:06 +0200, Zoltan Varga escribió:
 Hi,
 
   I think it would be a little bit easier to return the actual
 exception to be thrown from the
 TryParse methods as an out argument, instead of adding this
 abstraction layer which
 cannot return more helpful exceptions messages like Number '123' is
 not valid. We should
 also retain the tryParse argument so these exception objects are not
 creared if it is true.
 
 So for example:
 
 internal bool Parse (String number, bool tryParse, out int result, out
 Exception ex)
 {
 ...
if (something_is_wrong) {
   if (!tryParse)
  ex = new ArgumentException ();
  return false;
}
 
   Zoltan
 
 On 10/20/05, Carlos Alberto Cortez [EMAIL PROTECTED] wrote:
  Hey,
 
  Currently the Int32.TryParse method calls the Int32.Parse method, and
  catches the exceptions. That's not the best behaviour, since
  Int32.TryParse is designed to avoid the performance problems associated
  with exception handling.
 
  The attached patch proposes an approach to keep the result of the
  parsing as an enum, and based on it the methods decide whether they
  throw an exception or not.
 
  I wanted you to take a look at it, since we need to decide the best
  solution for this before changing the TryParse/Parse methods in other
  types.
 
  Carlos.
 
 
  ___
  Mono-devel-list mailing list
  Mono-devel-list@lists.ximian.com
  http://lists.ximian.com/mailman/listinfo/mono-devel-list
 
 
 
 
Index: Int32.cs
===
--- Int32.cs	(revisión: 52018)
+++ Int32.cs	(copia de trabajo)
@@ -179,7 +179,7 @@
 			return Parse (s, style, null);
 		}
 
-		internal static void CheckStyle (NumberStyles style)
+		internal static bool CheckStyle (NumberStyles style)
 		{
 			if ((style  NumberStyles.AllowHexSpecifier) != 0) {
 NumberStyles ne = style ^ NumberStyles.AllowHexSpecifier;
@@ -188,24 +188,37 @@
 if ((ne  NumberStyles.AllowTrailingWhite) != 0)
 	ne ^= NumberStyles.AllowTrailingWhite;
 if (ne != 0)
-	throw new ArgumentException (
-		With AllowHexSpecifier only  + 
-		AllowLeadingWhite and AllowTrailingWhite  + 
-		are permitted.);
+	return false;
 			}
+
+			return true;
 		}
 		
-		internal static int JumpOverWhite (int pos, string s, bool excp)
+		internal static bool JumpOverWhite (ref int pos, string s)
 		{
+			return JumpOverWhite (ref pos, s, true);
+		}
+		
+		internal static bool JumpOverWhite (ref int pos, string s, bool report_error)
+		{
 			while (pos  s.Length  Char.IsWhiteSpace (s [pos]))
 pos++;
 
-			if (excp  pos = s.Length)
-throw new FormatException (Input string was not in the correct format.);
+			if (report_error  pos = s.Length)
+return false;
 
-			return pos;
+			return true;
 		}
 
+		internal static int JumpOverWhite (int pos, string s, bool exc)
+		{
+			int p = pos;
+			if (!JumpOverWhite (ref p, s, exc))
+throw GetFormatException ();
+
+			return p;
+		}
+
 		internal static void FindSign (ref int pos, string s, NumberFormatInfo nfi, 
   ref bool foundSign, ref bool negative)
 		{
@@ -275,22 +288,33 @@
 			return Char.IsDigit (e);
 		}
 		
-		internal static bool Parse (string s, NumberStyles style, IFormatProvider fp, bool tryParse, out int result)
+		internal static Exception GetFormatException ()
 		{
+			return new FormatException (Input string was not in the correct format.);
+		}
+		
+		internal static bool Parse (string s, NumberStyles style, IFormatProvider fp, bool tryParse, out int result, out Exception exc)
+		{
 			result = 0;
+			exc = null;
 
-			if (s == null)
-if (tryParse)
-	return false;
-else
-	throw new ArgumentNullException ();
+			if (s == null) {
+if (!tryParse)
+	exc = GetFormatException ();
+return false;
+			}
+			
+			if (s == null) {
+if (!tryParse)
+	exc = new ArgumentNullException ();
+return false;
+			}
 
-			if (s.Length == 0)
-if (tryParse)
-	return false;
-else
-	throw new FormatException (Input string was not  + 
-			   in the correct format.);
+			if (s.Length == 0) {
+if (!tryParse)
+	exc = GetFormatException ();
+return false;
+			}
 
 			NumberFormatInfo nfi;
 			if (fp != null) {
@@ -300,7 +324,11 @@
 			else
 nfi = Thread.CurrentThread.CurrentCulture.NumberFormat;
 
-			CheckStyle (style);
+			if (!CheckStyle (style)) {
+if (!tryParse)
+	exc = new ArgumentException ();
+return false;
+			}
 
 			bool AllowCurrencySymbol = (style  NumberStyles.AllowCurrencySymbol

Re: [Mono-dev] [PATCH] Int32.Parse

2005-10-21 Thread Carlos Alberto Cortez
Ok, let's keep that change too. Is it ok to commit? More comments? based
on this, I will work on change the impl of Parse in other types.

Carlos.

El vie, 21-10-2005 a las 12:59 +0200, Zoltan Varga escribió:
 Hi,
 
   This looks cool. I think it would be easier to add an out ex
 argument to CheckStyle
 as well, instead of duplicating the exception message in three different 
 places.
 
  Zoltan
 
 On 10/21/05, Carlos Alberto Cortez [EMAIL PROTECTED] wrote:
  Hello,
 
  Ok, then let's keep as you said. The attached patch applies what you
  suggested, and also added a method to retrieve the so-often-used
  FormatException (I think it was kind of insane to have the exception
  being thrown from different places with exactly the same message).
 
  Carlos.
 
  El jue, 20-10-2005 a las 13:06 +0200, Zoltan Varga escribió:
   Hi,
  
 I think it would be a little bit easier to return the actual
   exception to be thrown from the
   TryParse methods as an out argument, instead of adding this
   abstraction layer which
   cannot return more helpful exceptions messages like Number '123' is
   not valid. We should
   also retain the tryParse argument so these exception objects are not
   creared if it is true.
  
   So for example:
  
   internal bool Parse (String number, bool tryParse, out int result, out
   Exception ex)
   {
   ...
  if (something_is_wrong) {
 if (!tryParse)
ex = new ArgumentException ();
return false;
  }
  
 Zoltan
  
   On 10/20/05, Carlos Alberto Cortez [EMAIL PROTECTED] wrote:
Hey,
   
Currently the Int32.TryParse method calls the Int32.Parse method, and
catches the exceptions. That's not the best behaviour, since
Int32.TryParse is designed to avoid the performance problems associated
with exception handling.
   
The attached patch proposes an approach to keep the result of the
parsing as an enum, and based on it the methods decide whether they
throw an exception or not.
   
I wanted you to take a look at it, since we need to decide the best
solution for this before changing the TryParse/Parse methods in other
types.
   
Carlos.
   
   
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
   
   
   
   
 
 
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Warning and errors for InternalsVisibleAttr

2005-10-20 Thread Carlos Alberto Cortez
Hey guys, 

Any news? I think this small patch can go in gmcs, since nobody
commented on the posibility of having it on mcs.

Carlos.

El vie, 14-10-2005 a las 09:08 +0100, Marek Safar escribió:
 Hello,
 
 The attached patch checks the validity of InternalsVisibleToAttribute,
 and reports and warnings depending on the contents.
 
 May I commit?
   
 
 - no test for CS1700.
 - please use syntax `blabla' for error/warning arguments.
 
 + if (a.Type == TypeManager.internals_visible_attr_type)
 + if (!CheckInternalsVisibleAttribute (a))
 + return;
 + 
 


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [PATCH] Int32.Parse

2005-10-20 Thread Carlos Alberto Cortez
Hey,

Currently the Int32.TryParse method calls the Int32.Parse method, and
catches the exceptions. That's not the best behaviour, since
Int32.TryParse is designed to avoid the performance problems associated
with exception handling.

The attached patch proposes an approach to keep the result of the
parsing as an enum, and based on it the methods decide whether they
throw an exception or not.

I wanted you to take a look at it, since we need to decide the best
solution for this before changing the TryParse/Parse methods in other
types.

Carlos.
Index: Int32.cs
===
--- Int32.cs	(revisión: 51973)
+++ Int32.cs	(copia de trabajo)
@@ -92,7 +92,7 @@
 		}
 #endif
 
-		internal static bool Parse (string s, bool tryParse, out int result)
+		internal static ParseResult Parse (string s, out int result)
 		{
 			int val = 0;
 			int len;
@@ -102,10 +102,7 @@
 			result = 0;
 
 			if (s == null)
-if (tryParse)
-	return false;
-else
-	throw new ArgumentNullException (s);
+return ParseResult.NullArgument;
 
 			len = s.Length;
 
@@ -117,10 +114,7 @@
 			}
 			
 			if (i == len)
-if (tryParse)
-	return false;
-else
-	throw new FormatException ();
+return ParseResult.WrongFormat;
 
 			c = s [i];
 			if (c == '+')
@@ -145,28 +139,18 @@
 	if (Char.IsWhiteSpace (c)){
 		for (i++; i  len; i++){
 			if (!Char.IsWhiteSpace (s [i]))
-if (tryParse)
-	return false;
-else
-	throw new FormatException ();
+return ParseResult.WrongFormat;
 		}
 		break;
 	} else
-		if (tryParse)
-			return false;
-		else
-			throw new FormatException ();
+		return ParseResult.WrongFormat;
 }
 			}
 			if (!digits_seen)
-if (tryParse)
-	return false;
-else
-	throw new FormatException ();
+return ParseResult.WrongFormat;
 
 			result = val;
-
-			return true;
+			return ParseResult.Success;
 		}
 
 		public static int Parse (string s, IFormatProvider fp)
@@ -179,7 +163,7 @@
 			return Parse (s, style, null);
 		}
 
-		internal static void CheckStyle (NumberStyles style)
+		internal static ParseResult CheckStyle (NumberStyles style)
 		{
 			if ((style  NumberStyles.AllowHexSpecifier) != 0) {
 NumberStyles ne = style ^ NumberStyles.AllowHexSpecifier;
@@ -188,24 +172,37 @@
 if ((ne  NumberStyles.AllowTrailingWhite) != 0)
 	ne ^= NumberStyles.AllowTrailingWhite;
 if (ne != 0)
-	throw new ArgumentException (
-		With AllowHexSpecifier only  + 
-		AllowLeadingWhite and AllowTrailingWhite  + 
-		are permitted.);
+	return ParseResult.WrongHexFormat;
 			}
+
+			return ParseResult.Success;
 		}
 		
-		internal static int JumpOverWhite (int pos, string s, bool excp)
+		internal static bool JumpOverWhite (ref int pos, string s)
 		{
+			return JumpOverWhite (ref pos, s, true);
+		}
+		
+		internal static bool JumpOverWhite (ref int pos, string s, bool report_error)
+		{
 			while (pos  s.Length  Char.IsWhiteSpace (s [pos]))
 pos++;
 
-			if (excp  pos = s.Length)
-throw new FormatException (Input string was not in the correct format.);
+			if (report_error  pos = s.Length)
+return false;
 
-			return pos;
+			return true;
 		}
 
+		internal static int JumpOverWhite (int pos, string s, bool exc)
+		{
+			int p = pos;
+			if (!JumpOverWhite (ref p, s, exc))
+throw new FormatException ();
+
+			return p;
+		}
+
 		internal static void FindSign (ref int pos, string s, NumberFormatInfo nfi, 
   ref bool foundSign, ref bool negative)
 		{
@@ -275,22 +272,16 @@
 			return Char.IsDigit (e);
 		}
 		
-		internal static bool Parse (string s, NumberStyles style, IFormatProvider fp, bool tryParse, out int result)
+		internal static ParseResult Parse (string s, NumberStyles style, IFormatProvider fp, out int result)
 		{
+			ParseResult parse_result;
 			result = 0;
 
 			if (s == null)
-if (tryParse)
-	return false;
-else
-	throw new ArgumentNullException ();
+return ParseResult.NullArgument;
 
 			if (s.Length == 0)
-if (tryParse)
-	return false;
-else
-	throw new FormatException (Input string was not  + 
-			   in the correct format.);
+return ParseResult.WrongFormat;
 
 			NumberFormatInfo nfi;
 			if (fp != null) {
@@ -300,7 +291,9 @@
 			else
 nfi = Thread.CurrentThread.CurrentCulture.NumberFormat;
 
-			CheckStyle (style);
+			parse_result = CheckStyle (style);
+			if (parse_result != ParseResult.Success)
+return parse_result;
 
 			bool AllowCurrencySymbol = (style  NumberStyles.AllowCurrencySymbol) != 0;
 			bool AllowHexSpecifier = (style  NumberStyles.AllowHexSpecifier) != 0;
@@ -316,7 +309,8 @@
 			int pos = 0;
 
 			if (AllowLeadingWhite)
-pos = JumpOverWhite (pos, s, true);
+if (!JumpOverWhite (ref pos, s))
+	return ParseResult.WrongFormat;
 
 			bool foundOpenParentheses = false;
 			bool negative = false;
@@ -331,20 +325,14 @@

Re: [Mono-dev] [PATCH] Warning and errors for InternalsVisibleAttr

2005-10-14 Thread Carlos Alberto Cortez
Hey, 

Comments below:

El vie, 14-10-2005 a las 09:08 +0100, Marek Safar escribió:
 Hello,
 
 The attached patch checks the validity of InternalsVisibleToAttribute,
 and reports and warnings depending on the contents.
 
 May I commit?
   
 
 - no test for CS1700.

Sorry, since it is a warning I didn't take the time for it. The test is
attached.

 - please use syntax `blabla' for error/warning arguments.

Ok.

 
 + if (a.Type == TypeManager.internals_visible_attr_type)
 + if (!CheckInternalsVisibleAttribute (a))
 + return;
 + 
 
 Please use, .

Ok.

 
 But I am not sure whether we should commit this to mcs and then 
 integrate or to gmcs only.
 Any ideas ?
 

Well, I think we should keep it in gmcs only by now, since it requires
InternalsVisibleToAttribute, which is 2.0 only. 

I was trying to figure out a way to commit it to mcs, but they would be
hacks, so I would prefer to keep this in gmcs.

The patch with the changes is attached. Here it's 4 a.m, so I think I
will write the test tomorrow.

Carlos.
Index: typemanager.cs
===
--- typemanager.cs	(revisión: 51640)
+++ typemanager.cs	(copia de trabajo)
@@ -107,6 +107,7 @@
 	static internal Type compiler_generated_attr_type;
 	static internal Type fixed_buffer_attr_type;
 	static internal Type default_charset_type;
+	static internal Type internals_visible_attr_type;
 
 	//
 	// An empty array of types
@@ -1143,6 +1144,7 @@
 		compiler_generated_attr_type = CoreLookupType (System.Runtime.CompilerServices, CompilerGeneratedAttribute);
 		fixed_buffer_attr_type = CoreLookupType (System.Runtime.CompilerServices, FixedBufferAttribute);
 		default_charset_type = CoreLookupType (System.Runtime.InteropServices, DefaultCharSetAttribute);
+		internals_visible_attr_type = CoreLookupType (System.Runtime.CompilerServices, InternalsVisibleToAttribute);
 		//
 		// When compiling corlib, store the real types here.
 		//
Index: codegen.cs
===
--- codegen.cs	(revisión: 51690)
+++ codegen.cs	(copia de trabajo)
@@ -144,6 +144,10 @@
 return false;
 			}
 
+			// Get the complete AssemblyName from the builder
+			// (We need to get the public key and token)
+			Assembly.Name = Assembly.Builder.GetName ();
+			
 			//
 			// Pass a path-less name to DefineDynamicModule.  Wonder how
 			// this copes with output in different directories then.
@@ -1006,6 +1010,7 @@
 	public class AssemblyClass: CommonAssemblyModulClass {
 		// TODO: make it private and move all builder based methods here
 		public AssemblyBuilder Builder;
+		public AssemblyName Name;
 
 		bool is_cls_compliant;
 		public Attribute ClsCompliantAttribute;
@@ -1196,6 +1201,35 @@
 			Report.Error (1548, Error during assembly signing.  + text);
 		}
 
+		bool CheckInternalsVisibleAttribute (Attribute a)
+		{
+			string assembly_name = a.GetString ();
+			if (assembly_name.Length == 0)
+return false;
+
+			AssemblyName aname = null;
+			try {
+aname = new AssemblyName (assembly_name);
+			} catch (FileLoadException) {
+			} catch (ArgumentException) {
+			}
+
+			// Bad assembly name format
+			if (aname == null)
+Report.Warning (1700, 3, a.Location, Assembly reference ' + assembly_name + ' is invalid and cannot be resolved);
+			// Report error if we have defined Version or Culture
+			else if (aname.Version != null || aname.CultureInfo != null)
+throw new Exception (Friend assembly ` + a.GetString () + 
+		' is invalid. InternalsVisibleTo cannot have version or culture specified.);
+			else if (aname.GetPublicKeyToken () == null  Name.GetPublicKeyToken () != null) {
+Report.Error (1726, a.Location, Friend assembly reference ' + aname.Name + ' is invalid. +
+		 Strong named assemblies must specify a public key token in their InternalsVisibleTo declarations);
+return false;
+			}
+
+			return true;
+		}
+
 		public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
 		{
 			if (a.Type.IsSubclassOf (TypeManager.security_attr_type)  a.CheckSecurityActionValidity (true)) {
@@ -1217,6 +1251,9 @@
 }
 			}
 
+			if (a.Type == TypeManager.internals_visible_attr_type  !CheckInternalsVisibleAttribute (a))
+	return;
+			
 			Builder.SetCustomAttribute (customBuilder);
 		}
 
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Warning and errors for InternalsVisibleAttr

2005-10-14 Thread Carlos Alberto Cortez
Hey Marek,

I've attached the patch that I was missing for this patch to be
approved. So I think the remaining issue has to see with applying the
patch to mcs and/or gmcs or not.

Carlos.
// gcs1700.cs: Assembly reference `MyAssemblyName, Version=' is invalid and cannot be resolved
// Line: 8
// Compiler options: -warnaserror -warn:3

using System;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo (MyAssemblyName, Version=)]

public class InternalsVisibleToTest 
{
	static void Main ()
	{
	}

}

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] Extern alias patch (latest modifications)

2005-10-13 Thread Carlos Alberto Cortez
Hey,

The attached patch contains the impl of extern alias, and also the clean
ups to the original code needed for my patch, as required by Hari.

I'm also attaching some tests and tests for errors (observe that cs1679
and cs1780 are receiving an error, since it looks like '=' in the comp
options is not handled). Errors 1769 and 1680 are handled since my first
patch, but hadn't included tests for them ;-) (as required by Marek).

Carlos.

By the way, all the tests are running fine.
Index: typemanager.cs
===
--- typemanager.cs	(revisión: 51651)
+++ typemanager.cs	(copia de trabajo)
@@ -215,6 +215,8 @@
 	// /remarks
 	static Assembly [] assemblies;
 
+	static Hashtable external_aliases;
+
 	// remarks
 	//  Keeps a list of modules. We used this to do lookups
 	//  on the module using GetType -- needed for arrays
@@ -278,6 +280,7 @@
 		// Lets get everything clean so that we can collect before generating code
 		assemblies = null;
 		modules = null;
+		external_aliases = null;
 		builder_to_declspace = null;
 		builder_to_member_cache = null;
 		builder_to_ifaces = null;
@@ -379,6 +382,7 @@
 		assemblies = new Assembly [0];
 		modules = null;
 		
+		external_aliases = new Hashtable ();
 		builder_to_declspace = new PtrHashtable ();
 		builder_to_member_cache = new PtrHashtable ();
 		builder_to_method = new PtrHashtable ();
@@ -504,11 +508,22 @@
 		assemblies = n;
 	}
 
+	public static void AddExternAlias (string alias, Assembly a)
+	{
+		// Keep the new as the chosen one
+		external_aliases [alias] = a;
+	}
+
 public static Assembly [] GetAssemblies ()
 {
 return assemblies;
 }
 
+	public static Assembly GetExternAlias (string alias)
+	{
+		return (Assembly) external_aliases [alias];
+	}
+
 	/// summary
 	///  Registers a module builder to lookup types from
 	/// /summary
@@ -578,110 +593,26 @@
 		return (Type) ret;
 	}
 
-	public static Type LookupTypeReflection (string name, Location loc)
-	{
-		Type found_type = null;
-
-		foreach (Assembly a in assemblies) {
-			Type t = a.GetType (name);
-			if (t == null)
-continue;
-
-			if (t.IsPointer)
-throw new InternalErrorException (Use GetPointerType() to get a pointer);
-
-			TypeAttributes ta = t.Attributes  TypeAttributes.VisibilityMask;
-			if (ta != TypeAttributes.NotPublic  ta != TypeAttributes.NestedPrivate 
-ta != TypeAttributes.NestedAssembly  ta != TypeAttributes.NestedFamANDAssem) {
-if (found_type == null) {
-	found_type = t;
-	continue;
-}
-
-Report.SymbolRelatedToPreviousError (found_type);
-Report.SymbolRelatedToPreviousError (t);
-Report.Error (433, loc, The imported type `{0}' is defined multiple times, name);
-return found_type;
-			}
-		}
-
-		foreach (Module mb in modules) {
-			Type t = mb.GetType (name);
-			if (t == null)
-continue;
-			
-			if (found_type == null) {
-found_type = t;
-continue;
-			}
-
-			Report.SymbolRelatedToPreviousError (t);
-			Report.SymbolRelatedToPreviousError (found_type);
-			Report.Warning (436, 2, loc, Ignoring imported type `{0}' since the current assembly already has a declaration with the same name,
-TypeManager.CSharpName (t));
-			return t;
-		}
-
-		return found_type;
-	}
-
 	/// summary
 	///   Computes the namespaces that we import from the assemblies we reference.
 	/// /summary
 	public static void ComputeNamespaces ()
 	{
-		MethodInfo assembly_get_namespaces = typeof (Assembly).GetMethod (GetNamespaces, BindingFlags.Instance|BindingFlags.NonPublic);
+		foreach (Assembly assembly in assemblies)
+			GlobalRootNamespace.Global.AddAssemblyReference (assembly);
+		
+		foreach (Module m in modules)
+			GlobalRootNamespace.Global.AddModuleReference (m);
 
-		Hashtable cache = null;
+	}
 
-		//
-		// First add the assembly namespaces
-		//
-		if (assembly_get_namespaces != null){
-			int count = assemblies.Length;
-
-			for (int i = 0; i  count; i++){
-Assembly a = assemblies [i];
-string [] namespaces = (string []) assembly_get_namespaces.Invoke (a, null);
-foreach (string ns in namespaces){
-	if (ns.Length == 0)
-		continue;
-	Namespace.LookupNamespace (ns, true);
-}
-			}
-		} else {
-			cache = new Hashtable ();
-			cache.Add (, null);
-			foreach (Assembly a in assemblies) {
-foreach (Type t in a.GetExportedTypes ()) {
-	string ns = t.Namespace;
-	if (ns == null || cache.Contains (ns))
-		continue;
-
-	Namespace.LookupNamespace (ns, true);
-	cache.Add (ns, null);
-}
-			}
-		}
-
-		//
-		// Then add module namespaces
-		//
-		foreach (Module m in modules) {
-			if (m == CodeGen.Module.Builder)
-continue;
-			if (cache == null) {
-cache = new Hashtable ();
-cache.Add (, null);
-			}
-			foreach (Type t in m.GetTypes ()) {
-string ns = t.Namespace;
-if (ns == null || cache.Contains (ns))
-	continue;
-Namespace.LookupNamespace (ns, true);
-cache.Add (ns, 

[Mono-dev] [PATCH] Warning and errors for InternalsVisibleAttr

2005-10-13 Thread Carlos Alberto Cortez
Hey,

The attached patch checks the validity of InternalsVisibleToAttribute,
and reports and warnings depending on the contents.

May I commit?

Carlos.

PD - Attached are some tests.
Index: typemanager.cs
===
--- typemanager.cs	(revisión: 51640)
+++ typemanager.cs	(copia de trabajo)
@@ -107,6 +107,7 @@
 	static internal Type compiler_generated_attr_type;
 	static internal Type fixed_buffer_attr_type;
 	static internal Type default_charset_type;
+	static internal Type internals_visible_attr_type;
 
 	//
 	// An empty array of types
@@ -1143,6 +1144,7 @@
 		compiler_generated_attr_type = CoreLookupType (System.Runtime.CompilerServices, CompilerGeneratedAttribute);
 		fixed_buffer_attr_type = CoreLookupType (System.Runtime.CompilerServices, FixedBufferAttribute);
 		default_charset_type = CoreLookupType (System.Runtime.InteropServices, DefaultCharSetAttribute);
+		internals_visible_attr_type = CoreLookupType (System.Runtime.CompilerServices, InternalsVisibleToAttribute);
 		//
 		// When compiling corlib, store the real types here.
 		//
Index: codegen.cs
===
--- codegen.cs	(revisión: 51690)
+++ codegen.cs	(copia de trabajo)
@@ -144,6 +144,10 @@
 return false;
 			}
 
+			// Get the complete AssemblyName from the builder
+			// (We need to get the public key and token)
+			Assembly.Name = Assembly.Builder.GetName ();
+			
 			//
 			// Pass a path-less name to DefineDynamicModule.  Wonder how
 			// this copes with output in different directories then.
@@ -1006,6 +1010,7 @@
 	public class AssemblyClass: CommonAssemblyModulClass {
 		// TODO: make it private and move all builder based methods here
 		public AssemblyBuilder Builder;
+		public AssemblyName Name;
 
 		bool is_cls_compliant;
 		public Attribute ClsCompliantAttribute;
@@ -1196,6 +1201,35 @@
 			Report.Error (1548, Error during assembly signing.  + text);
 		}
 
+		bool CheckInternalsVisibleAttribute (Attribute a)
+		{
+			string assembly_name = a.GetString ();
+			if (assembly_name.Length == 0)
+return false;
+
+			AssemblyName aname = null;
+			try {
+aname = new AssemblyName (assembly_name);
+			} catch (FileLoadException) {
+			} catch (ArgumentException) {
+			}
+
+			// Bad assembly name format
+			if (aname == null)
+Report.Warning (1700, 3, a.Location, Assembly reference ' + assembly_name + ' is invalid and cannot be resolved);
+			// Report error if we have defined Version or Culture
+			else if (aname.Version != null || aname.CultureInfo != null)
+throw new Exception (Friend assembly ' + a.GetString () + 
+		' is invalid. InternalsVisibleTo cannot have version or culture specified.);
+			else if (aname.GetPublicKeyToken () == null  Name.GetPublicKeyToken () != null) {
+Report.Error (1726, a.Location, Friend assembly reference ' + aname.Name + ' is invalid. +
+		 Strong named assemblies must specify a public key token in their InternalsVisibleTo declarations);
+return false;
+			}
+
+			return true;
+		}
+
 		public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
 		{
 			if (a.Type.IsSubclassOf (TypeManager.security_attr_type)  a.CheckSecurityActionValidity (true)) {
@@ -1217,6 +1251,10 @@
 }
 			}
 
+			if (a.Type == TypeManager.internals_visible_attr_type)
+if (!CheckInternalsVisibleAttribute (a))
+	return;
+			
 			Builder.SetCustomAttribute (customBuilder);
 		}
 


internals-errors.tar.gz
Description: application/compressed-tar
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] Avoid creating version in AssemblyName ctor

2005-10-06 Thread Carlos Alberto Cortez
Hey,

The attached patch adds a param to mono_assembly_name_parse_full, which
lets us avoid creating 'version' if it wasn't defined. 

This helps us to have the same behavior when the version wasn't defined
in AssemblyName(string name).

Carlos.
Index: assembly.c
===
--- assembly.c	(revisión: 51288)
+++ assembly.c	(copia de trabajo)
@@ -1355,7 +1355,7 @@
 }
 
 gboolean
-mono_assembly_name_parse_full (const char *name, MonoAssemblyName *aname, gboolean save_public_key)
+mono_assembly_name_parse_full (const char *name, MonoAssemblyName *aname, gboolean save_public_key, gboolean *is_version_defined)
 {
 	gchar *dllname;
 	gchar *version = NULL;
@@ -1366,7 +1366,12 @@
 	gchar *value;
 	gchar **parts;
 	gchar **tmp;
+	gboolean version_defined;
 
+	if (!is_version_defined)
+		is_version_defined = version_defined;
+	*is_version_defined = FALSE;
+	
 	parts = tmp = g_strsplit (name, ,, 4);
 	if (!tmp || !*tmp) {
 		g_strfreev (tmp);
@@ -1380,6 +1385,7 @@
 	while (*tmp) {
 		value = g_strstrip (*tmp);
 		if (!g_ascii_strncasecmp (value, Version=, 8)) {
+			*is_version_defined = TRUE;
 			version = g_strstrip (value + 8);
 			tmp++;
 			continue;
@@ -1424,7 +1430,7 @@
 gboolean
 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname)
 {
-	return mono_assembly_name_parse_full (name, aname, FALSE);
+	return mono_assembly_name_parse_full (name, aname, FALSE, NULL);
 }
 
 static MonoAssembly*
Index: icall.c
===
--- icall.c	(revisión: 51288)
+++ icall.c	(copia de trabajo)
@@ -4111,7 +4111,7 @@
 }
 
 static void
-fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute)
+fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute, gboolean by_default_version)
 {
 	static MonoMethod *create_culture = NULL;
 	gpointer args [1];
@@ -4127,7 +4127,8 @@
 	aname-build = name-build;
 	aname-revision = name-revision;
 	aname-hashalg = name-hash_alg;
-	aname-version = create_version (domain, name-major, name-minor, name-build, name-revision);
+	if (by_default_version)
+		aname-version = create_version (domain, name-major, name-minor, name-build, name-revision);
 	
 	codebase = g_filename_to_uri (absolute, NULL, NULL);
 	if (codebase) {
@@ -4181,7 +4182,7 @@
 	absolute = g_build_filename (assembly-assembly-basedir, assembly-assembly-image-module_name, NULL);
 
 	fill_reflection_assembly_name (mono_object_domain (assembly), aname, 
-   assembly-assembly-aname, absolute);
+   assembly-assembly-aname, absolute, TRUE);
 
 	g_free (absolute);
 }
@@ -4216,7 +4217,7 @@
 		mono_raise_exception (mono_get_exception_argument (assemblyFile, The file does not contain a manifest));
 	}
 
-	fill_reflection_assembly_name (mono_domain_get (), aname, name, filename);
+	fill_reflection_assembly_name (mono_domain_get (), aname, name, filename, TRUE);
 
 	g_free (filename);
 	mono_image_close (image);
@@ -4442,12 +4443,13 @@
 	MonoAssemblyName aname;
 	MonoDomain *domain = mono_object_domain (name);
 	char *val;
+	gboolean is_version_defined;
 
 	val = mono_string_to_utf8 (assname);
-	if (!mono_assembly_name_parse_full (val, aname, TRUE))
+	if (!mono_assembly_name_parse_full (val, aname, TRUE, is_version_defined))
 		return FALSE;
 	
-	fill_reflection_assembly_name (domain, name, aname, );
+	fill_reflection_assembly_name (domain, name, aname, , is_version_defined);
 
 	mono_assembly_name_free (aname);
 	g_free ((guint8*) aname.public_key);
Index: metadata-internals.h
===
--- metadata-internals.h	(revisión: 51288)
+++ metadata-internals.h	(copia de trabajo)
@@ -334,7 +334,8 @@
 gboolean
 mono_assembly_name_parse_full 		 (const char	   *name,
 	  MonoAssemblyName	   *aname,
-	  gboolean save_public_key);
+	  gboolean save_public_key,
+	  gboolean *is_version_defined);
 
 #endif /* __MONO_METADATA_INTERNALS_H__ */
 
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] Extern alias (with modifications)

2005-10-05 Thread Carlos Alberto Cortez
Hey,

I applied the corrections made by Hari and all my tests are working
fine. 

Comments and suggestions are welcome.

Carlos.
Index: typemanager.cs
===
--- typemanager.cs	(revisión: 51315)
+++ typemanager.cs	(copia de trabajo)
@@ -215,6 +215,8 @@
 	// /remarks
 	static Assembly [] assemblies;
 
+	static Hashtable external_aliases;
+
 	// remarks
 	//  Keeps a list of modules. We used this to do lookups
 	//  on the module using GetType -- needed for arrays
@@ -278,6 +280,7 @@
 		// Lets get everything clean so that we can collect before generating code
 		assemblies = null;
 		modules = null;
+		external_aliases = null;
 		builder_to_declspace = null;
 		builder_to_member_cache = null;
 		builder_to_ifaces = null;
@@ -379,6 +382,7 @@
 		assemblies = new Assembly [0];
 		modules = null;
 		
+		external_aliases = new Hashtable ();
 		builder_to_declspace = new PtrHashtable ();
 		builder_to_member_cache = new PtrHashtable ();
 		builder_to_method = new PtrHashtable ();
@@ -504,11 +508,22 @@
 		assemblies = n;
 	}
 
+	public static void AddExternAlias (string alias, Assembly a)
+	{
+		// Keep the new as the chosen one
+		external_aliases [alias] = a;
+	}
+
 public static Assembly [] GetAssemblies ()
 {
 return assemblies;
 }
 
+	public static Assembly GetExternAlias (string alias)
+	{
+		return (Assembly) external_aliases [alias];
+	}
+
 	/// summary
 	///  Registers a module builder to lookup types from
 	/// /summary
@@ -578,60 +593,33 @@
 		return (Type) ret;
 	}
 
-	public static Type LookupTypeReflection (string name, Location loc)
+	public static Type LookupTypeInModules (string name)
 	{
-		Type found_type = null;
-
-		foreach (Assembly a in assemblies) {
-			Type t = a.GetType (name);
-			if (t == null)
-continue;
-
-			if (t.IsPointer)
-throw new InternalErrorException (Use GetPointerType() to get a pointer);
-
-			TypeAttributes ta = t.Attributes  TypeAttributes.VisibilityMask;
-			if (ta != TypeAttributes.NotPublic  ta != TypeAttributes.NestedPrivate 
-ta != TypeAttributes.NestedAssembly  ta != TypeAttributes.NestedFamANDAssem) {
-if (found_type == null) {
-	found_type = t;
-	continue;
-}
-
-Report.SymbolRelatedToPreviousError (found_type);
-Report.SymbolRelatedToPreviousError (t);
-Report.Error (433, loc, The imported type `{0}' is defined multiple times, name);
-return found_type;
-			}
-		}
-
 		foreach (Module mb in modules) {
 			Type t = mb.GetType (name);
-			if (t == null)
-continue;
-			
-			if (found_type == null) {
-found_type = t;
-continue;
-			}
-
-			Report.SymbolRelatedToPreviousError (t);
-			Report.SymbolRelatedToPreviousError (found_type);
-			Report.Warning (436, 2, loc, Ignoring imported type `{0}' since the current assembly already has a declaration with the same name,
-TypeManager.CSharpName (t));
-			return t;
+			if (t != null)
+return t;
 		}
 
-		return found_type;
+		return null;
 	}
+	
+	//
+	// We use this for retrieving GetNamespaces method if avalaible
+	//
+	static MethodInfo assembly_get_namespaces;
 
 	/// summary
 	///   Computes the namespaces that we import from the assemblies we reference.
 	/// /summary
 	public static void ComputeNamespaces ()
 	{
-		MethodInfo assembly_get_namespaces = typeof (Assembly).GetMethod (GetNamespaces, BindingFlags.Instance|BindingFlags.NonPublic);
+		if (assembly_get_namespaces == null)
+			assembly_get_namespaces = typeof (Assembly).GetMethod (GetNamespaces, BindingFlags.Instance|BindingFlags.NonPublic);
 
+		foreach (Assembly assembly in assemblies)
+			Namespace.Root.AddAssemblyReference (assembly);
+		
 		Hashtable cache = null;
 
 		//
@@ -682,8 +670,43 @@
 cache.Add (ns, null);
 			}
 		}
+
 	}
 
+	public static Namespace ComputeNamespacesForAlias (string name)
+	{
+		Assembly assembly = (Assembly) external_aliases [name];
+		if (assembly == null)
+			return null;
+		
+		if (assembly_get_namespaces == null)
+			assembly_get_namespaces = typeof (Assembly).GetMethod (GetNamespaces, BindingFlags.Instance|BindingFlags.NonPublic);
+		
+		Namespace retval = Namespace.DefineRootNamespace (name, assembly);
+		if (assembly_get_namespaces != null) {
+			string [] namespaces = (string []) assembly_get_namespaces.Invoke (assembly, null);
+			foreach (string ns in namespaces) {
+if (ns.Length == 0)
+	continue;
+
+retval.GetNamespace (ns, true);
+			}
+		} else {
+			Hashtable alias_cache = new Hashtable ();
+			alias_cache.Add (, null);
+			foreach (Type t in assembly.GetExportedTypes ()) {
+string ns = t.Namespace;
+if (ns == null || alias_cache.Contains (ns))
+	continue;
+
+retval.GetNamespace (ns, true);
+alias_cache.Add (ns, null);
+			}
+		}
+
+		return retval;
+	}
+
 	/// summary
 	/// Fills static table with exported types from all referenced assemblies.
 	/// This information is required for CLS Compliance tests.
Index: 

Re: [Mono-dev] [Patch] Extern assembly alias

2005-09-24 Thread Carlos Alberto Cortez
Hey, 

I've been thinking about your ideas, but haven't understood yet the some
of the reasons behind your suggestions. Maybe to have a cleaner code? or
am I losing anything?

Some more comments below:

El vie, 23-09-2005 a las 18:34 +0530, Raja R Harinath escribió:
 Hi,
 
 Carlos Alberto Cortez [EMAIL PROTECTED] writes:
 
  The attached patch implements extern assembly alias support for mcs.
  I've also added tests and errors for it, and all the tests are running
  fine. Could anybody of the mcs guys take a look at it?
 
 I'm not particularly thrilled by the approach.
 
 I'd prefer introducing classes RootNamespace (deriving from Namespace)

Would we have to change Namespace to be abstract?

 We just create
 an Using alias that points to a RootNamespace, and the current
 QualifiedAliasEntry code should handle it.

Could you be more specific?

 And we move
 TypeManager.LookupTypeReflection to RootNamespace and
 GlobalRootNamespace, and  things should be hunky-dory.

This change looks reasonable.

Thanks for the comments,
Carlos.

PD - Note that looks like csc created a 'normal' namespace per extern
alias. For example, if you have an alias 'Hey', and then write something
like 'Hey.MyNamespace.MyClass ..., it won't complain. I just mentioned
this, because could have something to see with some observations in the
future ;-)


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] Extern assembly alias

2005-09-23 Thread Carlos Alberto Cortez
Hey,

The attached patch implements extern assembly alias support for mcs.
I've also added tests and errors for it, and all the tests are running
fine. Could anybody of the mcs guys take a look at it?

Thanks,
Carlos.

PD - The next link gives some info about it:
http://msdn2.microsoft.com/en-us/library/ms173212
Index: Makefile
===
--- Makefile	(revisión: 50176)
+++ Makefile	(copia de trabajo)
@@ -31,7 +31,7 @@
 	CS0118-2-lib.dll CS0122-10-lib.dll CS0122-14-lib.dll CS0122-15-lib.dll CS0433-lib.dll CS0433-2-lib.dll \
 	CS0534-3-lib.dll CS0534-4-lib.dll CS0571-3-lib.dll \
 	CS0612-2-lib.dll CS0618-2-lib.dll CS0619-8-lib.dll CS0619-17-lib.dll CS0619-32-lib.dll CS0619-33-lib.dll CS0619-36-lib.dll CS0619-42-lib.dll \
-	CS1546-lib.dll CS2015-lib.dll CS3005-16-lib.dll CS3013-module.dll
+	CS1546-lib.dll CS2015-lib.dll CS3005-16-lib.dll CS3013-module.dll CSExternAlias-lib.dll
 
 all-local:
 


extern-alias-errors.tar.gz
Description: application/compressed-tar


extern-alias-test.tar.gz
Description: application/compressed-tar
Index: typemanager.cs
===
--- typemanager.cs	(revisión: 50567)
+++ typemanager.cs	(copia de trabajo)
@@ -215,6 +215,8 @@
 	// /remarks
 	static Assembly [] assemblies;
 
+	static Hashtable external_aliases;
+
 	// remarks
 	//  Keeps a list of modules. We used this to do lookups
 	//  on the module using GetType -- needed for arrays
@@ -278,6 +280,7 @@
 		// Lets get everything clean so that we can collect before generating code
 		assemblies = null;
 		modules = null;
+		external_aliases = null;
 		builder_to_declspace = null;
 		builder_to_member_cache = null;
 		builder_to_ifaces = null;
@@ -379,6 +382,7 @@
 		assemblies = new Assembly [0];
 		modules = null;
 		
+		external_aliases = new Hashtable ();
 		builder_to_declspace = new PtrHashtable ();
 		builder_to_member_cache = new PtrHashtable ();
 		builder_to_method = new PtrHashtable ();
@@ -504,11 +508,22 @@
 		assemblies = n;
 	}
 
+	public static void AddExternAlias (string alias, Assembly a)
+	{
+		// Keep the new as the chosen one
+		external_aliases [alias] = a;
+	}
+
 public static Assembly [] GetAssemblies ()
 {
 return assemblies;
 }
 
+	public static Assembly GetExternAlias (string alias)
+	{
+		return (Assembly) external_aliases [alias];
+	}
+
 	/// summary
 	///  Registers a module builder to lookup types from
 	/// /summary
@@ -625,12 +640,63 @@
 		return found_type;
 	}
 
+	public static Type LookupTypeInExternAlias (string ns, string name, Location loc)
+	{
+		Type found_type = null;
+		
+		int idx = ns.IndexOf ('.');
+		string first = idx != -1 ? ns.Substring (0, idx) : ns;
+		Assembly assembly = (Assembly) external_aliases [first];
+		if (assembly == null)
+			throw new InternalErrorException (External alias ` + first + ' hasn't been registered.);
+		
+		string nspace = ns != first ? ns.Substring (idx + 1) : ;
+		string fullname = nspace.Length  0 ? nspace + . + name : name;
+		Type t = assembly.GetType (fullname);
+		if (t != null) {
+			if (t.IsPointer)
+throw new InternalErrorException (Use GetPointerType() to get a pointer);
+			
+			TypeAttributes ta = t.Attributes  TypeAttributes.VisibilityMask;
+			if (ta != TypeAttributes.NotPublic  ta != TypeAttributes.NestedPrivate 
+	ta != TypeAttributes.NestedAssembly  ta != TypeAttributes.NestedFamANDAssem)
+found_type = t;
+		}
+		
+		// Look for the type in the code
+		fullname = ns.Length  0 ? ns + . + name : name;
+		foreach (Module mb in modules) {
+			t = mb.GetType (fullname);
+			if (t == null)
+continue;
+			
+			if (found_type == null) {
+found_type = t;
+continue;
+			}
+
+			Report.SymbolRelatedToPreviousError (t);
+			Report.SymbolRelatedToPreviousError (found_type);
+			Report.Warning (436, 2, loc, Ignoring imported type `{0}' since the current assembly already has a declaration with the same name,
+TypeManager.CSharpName (t));
+			return t;
+		}
+
+		return found_type;
+	}
+
+	//
+	// We use this for retrieving GetNamespaces method if avalaible
+	//
+	static MethodInfo assembly_get_namespaces;
+
 	/// summary
 	///   Computes the namespaces that we import from the assemblies we reference.
 	/// /summary
 	public static void ComputeNamespaces ()
 	{
-		MethodInfo assembly_get_namespaces = typeof (Assembly).GetMethod (GetNamespaces, BindingFlags.Instance|BindingFlags.NonPublic);
+		if (assembly_get_namespaces == null)
+			assembly_get_namespaces = typeof (Assembly).GetMethod (GetNamespaces, BindingFlags.Instance|BindingFlags.NonPublic);
 
 		Hashtable cache = null;
 
@@ -682,8 +748,43 @@
 cache.Add (ns, null);
 			}
 		}
+
 	}
 
+	public static Namespace ComputeNamespacesForAlias (string name)
+	{
+		Assembly assembly = (Assembly) external_aliases [name];
+		if (assembly == null)
+			return null;
+		
+		if (assembly_get_namespaces == null)
+			

Re: [Mono-dev] [Patch] AssemblyName ctor (with corrections)

2005-09-16 Thread Carlos Alberto Cortez
Hey Paolo,

Thanks for the comments.

Carlos.

El mié, 14-09-2005 a las 20:45 +0200, Paolo Molaro escribió:
 On 09/01/05 Carlos Alberto Cortez wrote:
  Index: AssemblyName.cs
  ===
  --- AssemblyName.cs (revisión: 48811)
  +++ AssemblyName.cs (copia de trabajo)
  @@ -37,6 +37,7 @@
   using System.Text;
   using System.Runtime.InteropServices;
   using System.Runtime.CompilerServices;
  +using System.IO;
   
   using Mono.Security;
   
  @@ -80,12 +81,23 @@
  versioncompat = 
  AssemblyVersionCompatibility.SameMachine;
  }
   
  -#if NET_2_0
  +#if NET_2_0 || BOOTSTRAP_NET_2_0
  +   [MethodImpl (MethodImplOptions.InternalCall)]
  +   static extern bool ParseName (AssemblyName aname, string 
  assemblyName);
  +   
  public AssemblyName (string assemblyName)
  {
  -   name = assemblyName;
  +   if (assemblyName == null)
  +   throw new ArgumentNullException 
  (assemblyName);
  +   if (assemblyName.Length  1)
  +   throw new ArgumentException (assemblyName 
  cannot have zero length.);
  +   
  +   if (!ParseName (this, assemblyName))
  +   throw new FileLoadException (The assembly name 
  is invalid.);
 
 Is a FileLoadException really ok? Do you have tests for this?
 
  Index: assembly.c
  ===
  --- assembly.c  (revisión: 48811)
  +++ assembly.c  (copia de trabajo)
  @@ -1171,10 +1171,92 @@
  g_free ((void *) aname-hash_value);
   }
   
  +static gint 
  +to_int32_le (gchar bytes [], gint offset)
  +{
  +   return (bytes [offset+3]  24) | (bytes [offset+2]  16) | (bytes 
  [offset+1]  8) | bytes [offset];
  +}
  +
 
 The function name looks wrong. You should likely use read32() anyway.
 
   static gboolean
  -build_assembly_name (const char *name, const char *version, const char 
  *culture, const char *token, MonoAssemblyName *aname)
  +parse_public_key (const gchar *key, const gchar** pubkey)
   {
 [...]
  +   if (key  strncmp (key, null, 4) != 0) {
  +   if (!parse_public_key (key, (const gchar**) pkey)) {
 
 Why declare parse_public_key() to take a const gchar** when it's not in
 the only place it's called?
 
  +
  +   if (!g_ascii_strncasecmp (value, PublicKey=, 10)) {
  +   key = g_strstrip (value + 10);
 
 Where is key freed?
 
  +   tmp++;
  +   continue;
  +   }
  
  g_strfreev (parts);
  return FALSE;
  }
   
  -   res = build_assembly_name (dllname, version, culture, token, aname);
  +   res = build_assembly_name (dllname, version, culture, token, key, 
  aname, save_public_key);
  g_strfreev (parts);
  return res;
   }
 [...]
  Index: icall.c
  ===
  --- icall.c (revisión: 48811)
  +++ icall.c (copia de trabajo)
  @@ -4152,9 +4152,11 @@
  mono_method_desc_free (desc);
  }
   
  -   args [0] = mono_string_new (domain, name-culture);
  -   aname-cultureInfo = 
  -   mono_runtime_invoke (create_culture, NULL, args, NULL);
  +   if (name-culture) {
  +   args [0] = mono_string_new (domain, name-culture);
  +   aname-cultureInfo = 
  +   mono_runtime_invoke (create_culture, NULL, args, NULL);
 
 Put on the same line.
 
 Thanks.
 Once you'll have fixed the remaining issues, please commit.
 
 lupus
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Patch] Generic Array.Sort

2005-09-05 Thread Carlos Alberto Cortez
Hello,

yes, it has a good performance. But we have a problem, because the
runtime has a problem comparing generic types. See: 
http://bugzilla.ximian.com/show_bug.cgi?id=75889

After this is solved, we can apply the patch.

Carlos.

El lun, 05-09-2005 a las 11:27 -0400, Ben Maurer escribió:
 Hey,
 
 On Thu, 2005-08-18 at 20:45 -0500, Carlos Alberto Cortez wrote:
  I've attached a patch containing the impl for the generic versions of
  Array.Sort.
 
 What's the status of this patch? I am thinking that the performance of
 this is probably good enough that we can get it in. IIRC, there were no
 comments other than my performance based ones on the list.
 
 -- Ben
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Patch] AssemblyName ctor (yes, again)

2005-08-25 Thread Carlos Alberto Cortez
 
 This break the ABI: is_version_defined is not needed since you can check
 the fields anyway.
 is_persistent can go away some other way (for example by always having
 public_key allocated, but it would be better to find another which
 doesn't make us waste memory).

No, you can't check the fields. If Version is defined as 0.0.0.0, or
if the user didn't specified version, it happens the same. Then
Version is created for AssemblyName calling the new ctor, even when it
wasn't specified (not compatible with .Net).

However, since it could break api, as you mentioned maybe we should
find other way to do it (and also change the persistent flag).

Carlos.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Patch] AssemblyName ctor

2005-08-23 Thread Carlos Alberto Cortez
Hey,

I didn't take the choice of using the internal call (unamnaged code)
since I thought it was not optimal (Paolo's told me that was not true).
About the other point, I hadn't thought about it (using the same
function to provide the same behavior for all the possible uses).

So I will be using the internal call and will see if we need changes
there.

Thanks for the reply,
Carlos.



___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Patch] AssemblyName ctor

2005-08-22 Thread Carlos Alberto Cortez
Hey Paolo,

We have mono_assembly_name_parse, which receives a MonoString* and a
MonoAssemblyName*. The problem I find is that every time a
System.Reflection.AssemblyName were created using the described ctor, we
should also create a MonoAssemblyName (not needed).

With the managed ctor, we also avoid calling the internal call.

What do you think?

Carlos.

El sáb, 20-08-2005 a las 12:27 +0200, Paolo Molaro escribió:
 On 08/19/05 Carlos Alberto Cortez wrote:
  The patch attached implements the new AssemblyName ctor without using
  internal calls. Could anybody review it?
 
 And the advantage of this is?
 The runtime needs and does have a function to do the parsing of the
 string, so just use an icall to use that.
 
 lupus
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Re: [Mono-devel-list] [Patch] Publisher Policy support

2005-08-20 Thread Carlos Alberto Cortez
Hey Paolo,

Thanks for the comments. I will be commiting today.

Carlos.

El sáb, 20-08-2005 a las 15:50 +0200, Paolo Molaro escribió:
 On 08/17/05 Carlos Alberto Cortez wrote:
  the attached patch works ok, and applies the last suggestions you did. 
 
 Please commit, _after_ fixing the coding style with the else placement
 as I pointed out the last time.
 Thanks.
 
 lupus
 
  Index: metadata-internals.h
  ===
  --- metadata-internals.h(revisión: 48473)
  +++ metadata-internals.h(copia de trabajo)
  @@ -5,6 +5,7 @@
   #include mono/metadata/image.h
   #include mono/metadata/blob.h
   #include mono/metadata/mempool.h
  +#include mono/metadata/domain-internals.h
   #include mono/utils/mono-hash.h
   
   struct _MonoAssembly {
  @@ -236,6 +237,22 @@
  MonoDynamicTable tables [MONO_TABLE_NUM];
   };
   
  +/* Contains information about assembly binding */
  +typedef struct _MonoAssemblyBindingInfo {
  +char *name;
 
 You used spaces for indenting instead of TABs.
 
 lupus
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [Patch] AssemblyName ctor

2005-08-19 Thread Carlos Alberto Cortez
Hello again,

comments below:


 + if (String.Compare (parts [i], 0, Version=, 0, 8, true, 
 CultureInfo.InvariantCulture) == 0)
 This is most likely incorrect and needs to use an ordinal comparison, no 
 InvariantCulture (used more than one time)

I'm not sure that's correct. I tested in .Net and we requiere
insensitive comparison, not ordinal ones (as far I understood). So I
think I'll keep it this way.

Carlos.

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] AssemblyName ctor (fixed)

2005-08-19 Thread Carlos Alberto Cortez
Hey,

The attached patch contains the latest suggestions of both Kornel and
Ben. Maybe the only thing to be noted is that I kept the hexadecimal
notation when comparing chars, since the same is used in
Char.GetNumericalValue ().

New tests are also attached, and run fine under .Net 2.0

Carlos.
Index: AssemblyName.cs
===
--- AssemblyName.cs	(revisión: 48583)
+++ AssemblyName.cs	(copia de trabajo)
@@ -37,6 +37,8 @@
 using System.Text;
 using System.Runtime.InteropServices;
 using System.Runtime.CompilerServices;
+using System.IO;
+using System.Collections.Generic;
 
 using Mono.Security;
 
@@ -73,7 +75,6 @@
 		int processor_architecture;
 #endif
 #endregion
-		
 		public AssemblyName ()
 		{
 			// defaults
@@ -81,11 +82,102 @@
 		}
 
 #if NET_2_0
+		const string exceptionMessage = The assembly name is invalid.;
+		
 		public AssemblyName (string assemblyName)
 		{
-			name = assemblyName;
+			string [] parts;
+
+			if (assemblyName == null)
+throw new ArgumentNullException (assemblyName);
+			if (assemblyName.Length  1)
+throw new ArgumentException (assemblyName cannot have zero length, assemblyName);
+			
+			parts = assemblyName.Split (',');
+			name = parts [0].Trim ();
+			if (name.Length  1)
+throw new FileLoadException (exceptionMessage);
+
+			IComparerstring comparer = StringComparer.OrdinalIgnoreCase;
+			for (int i = 1; i  parts.Length; i++) {
+if (parts [i].IndexOf ('=')  0)
+	throw new FileLoadException (exceptionMessage);
+
+string [] values = parts [i].Split ('=');
+values [0] = values [0].Trim ();
+values [1] = values [1].Trim ();
+if (values [0].Length  1 || values [1].Length  1)
+	throw new FileLoadException (exceptionMessage);
+
+if (comparer.Compare (values [0], Version) == 0) {
+	if (version != null)
+		throw new FileLoadException (exceptionMessage);
+	try {
+		version = new Version (values [1]);
+	} catch (ArgumentException) {
+		throw new FileLoadException (exceptionMessage);
+	} catch (FormatException) {
+		throw new FileLoadException (exceptionMessage);
+	}
+} else if (comparer.Compare (values [0], Culture) == 0) {
+	if (cultureinfo != null)
+		throw new FileLoadException (exceptionMessage);
+	if (comparer.Compare (values [1], neutral) == 0)
+		values [1] = ;
+	cultureinfo = new CultureInfo (values [1]);
+} else if (comparer.Compare (values [0], PublicKeyToken) == 0) {
+	if (keyToken != null)
+		throw new FileLoadException (exceptionMessage);
+	ParsePublicKeyToken (values [1]);
+} else if (comparer.Compare (values [0], PublicKey) == 0) {
+	if (publicKey != null)
+		throw new FileLoadException (exceptionMessage);
+	ParsePublicKey (values [1]);
+} else
+	throw new FileLoadException (exceptionMessage);
+			}
+			
 		}
 
+		void ParsePublicKeyToken (string kToken)
+		{
+			if (kToken.Length != 16)
+throw new FileLoadException (exceptionMessage);
+
+			keyToken = new byte [8];
+			for (int i = 0, j = 0; i  8; i++) {
+keyToken [i] = (byte) (GetCharNumericValue (kToken [j++])  4);
+keyToken [i] |= (byte) GetCharNumericValue (kToken [j++]);
+			}
+		}
+
+		void ParsePublicKey (string key)
+		{
+			if (key.Length != 320)
+throw new FileLoadException (exceptionMessage);
+			
+			publicKey = new byte [160];
+			for (int i = 0, j = 0; i  160; i++) {
+publicKey [i] = (byte) (GetCharNumericValue (key [j++])  4);
+publicKey [i] |= (byte) GetCharNumericValue (key [j++]);
+			}
+			flags = AssemblyNameFlags.PublicKey;
+		}
+
+		int GetCharNumericValue (char c)
+		{
+			if (c = (char)0x30  c = (char)0x3B)
+return c - 0x30; // 0-9
+			if (c = (char)0x41  c = (char)0x46)
+return c - 0x37; // A-F
+			if (c = (char)0x61  c = (char)0x66)
+return c - 0x57; // a-f
+
+			throw new FileLoadException (exceptionMessage);
+		}
+#endif
+		
+#if NET_2_0
 		[MonoTODO]
 		public ProcessorArchitecture ProcessorArchitecture {
 			get {
Index: AssemblyNameTest.cs
===
--- AssemblyNameTest.cs	(revisión: 48583)
+++ AssemblyNameTest.cs	(copia de trabajo)
@@ -531,6 +531,228 @@
 		}
 		return tokenString;
 	}
+
+#if NET_2_0
+	[Test]
+	public void Ctor1 ()
+	{
+		const string assemblyName = TestAssembly;
+		AssemblyName an = new AssemblyName (assemblyName);
+		Assert.IsNotNull (an.Name, Ctor1#1);
+		Assert.AreEqual (an.Name, assemblyName, Ctor1#2);
+	}
+
+	[Test]
+	public void Ctor2 ()
+	{
+		const string assemblyName = TestAssembly;
+		const string assemblyVersion = 1.2.3.4;
+		AssemblyName an = new AssemblyName (assemblyName + , Version= + assemblyVersion);
+		Assert.IsNotNull (an.Name, Ctor2#1);
+		Assert.AreEqual (an.Name, assemblyName, Ctor2#2);
+		Assert.IsNotNull (an.Version, Ctor2#3);
+		Assert.AreEqual (an.Version, new Version (assemblyVersion), Ctor2#4);
+	}
+
+	[Test]
+	public void Ctor3 ()
+	{
+		const 

[Mono-dev] [Patch] Generic Array.Sort

2005-08-18 Thread Carlos Alberto Cortez
Hey,

I've attached a patch containing the impl for the generic versions of
Array.Sort.

Could anybody take a look at it?

Carlos.

Index: Array.cs
===
--- Array.cs	(revisión: 48473)
+++ Array.cs	(copia de trabajo)
@@ -912,6 +912,18 @@
 		}
 
 #if NET_2_0
+		static Swapper get_swapperT (T [] array)
+		{
+			if (array is int[])
+return new Swapper (array.int_swapper);
+			if (array is double[])
+return new Swapper (array.double_swapper);
+
+			return new Swapper (array.obj_swapper);
+		}
+#endif
+
+#if NET_2_0
 		[ReliabilityContractAttribute (Consistency.MayCorruptInstance, Cer.MayFail)]
 #endif
 		public static void Reverse (Array array)
@@ -1275,6 +1287,239 @@
 return comparer.Compare (value1, value2);
 		}
 	
+#if NET_2_0
+		[CLSCompliant (false)]
+		public static void SortT (T [] array)
+		{
+			if (array == null)
+throw new ArgumentNullException (array);
+
+			SortT, T (array, null, 0, array.Length, null);
+		}
+
+		[CLSCompliant (false)]
+		public static void SortK, V (K [] keys, V [] items)
+		{
+			if (keys == null)
+throw new ArgumentNullException (keys);
+			
+			SortK, V (keys, items, 0, keys.Length, null);
+		}
+
+		[CLSCompliant (false)]
+		public static void SortT (T [] array, IComparerT comparer)
+		{
+			if (array == null)
+throw new ArgumentNullException (array);
+
+			SortT, T (array, null, 0, array.Length, comparer);
+		}
+
+		[CLSCompliant (false)]
+		public static void SortK, V (K [] keys, V [] items, IComparerK comparer)
+		{
+			if (keys == null)
+throw new ArgumentNullException (keys);
+			
+			SortK, V (keys, items, 0, keys.Length, comparer);
+		}
+
+		[CLSCompliant (false)]
+		public static void SortT (T [] array, int index, int length)
+		{
+			if (array == null)
+throw new ArgumentNullException (array);
+			
+			SortT, T (array, null, index, length, null);
+		}
+
+		[CLSCompliant (false)]
+		public static void SortK, V (K [] keys, V [] items, int index, int length)
+		{
+			SortK, V (keys, items, index, length, null);
+		}
+
+		[CLSCompliant (false)]
+		public static void SortT (T [] array, int index, int length, IComparerT comparer)
+		{
+			if (array == null)
+throw new ArgumentNullException (array);
+
+			SortT, T (array, null, index, length, comparer);
+		}
+
+		[CLSCompliant (false)]
+		public static void SortK, V (K [] keys, V [] items, int index, int length, IComparerK comparer)
+		{
+			if (keys == null)
+throw new ArgumentNullException (keys);
+
+			if (index  0)
+throw new ArgumentOutOfRangeException (index);
+
+			if (length  0)
+throw new ArgumentOutOfRangeException (length);
+
+			if (keys.Length - index  length
+|| (items != null  index  items.Length - length))
+throw new ArgumentException ();
+
+			if (length = 1)
+return;
+			
+			//
+			// Check for value types which can be sorted without Compare () method
+			//
+			if (comparer == null) {
+Swapper iswapper;
+if (items == null)
+	iswapper = null;
+else 
+	iswapper = get_swapperV (items);
+if (keys is double[]) {
+	combsort (keys as double[], index, length, iswapper);
+	return;
+}
+if (keys is int[]) {
+	combsort (keys as int[], index, length, iswapper);
+	return;
+}
+if (keys is char[]) {
+	combsort (keys as char[], index, length, iswapper);
+	return;
+}
+			}
+			
+			try {
+int low0 = index;
+int high0 = index + length - 1;
+qsortK, V (keys, items, low0, high0, comparer);
+			}
+			catch (Exception e) {
+throw new InvalidOperationException (Locale.GetText (The comparer threw an exception.), e);
+			}
+		}
+
+		[CLSCompliant (false)]
+		public static void SortT (T [] array, ComparisonT comparison)
+		{
+			if (array == null)
+throw new ArgumentNullException (array);
+			if (comparison == null)
+throw new ArgumentNullException (comparison);
+
+			if (array.Length = 1)
+return;
+			
+			try {
+int low0 = 0;
+int high0 = array.Length - 1;
+qsortT (array, low0, high0, comparison);
+			}
+			catch (Exception e) {
+throw new InvalidOperationException (Locale.GetText (Comparison threw an exception.), e);
+			}
+		}
+
+		private static void qsortK, V (K [] keys, V [] items, int low0, int high0, IComparerK comparer)
+		{
+			if (low0 = high0)
+return;
+
+			int low = low0;
+			int high = high0;
+
+			K keyPivot = keys [(low + high) / 2];
+
+			while (low = high) {
+// Move the walls in
+while (low  high0  compareK (keys [low], keyPivot, comparer)  0)
+	++low;
+while (high  low0  compareK (keyPivot, keys [high], comparer)  0)
+	--high;
+
+if (low = high) {
+	swapK, V (keys, items, low, high);
+	++low;
+	--high;
+}
+			}
+
+			if (low0  high)
+qsortK, V (keys, items, low0, high, comparer);
+			if (low  high0)
+qsortK, V (keys, items, low, high0, comparer);
+		}
+
+		private static void qsortT (T [] array, int low0, int high0, ComparisonT 

Re: [Mono-dev] Re: [Mono-devel-list] [Patch] Publisher Policy support

2005-08-17 Thread Carlos Alberto Cortez
Hey, 

the attached patch works ok, and applies the last suggestions you did. 

Carlos.

El lun, 15-08-2005 a las 19:55 +0200, Paolo Molaro escribió:
 On 08/13/05 Carlos Alberto Cortez wrote:
   struct version doesn't conform to the mono naming conventions.
   Use a typedef and something like MonoAssemblyVersion.
  
  This was based on the fact I wanted to keep it -at least initially- as
  private. We can rename it the way you want, however.
 
 I just noticed we have already AssemblyVersionSet in domain-internals.h, so
 please use that.
 
   Why do you associate assembly bindings to domains? Since they are stored
   in the GAC they seem to be valid for all the domains.
  
  That's the way they are associated in .Net in both 1.0 and 1.1. In .Net
  2.0 they are domain neutral. So, it's a matter of deciding where we
  should put them.
 
 From my limited understanding of it, it makes no sense to have them
 per-domain, unless there is also a separate mechanims to tell the
 runtime about policy files that is per-domain. If the files are in the
 GAC, you end up with the same copy of the policy info in each domain.
 
   Since this stuff sseems to be used only in one file, there is no point
   in exposing them in the headers.
  
  I needed it for freeing in mono_domain_unload, but since we are going to
 
 This was missing from the patch.
 Thanks.
 
 lupus
 
Index: assembly.c
===
--- assembly.c	(revisión: 48473)
+++ assembly.c	(copia de trabajo)
@@ -20,6 +20,7 @@
 #include mono/metadata/loader.h
 #include mono/metadata/tabledefs.h
 #include mono/metadata/metadata-internals.h
+#include mono/metadata/class-internals.h
 #include mono/metadata/domain-internals.h
 #include mono/io-layer/io-layer.h
 #include mono/utils/mono-uri.h
@@ -128,6 +129,9 @@
 /* Reflection only private hook functions */
 static MonoAssembly* mono_assembly_refonly_invoke_search_hook (MonoAssemblyName *aname);
 
+/* Loaded assembly binding info */
+static GSList *loaded_assembly_bindings = NULL;
+
 static gchar*
 encode_public_tok (const guchar *token, gint32 len)
 {
@@ -193,6 +197,132 @@
 	}
 }
 
+static gboolean
+assembly_binding_maps_name (MonoAssemblyBindingInfo *info, MonoAssemblyName *aname)
+{
+	if (strcmp (info-name, aname-name))
+		return FALSE;
+
+	if (info-major != aname-major || info-minor != aname-minor)
+		return FALSE;
+
+	if ((info-culture != NULL) != (aname-culture != NULL))
+		return FALSE;
+	
+	if (info-culture  strcmp (info-culture, aname-culture))
+		return FALSE;
+	
+	if (strcmp ((const char *)info-public_key_token, (const char *)aname-public_key_token))
+		return FALSE;
+
+	return TRUE;
+}
+
+void
+mono_assembly_binding_info_free (MonoAssemblyBindingInfo *info)
+{
+	g_free (info-name);
+	g_free (info-culture);
+}
+
+static void
+get_publisher_policy_info (MonoImage *image, MonoAssemblyName *aname, MonoAssemblyBindingInfo *binding_info)
+{
+	MonoTableInfo *t;
+	guint32 cols [MONO_MANIFEST_SIZE];
+	const gchar *filename;
+	gchar *subpath, *fullpath;
+
+	t = image-tables [MONO_TABLE_MANIFESTRESOURCE];
+	/* MS Impl. accepts policy assemblies with more than
+	 * one manifest resource, and only takes the first one */
+	if (t-rows  1) {
+		binding_info-is_valid = FALSE;
+		return;
+	}
+	
+	mono_metadata_decode_row (t, 0, cols, MONO_MANIFEST_SIZE);
+	if ((cols [MONO_MANIFEST_IMPLEMENTATION]  MONO_IMPLEMENTATION_MASK) != MONO_IMPLEMENTATION_FILE) {
+		binding_info-is_valid = FALSE;
+		return;
+	}
+	
+	filename = mono_metadata_string_heap (image, cols [MONO_MANIFEST_NAME]);
+	g_assert (filename != NULL);
+	
+	/* By default is invalid */
+	subpath = g_path_get_dirname (image-name);
+	fullpath = g_build_path (G_DIR_SEPARATOR_S, subpath, filename, NULL);
+	mono_config_parse_publisher_policy (fullpath, binding_info);
+	g_free (subpath);
+	g_free (fullpath);
+	
+	/* Define the optional elements/attributes before checking */
+	if (!binding_info-culture)
+		binding_info-culture = g_strdup ();
+	
+	/* Check that the most important elements/attributes exist */
+	if (!binding_info-name || !binding_info-public_key_token [0] || !binding_info-has_old_version_bottom ||
+			!binding_info-has_new_version || !assembly_binding_maps_name (binding_info, aname)) {
+		mono_assembly_binding_info_free (binding_info);
+		binding_info-is_valid = FALSE;
+		return;
+	}
+
+	binding_info-is_valid = TRUE;
+}
+
+static int
+compare_versions (AssemblyVersionSet *v, MonoAssemblyName *aname)
+{
+	if (v-major  aname-major)
+		return 1;
+	else if (v-major  aname-major)
+		return -1;
+
+	if (v-minor  aname-minor)
+		return 1;
+	else if (v-minor  aname-minor)
+		return -1;
+
+	if (v-build  aname-build)
+		return 1;
+	else if (v-build  aname-build)
+		return -1;
+
+	if (v-revision  aname-revision)
+		return 1;
+	else if (v-revision  aname-revision)
+		return -1;
+
+	return 0;
+}
+
+static gboolean
+check_policy_versions (MonoAssemblyBindingInfo *info, MonoAssemblyName *name)
+{
+	if (!info-is_valid)
+		return

Re: [Mono-dev] Re: [Mono-devel-list] [Patch] Publisher Policy support

2005-08-15 Thread Carlos Alberto Cortez
Hey Paolo,

Thanks for answering, comments below:

El vie, 12-08-2005 a las 15:49 +0200, Paolo Molaro escribió:
 On 08/11/05 Carlos Alberto Cortez wrote:
  Index: assembly.c
  ===
  --- assembly.c  (revisión: 47896)
  +++ assembly.c  (copia de trabajo)
 [...]
  +void
  +assembly_binding_info_free (AssemblyBindingInfo *info)
 
 This function is exported, but it has a namespace-polluting name.
 
  +{
  +   g_free (info-name);
  +   g_free (info-culture);
  +}
  +
  +static void
  +start_element (GMarkupParseContext *context, 
 
 Please move all the uses of GMarkup inside mono-config.c and make also
 sure it uses the functions there to deal with bundled files.
 

Well, I found that the functions at mono-config.c are a little bit
overheaded IHMO. But we could move there, however. I had a problem
before, and that caused me to move my functions inside assembly.c, but
since I don't rememebr the problem,  I will give a try.

  +   if (!strcmp (element_name, assemblyIdentity)) {
  +   for (n = 0; attribute_names [n]; n++) {
  +   const gchar *attribute_name = attribute_names [n];
  +   
  +   if (!strcmp (attribute_name, name))
  +   info-name = g_strdup (attribute_values [n]);
  +   else if (!strcmp (attribute_name, publicKeyToken)) {
  +   if (strlen (attribute_values [n]) == 
  MONO_PUBLIC_KEY_TOKEN_LENGTH - 1)
  +   g_strlcpy (info-public_key_token, 
  attribute_values [n], MONO_PUBLIC_KEY_TOKEN_LENGTH);
  +   }
  +   else if (!strcmp (attribute_name, culture)) {
 
 The else needs to go into the same line as the '}'.

Good, will take care of it.

 
  +   numbers = version = g_strsplit (*(versions + 
  1), ., 4);
  +   info-old_version_top.major = *numbers ? atoi 
  (*numbers++) : -1;
  +   info-old_version_top.minor = *numbers ? atoi 
  (*numbers++) : -1;
  +   info-old_version_top.build = *numbers ? atoi 
  (*numbers++) : -1;
  +   info-old_version_top.revision = *numbers ? 
  atoi (*numbers) : 1;
 
 Is it correct to use 1 here and not -1 as in all the other cases?

Thanks for the typo correction ;-)

 
  +   }
  +   else if (!strcmp (attribute_name, newVersion)) {
 
 Usuale else misplacement.
 

Good.

  +static int
  +compare_versions (struct version *v, MonoAssemblyName *aname)
 
 struct version doesn't conform to the mono naming conventions.
 Use a typedef and something like MonoAssemblyVersion.
 

This was based on the fact I wanted to keep it -at least initially- as
private. We can rename it the way you want, however.

  +static MonoAssemblyName*
  +mono_assembly_bind_version (AssemblyBindingInfo *info, MonoAssemblyName 
  *aname, MonoAssemblyName *dest_name)
  +{
  +   memcpy (dest_name, aname, sizeof (MonoAssemblyName));
  +   dest_name-major = info-new_version.major;
  +   dest_name-minor = info-new_version.minor;
  +   dest_name-build = info-new_version.build;
  +   dest_name-revision = info-new_version.revision;
  +   
  +   return dest_name;
  +}
  +
  +/* LOCKING: Assumes that we are already locked */
  +static AssemblyBindingInfo*
  +search_binding_loaded (MonoAssemblyName *aname)
  +{
  +   GSList *tmp;
  +   MonoDomain *domain = mono_domain_get ();
  +
  +   for (tmp = domain-assembly_bindings; tmp; tmp = tmp-next) {
  +   AssemblyBindingInfo *info = tmp-data;
  +   if (assembly_binding_maps_name (info, aname))
  +   return info;
  +   }
 
 Why do you associate assembly bindings to domains? Since they are stored
 in the GAC they seem to be valid for all the domains.

That's the way they are associated in .Net in both 1.0 and 1.1. In .Net
2.0 they are domain neutral. So, it's a matter of deciding where we
should put them. 

 
  Index: metadata-internals.h
  ===
  --- metadata-internals.h(revisión: 47896)
  +++ metadata-internals.h(copia de trabajo)
  @@ -236,6 +236,25 @@
  MonoDynamicTable tables [MONO_TABLE_NUM];
   };
   
  +struct version {
  +   int major;
  +   int minor;
  +   int build;
  +   int revision;
  +};
  +
  +/* Contains information about assembly binding */
  +typedef struct _AssemblyBindingInfo {
  +   char *name;
  +   char *culture;
  +   guchar public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
  +   int major;
  +   int minor;
  +   struct version old_version_bottom;
  +   struct version old_version_top;
  +   struct version new_version;
  +} AssemblyBindingInfo;
 
 Since this stuff sseems to be used only in one file, there is no point
 in exposing them in the headers.

I needed it for freeing in mono_domain_unload, but since we are going to
move it inside mono-config

[Mono-dev] Re: [Mono-devel-list] [Patch] Publisher Policy support

2005-08-14 Thread Carlos Alberto Cortez
Hey,

Great. Maybe we could move it to the svn tree.

Carlos.

El vie, 12-08-2005 a las 19:30 -0400, Ben Maurer escribió:
  Hey,
 
  I'm re-sending this patch, since the corrected version was only sent by
  mistake to Miguel, Paolo and Ben.
 
  Ben, I applied your change, do you think it's ok?
 
 
 As I remember, I had no other objections to the patch.
 
 -- Ben
 
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] AssemblyName ctor

2005-08-09 Thread Carlos Alberto Cortez
hey,

Currently the AssemblyName (string) ctor is not implemented to receive
the long format assembly name (such MyAssembly, Version=1.2,...). The
attached patch adds support for it.

Some tests are also attached.

Carlos.
Index: icall.c
===
--- icall.c	(revisión: 48211)
+++ icall.c	(copia de trabajo)
@@ -3730,6 +3730,44 @@
 	return result;
 }
 
+static void
+ves_icall_System_Reflection_AssemblyName_InternalParseKeyToken (MonoReflectionAssemblyName *aname, MonoString *key_token)
+{
+	char *p, *token;
+	int i, j;
+
+	token = mono_string_to_utf8 (key_token);
+	aname-keyToken = mono_array_new (mono_domain_get (), mono_defaults.byte_class, 8);
+	p = mono_array_addr (aname-keyToken, char, 0);
+	for (i = 0, j = 0; i  8; i++) {
+		*p = g_ascii_xdigit_value (token [j++])  4;
+		*p |= g_ascii_xdigit_value (token [j++]);
+		p++;
+	}
+
+	g_free (token);
+}
+
+static void
+ves_icall_System_Reflection_AssemblyName_InternalParseKey (MonoReflectionAssemblyName *aname, MonoString *public_key)
+{
+	char *p, *key;
+	int pkey_len, i, j;
+
+	key = mono_string_to_utf8 (public_key);
+	pkey_len = mono_string_length (public_key) / 2; // Format used in .Net
+
+	aname-publicKey = mono_array_new (mono_domain_get (), mono_defaults.byte_class, pkey_len);
+	p = mono_array_addr (aname-publicKey, char, 0);
+	for (i = 0, j = 0; i  pkey_len; i++) {
+		*p = g_ascii_xdigit_value (key [j++])  4;
+		*p |= g_ascii_xdigit_value (key [j++]);
+		p++;
+	}
+
+	g_free (key);
+}
+
 typedef struct {
 	MonoArray *res;
 	int idx;
@@ -6510,6 +6548,11 @@
 	{load_with_partial_name, ves_icall_System_Reflection_Assembly_load_with_partial_name}
 };
 
+static const IcallEntry assembly_name_icalls [] = {
+	{InternalParseKey, ves_icall_System_Reflection_AssemblyName_InternalParseKey},
+	{InternalParseKeyToken, ves_icall_System_Reflection_AssemblyName_InternalParseKeyToken}
+};
+
 static const IcallEntry methodbase_icalls [] = {
 	{GetCurrentMethod, ves_icall_GetCurrentMethod},
 	{GetMethodBodyInternal, ves_icall_System_Reflection_MethodBase_GetMethodBodyInternal},
@@ -7046,6 +7089,7 @@
 	{System.Net.Sockets.SocketException, socketex_icalls, G_N_ELEMENTS (socketex_icalls)},
 	{System.Object, object_icalls, G_N_ELEMENTS (object_icalls)},
 	{System.Reflection.Assembly, assembly_icalls, G_N_ELEMENTS (assembly_icalls)},
+	{System.Reflection.AssemblyName, assembly_name_icalls, G_N_ELEMENTS (assembly_name_icalls)},
 	{System.Reflection.Emit.AssemblyBuilder, assemblybuilder_icalls, G_N_ELEMENTS (assemblybuilder_icalls)},
 	{System.Reflection.Emit.CustomAttributeBuilder, customattrbuilder_icalls, G_N_ELEMENTS (customattrbuilder_icalls)},
 	{System.Reflection.Emit.DynamicMethod, dynamicmethod_icalls, G_N_ELEMENTS (dynamicmethod_icalls)},
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-dev] [Patch] AssemblyName ctor (correction)

2005-08-09 Thread Carlos Alberto Cortez
In the last message some attachments were missing. 
All of them are now correctly attached.
Index: AssemblyName.cs
===
--- AssemblyName.cs	(revisión: 48211)
+++ AssemblyName.cs	(copia de trabajo)
@@ -37,6 +37,7 @@
 using System.Text;
 using System.Runtime.InteropServices;
 using System.Runtime.CompilerServices;
+using System.IO;
 
 using Mono.Security;
 
@@ -73,6 +74,7 @@
 		int processor_architecture;
 #endif
 #endregion
+		static readonly char [] delimiter = {','};
 		
 		public AssemblyName ()
 		{
@@ -83,9 +85,64 @@
 #if NET_2_0
 		public AssemblyName (string assemblyName)
 		{
-			name = assemblyName;
+			string [] parts;
+
+			if (assemblyName == null)
+throw new ArgumentNullException (assemblyName);
+			if (assemblyName == )
+throw new ArgumentException (assemblyName cannot have zero length, assemblyName);
+			
+			// Remove white spaces, to mimic .Net behavior
+			assemblyName = assemblyName.Replace ( , );
+			parts = assemblyName.Split (delimiter);
+			if (parts [0] == )
+throw new FileLoadException (The assembly name is invalid.);
+
+			name = parts [0];
+			for (int i = 0; i  parts.Length; i++) {
+try {
+	if (String.Compare (parts [i], 0, Version=, 0, 8, true, CultureInfo.InvariantCulture) == 0)
+		version = new Version (parts [i].Substring (8, parts [i].Length - 8));
+	else if (String.Compare (parts [i], 0, Culture=, 0, 8, true, CultureInfo.InvariantCulture) == 0) {
+		string culture = parts [i].Substring (8, parts [i].Length - 8);
+		if (String.Compare (culture, neutral, true, CultureInfo.InvariantCulture) == 0)
+			culture = ;
+		cultureinfo = new CultureInfo (culture);
+	}
+	else if (String.Compare (parts [i], 0, PublicKeyToken=, 0, 15, true, CultureInfo.InvariantCulture) == 0)
+		ParseKeyToken (parts [i].Substring (15, parts [i].Length - 15));
+	else if (String.Compare (parts [i], 0, PublicKey=, 0, 10, true, CultureInfo.InvariantCulture) == 0)
+		ParseKey (parts [i].Substring (10, parts [i].Length - 10));
+} catch {
+	throw new FileLoadException (The assembly name is invalid.);
+}
+			}
+			
 		}
 
+		[MethodImpl (MethodImplOptions.InternalCall)]
+		extern void InternalParseKeyToken (string keyToken);
+		
+		void ParseKeyToken (string kToken)
+		{
+			if (kToken.Length != 16)
+throw new Exception ();
+
+			InternalParseKeyToken (kToken);
+		}
+
+		[MethodImpl (MethodImplOptions.InternalCall)]
+		extern void InternalParseKey (string key);
+		
+		void ParseKey (string key)
+		{
+			if (key.Length != 320)
+throw new Exception ();
+			
+			flags = AssemblyNameFlags.PublicKey;
+			InternalParseKey (key);
+		}
+
 		[MonoTODO]
 		public ProcessorArchitecture ProcessorArchitecture {
 			get {
Index: AssemblyNameTest.cs
===
--- AssemblyNameTest.cs	(revisión: 48211)
+++ AssemblyNameTest.cs	(copia de trabajo)
@@ -19,6 +19,7 @@
 using System.Globalization;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Security;
+using System.Text;
 
 namespace MonoTests.System.Reflection {
 
@@ -531,6 +532,73 @@
 		}
 		return tokenString;
 	}
+
+#if NET_2_0
+	[Test]
+	public void Ctor1 ()
+	{
+		const string assemblyName = TestAssembly;
+		AssemblyName an = new AssemblyName (assemblyName);
+		Assert.IsNotNull (an.Name, Ctor1#1);
+		Assert.AreEqual (an.Name, assemblyName, Ctor1#2);
+	}
+
+	[Test]
+	public void Ctor2 ()
+	{
+		const string assemblyName = TestAssembly;
+		const string assemblyVersion = 1.2;
+		AssemblyName an = new AssemblyName (assemblyName + , Version= + assemblyVersion);
+		Assert.IsNotNull (an.Name, Ctor2#1);
+		Assert.AreEqual (an.Name, assemblyName, Ctor2#2);
+		Assert.IsNotNull (an.Version, Ctor2#3);
+		Assert.AreEqual (an.Version, new Version (assemblyVersion), Ctor2#4);
+	}
+
+	[Test]
+	public void Ctor3 ()
+	{
+		const string assemblyName = TestAssembly;
+		const string assemblyCulture = en-US;
+		AssemblyName an = new AssemblyName (assemblyName + , Culture= + assemblyCulture);
+		Assert.IsNotNull (an.Name, Ctor3#1);
+		Assert.AreEqual (an.Name, assemblyName, Ctor3#2);
+		Assert.IsNotNull (an.CultureInfo, Ctor3#3);
+		Assert.AreEqual (an.CultureInfo, new CultureInfo (assemblyCulture), Ctor3#4);
+	}
+
+	[Test]
+	public void Ctor4 ()
+	{
+		const string assemblyName = TestAssembly;
+		byte [] assemblyKeyToken;
+		AssemblyName an = new AssemblyName (assemblyName + , PublicKeyToken= + GetTokenString (token));
+		Assert.IsNotNull (an.Name, Ctor4#1);
+		Assert.AreEqual (an.Name, assemblyName, Ctor4#2);
+		Assert.IsNotNull (assemblyKeyToken = an.GetPublicKeyToken (), Ctor4#3);
+		Assert.AreEqual (assemblyKeyToken, token, Ctor4#4);
+	}
+
+	[Test]
+	public void Ctor5 ()
+	{
+		const string assemblyName = TestAssembly;
+		const string assemblyCulture = neutral;
+		const string assemblyVersion = 1.2.3.4;
+		byte [] assemblyKeyToken;
+
+		AssemblyName an = new 

[Mono-dev] Re: [Mono-devel-list] [PATCH] Check for assembly attributes

2005-08-08 Thread Carlos Alberto Cortez
Hey,

I'm implementing it right now. So, as soon as it gets in the svn tree,
we can re-use it in mcs.

Carlos.

El lun, 08-08-2005 a las 14:42 +0100, Marek Safar escribió:
 Hello,
 
 I just checked it, and saw that in the .Net docs, it states that
 AssemblyName (string name) receives the simple name. However, in the
 beta 2, if you pass the long format name, it parses it. 
   
 
 I think we should keep this change to mcs this way, and wait for this
 change in the api (System.Reflection) to be 'official'. On the other
 hand, we could just implement the constructor the way .Net does, and the
 re-use it.
   
 
 I think Beta2 API is more or less stable. I prefer to implement this 
 piece of API at least in same way as you did for mcs.
 If you don't want to do it then mark relevant code in mcs with a comment 
 about this.
 
 Marek
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-devel-list] [PATCH] Check for assembly attributes

2005-08-05 Thread Carlos Alberto Cortez
Hey,

The constructor receiving a string doesn't parse the long format name.
Instead, it just assign Name property. So, I don't think we can use
it.

Carlos.

El vie, 05-08-2005 a las 13:55 +0100, Marek Safar escribió:
 Hello,
 
 The other things were applied. I attached two test cases. Do you think
 we could need more tests?
  
 
   
 
 They look fine.
 
 BTW: Could not we use AssemblyName class from corlib to avoid this 
 parsing code ?
 
 
 
 
 Well, yes. That's exactly what I tought. But, we don't have a Parse ()
 method that takes the assembly name (long format) and retrieves an
 AssemblyName. At least, I didn't found it ;-)
 
   
 
 I found string constructor in AssemblyName class which should be exactly 
 what we need.
 
 Marek
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-devel-list] [PATCH] Check for assembly attributes

2005-08-05 Thread Carlos Alberto Cortez
Hey,

I just checked it, and saw that in the .Net docs, it states that
AssemblyName (string name) receives the simple name. However, in the
beta 2, if you pass the long format name, it parses it. 

I think we should keep this change to mcs this way, and wait for this
change in the api (System.Reflection) to be 'official'. On the other
hand, we could just implement the constructor the way .Net does, and the
re-use it.

Carlos.

El vie, 05-08-2005 a las 13:55 +0100, Marek Safar escribió:
 Hello,
 
 The other things were applied. I attached two test cases. Do you think
 we could need more tests?
  
 
   
 
 They look fine.
 
 BTW: Could not we use AssemblyName class from corlib to avoid this 
 parsing code ?
 
 
 
 
 Well, yes. That's exactly what I tought. But, we don't have a Parse ()
 method that takes the assembly name (long format) and retrieves an
 AssemblyName. At least, I didn't found it ;-)
 
   
 
 I found string constructor in AssemblyName class which should be exactly 
 what we need.
 
 Marek
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-devel-list] Differences between Mono and .NET

2005-08-05 Thread Carlos Alberto Cortez
Hello,

I think. the best of Mono is its open source nature, and the fact thet
everybody can adapt it or modify it, adding the stability and the
support for more than one arch.

On the other hand, what Mono is missing the most, is an IDE for Winforms
and also documentation (docs for Mono libs and bindings).

My two cents,
Carlos.

El vie, 05-08-2005 a las 17:52 +0200, Martin Willemoes Hansen escribió:
 Hello everybody
 
 I'll be talking about differences between Mono and .NET in September and
 It would be nice to know what you think is the best difference between
 Mono and .NET.
 
 I have a short list of differences:
 
 1. Platform independent
 2. Open Source
 3. Extra cryptofunctionality
 4. Extra libs like Cecil
 5. Lacking behind in certain areas like missing CAS
 
 What do you think is the best thing about Mono compared to .NET?
 What do you think Mono is lacking the most compared to .NET?
 
 Best regards

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-devel-list] [PATCH] Check for assembly attributes

2005-08-04 Thread Carlos Alberto Cortez
Hello,

Below my comments.

El jue, 04-08-2005 a las 00:46 -0400, Ben Maurer escribió:
 On Wed, 2005-08-03 at 20:55 -0500, Carlos Alberto Cortez wrote:
  Hey,
  
  A patch is attached, containing a check for InternalsVisibleToAttribute,
  when it is applied to an assembly. It reports a warning or shows an
  error, just like csc does.
 
 
 
  +   if (t.Equals (typeof 
  (System.Runtime.CompilerServices.InternalsVisibleToAttribute))) {
 
 This precludes us from using the assembly in mscorlib.dll. It could
 potentially be useful to use there -- say to let us write nunit tests
 that poked at internals.

I'm not very sure about the scenarios you are thinking in. Could you
please show some detailed examples?

 
 See http://blogs.msdn.com/junfeng/archive/2004/09/14/229254.aspx about
 how there is support for handling commas in file names. Your code would
 break under this.

Well, I didn't know about that, but IHMO I find it like a very bad
practice, and I'm sure that there aren't people out there who like to
call their assemblies 'My,Assembly,Version=xx... or something like
that.

Also, to test this, I tried to load an assembly named
'Test,Assembly' (using Assembly.Load ()) in both mono and ..NET, and
neither could load it successfully. The only way to work with it AFAIK
is when you get name of the assembly itself, or use Assembly.LoadFrom.

So, I don't think it's that important. But, if anybody find it
neccessary, we could add it.

 
 Finally, comparisons should be done with the invariant culture.
 
 -- Ben
 

Thanks, I just noted that's the way the comparisons are done in the
runtime.

Carlos.


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-devel-list] [PATCH] Check for assembly attributes

2005-08-04 Thread Carlos Alberto Cortez
Right, that's true, since we need to support an insensitive case
comparison. Just corrected that.

Carlos.

El jue, 04-08-2005 a las 18:23 -0400, Ben Maurer escribió:
 On Thu, 2005-08-04 at 17:15 -0500, Carlos Alberto Cortez wrote:
  +   if (String.CompareOrdinal
  (values [0], Version) == 0)
  +   version = true;
 
 Weren't these case insensitive in your first version?
 
 If they are, then you can just use String.Equals, otherwise, i think
 this call is wrong
 
 -- Ben
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-devel-list] Re: [Mono-patches] r47921 - trunk/mcs/gmcs

2005-08-03 Thread Carlos Alberto Cortez
Hey Martin,

What errors did you receive? Before I commited this patch I ran all the
tests and all the error (mcs/tests, mcs/errors(), and even built my tree
without problems.

Thanks,
Carlos.

El mar, 02-08-2005 a las 12:33 -0400, Martin Baulig escribió:
 Author: martin
 Date: 2005-08-02 12:33:16 -0400 (Tue, 02 Aug 2005)
 New Revision: 47921
 
 Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/ecore.cs
 Log:
 Reverting Carlos's latest changes - please test your stuff before
 committing.
 
 
 Modified: trunk/mcs/gmcs/ChangeLog
 ===
 --- trunk/mcs/gmcs/ChangeLog  2005-08-02 16:26:27 UTC (rev 47920)
 +++ trunk/mcs/gmcs/ChangeLog  2005-08-02 16:33:16 UTC (rev 47921)
 @@ -1,11 +1,3 @@
 -2005-07-27  Carlos Alberto Cortez [EMAIL PROTECTED]
 -
 - Fix #75417
 - * ecore.cs (Expression.IsAccessorAccessible): Change the check for
 - Private accessor case, using TypeManager.IsPrivateAccessible instead of
 - invocation_type == mi.DeclaringType, since the first one also checks
 - other condition used by generic instances.
 - 
  2005-07-27  Martin Baulig  [EMAIL PROTECTED]
  
   * anonymous.cs (CaptureContext.AddField): Added
 
 Modified: trunk/mcs/gmcs/ecore.cs
 ===
 --- trunk/mcs/gmcs/ecore.cs   2005-08-02 16:26:27 UTC (rev 47920)
 +++ trunk/mcs/gmcs/ecore.cs   2005-08-02 16:33:16 UTC (rev 47921)
 @@ -191,7 +191,7 @@
   // If only accessible to the current class or children
   //
   if (ma == MethodAttributes.Private)
 - return TypeManager.IsPrivateAccessible 
 (invocation_type, mi.DeclaringType) ||
 + return invocation_type == mi.DeclaringType ||
   TypeManager.IsNestedChildOf 
 (invocation_type, mi.DeclaringType);
  
   if (mi.DeclaringType.Assembly == 
 invocation_type.Assembly) {
 
 ___
 Mono-patches maillist  -  Mono-patches@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-patches
 
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-devel-list] [PATCH] Check for assembly attributes

2005-08-03 Thread Carlos Alberto Cortez
Hey,

A patch is attached, containing a check for InternalsVisibleToAttribute,
when it is applied to an assembly. It reports a warning or shows an
error, just like csc does.

Carlos.
Index: ChangeLog
===
--- ChangeLog	(revisión: 47987)
+++ ChangeLog	(copia de trabajo)
@@ -1,3 +1,9 @@
+2005-08-03  Carlos Alberto Cortez [EMAIL PROTECTED]
+
+	* codegen.cs
+	(AssemblyClass.CheckAttributeValid): New method to check
+	validity in assembly attributes.
+	
 2005-08-03  Martin Baulig  [EMAIL PROTECTED]
 
 	Make iterators in generic methods work; see gtest-191.cs.
Index: codegen.cs
===
--- codegen.cs	(revisión: 47987)
+++ codegen.cs	(copia de trabajo)
@@ -1186,6 +1186,45 @@
 			Report.Error (1548, Error during assembly signing.  + text);
 		}
 
+		void CheckAttributeValid (Attribute a)
+		{
+			if (a == null)
+throw new ArgumentNullException (a);
+
+			Type t = a.Type;
+			if (t.Equals (typeof (System.Runtime.CompilerServices.InternalsVisibleToAttribute))) {
+string [] args = a.GetString ().Trim ().Split (new char [] {','});
+
+bool is_name_valid = true;
+bool version = false, culture = false, key_token = false;
+for (int i = 1; i  args.Length; i++) {
+	string [] values = args [i].Split (new char [] {'='});
+	if (values.Length  2 || values [1] == String.Empty) {
+		is_name_valid = false;
+		break;
+	}
+
+	if (String.Compare (values [0], Version, true) == 0)
+		version = true;
+	else if (String.Compare (values [0], Culture, true) == 0)
+		culture = true;
+	else if (String.Compare (values [0], PublicKeyToken, true) == 0)
+		key_token = true;
+	// PublicKey is the only valid entry
+	else if (String.Compare (values [0], PublicKey, true) != 0) {
+		is_name_valid = false;
+		break;
+	}
+}
+
+// If the name is invalid, report CS1700
+if (!is_name_valid || args [0] == )
+	Report.Warning (1700, a.Location, Assembly reference ' + a.GetString () + ' is invalid and cannot be resolved);
+else if (culture || key_token || version)
+	throw new Exception (Friend assembly ' + a.GetString () + ' is invalid. InternalsVisibleTo cannot have version, culture or key token specified.);
+			}
+		}
+
 		public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
 		{
 			if (a.Type.IsSubclassOf (TypeManager.security_attr_type)  a.CheckSecurityActionValidity (true)) {
@@ -1196,6 +1235,7 @@
 return;
 			}
 
+			CheckAttributeValid (a);
 			Builder.SetCustomAttribute (customBuilder);
 		}
 
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-devel-list] Re: Mono-devel-list Digest, Vol 3, Issue 83

2005-07-29 Thread Carlos Alberto Cortez
I think you need the devel package for apache.

Carlos.

El vie, 29-07-2005 a las 09:12 +, Rajesh Kumar Aggani escribió:
 Hi Friends,
 
 I want to use Mono on Red Hat linux Server edition. I have installed Mono 
 with binary file. Apache is already installed during RedHat installation.
 
 I was trying to intall mod_mono module and I am getting the following error.
 
 checking for strrchr... yes
 checking for --with-apxs... no
 checking for --with-apr-config... not specified
 checking for apxs2 in /usr/local/apache/sbin... no
 checking for apxs in /usr/local/apache/sbin... no
 checking for apr-config in /usr/local/apache/sbin... no
 checking for apxs2 in /usr/local/apache2/bin... no
 checking for apxs in /usr/local/apache2/bin... no
 checking for apr-config in /usr/local/apache2/bin... no
 checking for apxs2 in /usr/sbin... no
 checking for apxs in /usr/sbin... no
 checking for apr-config in /usr/sbin... no
 checking for apxs2... no
 checking for apxs... no
 configure: error:  apxs was not found, DSO compilation will not be 
 available.
 
 Mono is installed in /opt/mono-1.1.8.3 folder.
 
 I got the mono module from 
 http://www.go-mono.com/archive/1.0.5/mod_mono-1.0.5.tar.gz 
 
 Please suggest me the next step.
 
 Thanks,
 Rajesh


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-devel-list] [PATCH] Assembly.GetReferencedAssemblies

2005-07-29 Thread Carlos Alberto Cortez
Hey,

The attached patch fixes the behavior for GetReferencedAssemblies (it
used to load the references and get the info from them, instead of
getting it from the metadata tables, just like MS impl).

It also fix a problem when calling this with a Reflection Only assembly.

The corlib nunit tests ran just fine (both for default and 2_0
profiles).

May I commit it?

Carlos.
Index: ChangeLog
===
--- ChangeLog	(revisión: 47832)
+++ ChangeLog	(copia de trabajo)
@@ -1,3 +1,11 @@
+2005-07-29  Carlos Alberto Cortez [EMAIL PROTECTED]
+
+	* icall.c (ves_icall_System_Reflection_GetReferencedAssemblies):
+	Fix the last behavior, which used to load the assemblies and
+	extract MonoReflectionAssemblyName information, instead of
+	extract it from the metadata tables. Needed for Reflection
+	Only assemblies.
+	
 2005-07-28  Zoltan Varga  [EMAIL PROTECTED]
 	
 	* reflection.c (mono_method_get_object): Fix warning.
Index: icall.c
===
--- icall.c	(revisión: 47832)
+++ icall.c	(copia de trabajo)
@@ -3622,12 +3622,11 @@
 }
 
 static MonoObject*
-create_version (MonoDomain *domain, MonoAssemblyName *aname)
+create_version (MonoDomain *domain, guint32 major, guint32 minor, guint32 build, guint32 revision)
 {
 	static MonoClass *System_Version = NULL;
 	static MonoMethod *create_version = NULL;
 	MonoObject *result;
-	int major, minor, build, revision;
 	gpointer args [4];
 	
 	if (!System_Version) {
@@ -3642,10 +3641,6 @@
 		mono_method_desc_free (desc);
 	}
 
-	major = aname-major;
-	minor = aname-minor;
-	build = aname-build;
-	revision = aname-revision;
 	args [0] = major;
 	args [1] = minor;
 	args [2] = build;
@@ -3664,6 +3659,7 @@
 	MonoDomain *domain = mono_object_domain (assembly);
 	int i, count = 0;
 	static MonoMethod *create_culture = NULL;
+	MonoImage *image = assembly-assembly-image;
 	MonoTableInfo *t;
 
 	MONO_ARCH_SAVE_REGS;
@@ -3686,52 +3682,46 @@
 	}
 
 	for (i = 0; i  count; i++) {
-		MonoAssembly *assem;
 		MonoReflectionAssemblyName *aname;
+		guint32 cols [MONO_ASSEMBLYREF_SIZE];
 
-		/* FIXME: There is no need to load the assemblies themselves */
-		mono_assembly_load_reference (assembly-assembly-image, i);
+		mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
 
-		assem = assembly-assembly-image-references [i];
-		if (assem == (gpointer)-1) {
-			char *msg = g_strdup_printf (Assembly %d referenced from assembly %s not found , i, assembly-assembly-image-name);
-			MonoException *ex = mono_get_exception_file_not_found2 (msg, NULL);
-			g_free (msg);
-			mono_raise_exception (ex);
-		}
-
 		aname = (MonoReflectionAssemblyName *) mono_object_new (
 			domain, System_Reflection_AssemblyName);
 
-		aname-name = mono_string_new (domain, assem-aname.name);
+		aname-name = mono_string_new (domain, mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_NAME]));
 
-		aname-major = assem-aname.major;
-		aname-minor = assem-aname.minor;
-		aname-build = assem-aname.build;
-		aname-revision = assem-aname.revision;
-		aname-hashalg = assem-aname.hash_alg;
-		aname-flags = assem-aname.flags;
+		aname-major = cols [MONO_ASSEMBLYREF_MAJOR_VERSION];
+		aname-minor = cols [MONO_ASSEMBLYREF_MINOR_VERSION];
+		aname-build = cols [MONO_ASSEMBLYREF_BUILD_NUMBER];
+		aname-revision = cols [MONO_ASSEMBLYREF_REV_NUMBER];
+		aname-flags = cols [MONO_ASSEMBLYREF_FLAGS];
 		aname-versioncompat = 1; /* SameMachine (default) */
-		aname-version = create_version (domain, assem-aname);
+		aname-hashalg = ASSEMBLY_HASH_SHA1; /* SHA1 (default) */
+		aname-version = create_version (domain, aname-major, aname-minor, aname-build, aname-revision);
 
 		if (create_culture) {
 			gpointer args [1];
-			args [0] = mono_string_new (domain, assem-aname.culture);
+			args [0] = mono_string_new (domain, mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_CULTURE]));
 			aname-cultureInfo = mono_runtime_invoke (create_culture, NULL, args, NULL);
 		}
+		
+		if (cols [MONO_ASSEMBLYREF_PUBLIC_KEY]) {
+			const gchar *pkey_ptr = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
+			guint32 pkey_len = mono_metadata_decode_blob_size (pkey_ptr, pkey_ptr);
 
-		if (assem-aname.public_key) {
-			guint32 pkey_len;
-			const char *pkey_ptr = (char*)assem-aname.public_key;
-			pkey_len = mono_metadata_decode_blob_size (pkey_ptr, pkey_ptr);
-
-			aname-publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
-			memcpy (mono_array_addr (aname-publicKey, guint8, 0), pkey_ptr, pkey_len);
+			if ((cols [MONO_ASSEMBLYREF_FLAGS]  ASSEMBLYREF_FULL_PUBLIC_KEY_FLAG)) {
+/* public key token isn't copied - the class library will 
+		   		automatically generate it from the public key if required */
+aname-publicKey = mono_array_new (domain, mono_defaults.byte_class, pkey_len);
+memcpy (mono_array_addr (aname-publicKey, guint8, 0), pkey_ptr, pkey_len);
+			} else {
+aname

[Mono-devel-list] [Patch] Publisher Policy support

2005-07-21 Thread Carlos Alberto Cortez
-name);
+	
+	if (aname-culture) {
+		culture = g_strdup (aname-culture);
+		g_strdown (culture);
+	}
+	else
+		culture = g_strdup ();
+	
+	pname = g_strdup_printf (policy.%d.%d.%s, aname-major, aname-minor, name);
+	version = g_strdup_printf (0.0.0.0_%s_%s, culture, aname-public_key_token);
+	g_free (name);
+	g_free (culture);
+	
+	filename = g_strconcat (pname, .dll, NULL);
+	subpath = g_build_path (G_DIR_SEPARATOR_S, pname, version, filename, NULL);
+	g_free (pname);
+	g_free (version);
+	g_free (filename);
+
+	image = NULL;
+	if (extra_gac_paths) {
+		paths = extra_gac_paths;
+		while (!image  *paths) {
+			fullpath = g_build_path (G_DIR_SEPARATOR_S, *paths,
+	lib, mono, gac, subpath, NULL);
+			image = mono_image_open (fullpath, NULL);
+			g_free (fullpath);
+			paths++;
+		}
+	}
+
+	if (image) {
+		g_free (subpath);
+		return image;
+	}
+
+	fullpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (), 
+			mono, gac, subpath, NULL);
+	image = mono_image_open (fullpath, NULL);
+	g_free (subpath);
+	g_free (fullpath);
+	
+	return image;
+}
+
+static MonoAssemblyName*
+mono_assembly_bind_version (AssemblyBindingInfo *info, MonoAssemblyName *aname, MonoAssemblyName *dest_name)
+{
+	memcpy (dest_name, aname, sizeof (MonoAssemblyName));
+	dest_name-major = info-new_version.major;
+	dest_name-minor = info-new_version.minor;
+	dest_name-build = info-new_version.build;
+	dest_name-revision = info-new_version.revision;
+	
+	return dest_name;
+}
+
+/* LOCKING: Assumes that the domain is already locked */
+static AssemblyBindingInfo*
+search_binding_loaded (MonoAssemblyName *aname)
+{
+	GSList *tmp;
+	MonoDomain *domain = mono_domain_get ();
+
+	for (tmp = domain-assembly_bindings; tmp; tmp = tmp-next) {
+		AssemblyBindingInfo *info = tmp-data;
+		if (assembly_binding_maps_name (info, aname))
+			return info;
+	}
+
+	return NULL;
+}
+
+static MonoAssemblyName*
+mono_assembly_apply_binding (MonoAssemblyName *aname, MonoAssemblyName *dest_name)
+{
+	AssemblyBindingInfo *info, *info2;
+	MonoDomain *domain = mono_domain_get ();
+	MonoImage *ppimage;
+	gboolean is_policy_valid;
+
+	if (aname-public_key_token [0] == 0)
+		return aname;
+
+	mono_domain_lock (domain);
+	info = search_binding_loaded (aname);
+	mono_domain_unlock (domain);
+	if (info) {
+		if (!check_policy_versions (info, aname))
+			return aname;
+		
+		mono_assembly_bind_version (info, aname, dest_name);
+		return dest_name;
+	}
+
+	info = g_new0 (AssemblyBindingInfo, 1);
+	ppimage = mono_assembly_load_publisher_policy (aname);
+	if (!ppimage)
+		is_policy_valid = FALSE;
+	else {
+		is_policy_valid = get_publisher_policy_info (ppimage, aname, info);
+		mono_image_close (ppimage);
+	}
+
+	/* Define default error value */
+	if (!is_policy_valid) {
+		info-name = g_strdup (aname-name);
+		info-culture = g_strdup (aname-culture);
+		info-major = aname-major;
+		info-minor = aname-minor;
+		info-new_version.major = info-new_version.minor = info-new_version.build = info-new_version.revision = -1;
+		info-old_version_bottom = info-new_version;
+		info-old_version_top = info-new_version;
+		g_strlcpy (info-public_key_token, aname-public_key_token, MONO_PUBLIC_KEY_TOKEN_LENGTH);
+	}
+	
+	mono_domain_lock (domain);
+	info2 = search_binding_loaded (aname);
+	if (info2) {
+		/* This binding was added by another thread 
+		 * before us */
+		assembly_binding_info_free (info);
+		g_free (info);
+		
+		info = info2;
+	} else
+		domain-assembly_bindings = g_slist_prepend (domain-assembly_bindings, info);
+		
+	mono_domain_unlock (domain);
+	
+	if (!is_policy_valid || !check_policy_versions (info, aname))
+		return aname;
+
+	mono_assembly_bind_version (info, aname, dest_name);
+	return dest_name;
+}
+
 /**
  * mono_assembly_load_from_gac
  *
@@ -1396,10 +1793,14 @@
 {
 	MonoAssembly *result;
 	char *fullpath, *filename;
-	MonoAssemblyName maped_aname;
+	MonoAssemblyName maped_aname, maped_name_pp;
 
 	aname = mono_assembly_remap_version (aname, maped_aname);
 	
+	/* Reflection only assemblies don't get assembly binding */
+	if (!refonly)
+		aname = mono_assembly_apply_binding (aname, maped_name_pp);
+	
 	result = mono_assembly_loaded_full (aname, refonly);
 	if (result)
 		return result;
Index: ChangeLog
===
--- ChangeLog	(revisión: 47493)
+++ ChangeLog	(copia de trabajo)
@@ -1,3 +1,44 @@
+2005-07-21  Carlos Alberto Cortez [EMAIL PROTECTED]
+
+	This patch implements a big portion of publisher policy
+	support, used to bind assembly versions and redirect
+	one assembly from version A to version B.
+
+	* assembly.c:
+	(assembly_binding_maps_name): New static function for checking if a 
+	assembly binding information maps an assembly name.
+	(assembly_binding_info_free): New function for freeing
+	assembly binding information resources.
+	(start_element): New static function used to parse publisher policy
+	config files.
+	(policy_parser): New static GMarkupParser containing the functions
+	used

[Mono-devel-list] [Patch] Include resource files in the GAC

2005-07-01 Thread Carlos Alberto Cortez
Hello,

Currently the linked resource files (not the normal resource, but the
ones that only are linked) are not copied to the GAC with the installed
assembly (MS Impl does it).

Maybe the only problem with the attached patch, is that the assembly is
copied while keeping it open (the assembly remains in the domain after
loading it with Assembly.LoadFrom). However, since we are only reading
it, I think it does not represent a problem.

Any comments/suggestions?

Carlos.
Index: driver.cs
===
--- driver.cs	(revisión: 46867)
+++ driver.cs	(copia de trabajo)
@@ -193,28 +193,45 @@
 string gacdir, string link_gacdir, string libdir, string link_libdir)
 		{
 			string failure_msg = Failure adding assembly to the cache: ;
+			ArrayList resources;
 
 			if (!File.Exists (name)) {
 WriteLine (failure_msg + The system cannot find the file specified.);
 Environment.Exit (1);
 			}
 
+			Assembly assembly = null;
 			AssemblyName an = null;
 			byte [] pub_tok;
 
 			try {
-an = AssemblyName.GetAssemblyName (name);
+assembly = Assembly.LoadFrom (name);
 			} catch {
 WriteLine (failure_msg + The file specified is not a valid assembly.);
 return false;
 			}
 
+			an = assembly.GetName ();
 			pub_tok = an.GetPublicKeyToken ();
 			if (pub_tok == null || pub_tok.Length == 0) {
 WriteLine (failure_msg + Attempt to install an assembly without a strong name.);
 return false;
 			}
 
+			resources = new ArrayList ();
+			foreach (string res_name in assembly.GetManifestResourceNames ()) {
+ManifestResourceInfo res_info = assembly.GetManifestResourceInfo (res_name);
+
+if ((res_info.ResourceLocation  ResourceLocation.Embedded) == 0) {
+	if (!File.Exists (res_info.FileName)) {
+		WriteLine (failure_msg + The system cannot find resource  + res_info.FileName);
+		return false;
+	}
+
+	resources.Add (res_info);
+}
+			}
+
 			if (check_refs  !CheckReferencedAssemblies (an)) {
 WriteLine (failure_msg + Attempt to install an assembly that references non  +
 		strong named assemblies with -check_refs enabled.);
@@ -250,6 +267,15 @@
 	File.Copy (sibling, String.Concat (asmb_path, ext), true);
 			}
 
+			foreach (ManifestResourceInfo resource_info in resources) {
+try {
+	File.Copy (resource_info.FileName, Path.Combine (full_path, Path.GetFileName (resource_info.FileName)), true);
+} catch {
+	WriteLine (ERROR: Could not install resource file  + resource_info.FileName);
+	Environment.Exit (1);
+}
+			}
+
 			if (package != null) {
 string ref_dir = Path.Combine (libdir, package);
 string ref_path = Path.Combine (ref_dir, asmb_file);
Index: ChangeLog
===
--- ChangeLog	(revisión: 46867)
+++ ChangeLog	(copia de trabajo)
@@ -1,3 +1,8 @@
+2005-07-01  Carlos Alberto Cortez [EMAIL PROTECTED]
+
+	* driver.cs (Install): Copy the linked resource files
+	for the assembly when installing it.
+	
 2005-05-20  Ben Maurer  [EMAIL PROTECTED]
 
 	* driver.cs (Main): If the switch argument isn't actually a
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-devel-list] [Patch] Images loaded with Reflection Only Assemblies

2005-06-09 Thread Carlos Alberto Cortez
Hey,

Currently, when loading a reflection only assembly, and then a normal
assembly is also loaded, they share their images, which of course is not
correct.

With the attached patch separated images are loaded.

Carlos.
Index: appdomain.c
===
--- appdomain.c	(revisin: 45717)
+++ appdomain.c	(copia de trabajo)
@@ -907,7 +907,7 @@
 	MonoDomain *domain = ad-data;
 	MonoImageOpenStatus status;
 	guint32 raw_assembly_len = mono_array_length (raw_assembly);
-	MonoImage *image = mono_image_open_from_data (mono_array_addr (raw_assembly, gchar, 0), raw_assembly_len, TRUE, NULL);
+	MonoImage *image = mono_image_open_from_data_full (mono_array_addr (raw_assembly, gchar, 0), raw_assembly_len, TRUE, NULL, refonly);
 
 	if (raw_symbol_store)
 		mono_raise_exception (mono_get_exception_not_implemented (LoadAssemblyRaw: Raw Symbol Store not Implemented));
Index: assembly.c
===
--- assembly.c	(revisin: 45717)
+++ assembly.c	(copia de trabajo)
@@ -787,7 +787,7 @@
  * returns NULL
  */
 static MonoImage *
-mono_assembly_open_from_bundle (const char *filename, MonoImageOpenStatus *status)
+mono_assembly_open_from_bundle (const char *filename, MonoImageOpenStatus *status, gboolean refonly)
 {
 	int i;
 	char *name = g_path_get_basename (filename);
@@ -800,7 +800,7 @@
 	EnterCriticalSection (assemblies_mutex);
 	for (i = 0; !image  bundles [i]; ++i) {
 		if (strcmp (bundles [i]-name, name) == 0) {
-			image = mono_image_open_from_data ((char*)bundles [i]-data, bundles [i]-size, FALSE, status);
+			image = mono_image_open_from_data_full ((char*)bundles [i]-data, bundles [i]-size, FALSE, status, refonly);
 			break;
 		}
 	}
@@ -814,18 +814,18 @@
 }
 
 static MonoImage*
-do_mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
+do_mono_assembly_open (const char *filename, MonoImageOpenStatus *status, gboolean refonly)
 {
 	MonoImage *image = NULL;
 
 	if (bundles != NULL){
-		image = mono_assembly_open_from_bundle (filename, status);
+		image = mono_assembly_open_from_bundle (filename, status, refonly);
 
 		if (image != NULL)
 			return image;
 	}
 	EnterCriticalSection (assemblies_mutex);
-	image = mono_image_open (filename, status);
+	image = mono_image_open_full (filename, status, refonly);
 	LeaveCriticalSection (assemblies_mutex);
 
 	return image;
@@ -876,7 +876,7 @@
 
 	mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY,
 			Assembly Loader probing location: '%s'., filename);
-	image = do_mono_assembly_open (fname, status);
+	image = do_mono_assembly_open (fname, status, refonly);
 
 	if (!image){
 		*status = MONO_IMAGE_ERROR_ERRNO;
Index: image.c
===
--- image.c	(revisin: 45717)
+++ image.c	(copia de trabajo)
@@ -34,6 +34,8 @@
  */
 static GHashTable *loaded_images_hash;
 static GHashTable *loaded_images_guid_hash;
+static GHashTable *loaded_images_refonly_hash;
+static GHashTable *loaded_images_refonly_guid_hash;
 
 static CRITICAL_SECTION images_mutex;
 
@@ -131,6 +133,8 @@
 
 	loaded_images_hash = g_hash_table_new (g_str_hash, g_str_equal);
 	loaded_images_guid_hash = g_hash_table_new (g_str_hash, g_str_equal);
+	loaded_images_refonly_hash = g_hash_table_new (g_str_hash, g_str_equal);
+	loaded_images_refonly_guid_hash = g_hash_table_new (g_str_hash, g_str_equal);
 }
 
 /**
@@ -466,7 +470,7 @@
 		mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
 		name = mono_metadata_string_heap (image, cols [MONO_MODULEREF_NAME]);
 		module_ref = g_build_filename (base_dir, name, NULL);
-		image-modules [i] = mono_image_open (module_ref, status);
+		image-modules [i] = mono_image_open_full (module_ref, status, refonly, image-refonly);
 		if (image-modules [i]) {
 			/* g_print (loaded module %s from %s (%p)\n, module_ref, image-name, image-assembly); */
 		}
@@ -551,11 +555,21 @@
 }
 
 static void
-build_guid_table (void)
+register_guid_refonly (gpointer key, gpointer value, gpointer user_data)
 {
-	g_hash_table_foreach (loaded_images_hash, register_guid, NULL);
+	MonoImage *image = (MonoImage*)value;
+
+	if (!g_hash_table_lookup (loaded_images_refonly_guid_hash, image))
+		g_hash_table_insert (loaded_images_refonly_guid_hash, image-guid, image);
 }
 
+static void
+build_guid_table (gboolean refonly)
+{
+	GHashTable *loaded_images = refonly ? loaded_images_refonly_hash : loaded_images_hash;
+	g_hash_table_foreach (loaded_images, refonly ? register_guid_refonly : register_guid, NULL);
+}
+
 void
 mono_image_init (MonoImage *image)
 {
@@ -761,7 +775,7 @@
 
 static MonoImage *
 do_mono_image_open (const char *fname, MonoImageOpenStatus *status,
-		gboolean care_about_cli)
+		gboolean care_about_cli, gboolean refonly)
 {
 	MonoCLIImageInfo *iinfo;
 	MonoImage *image;
@@ -788,39 +802,56 @@
 	iinfo = g_new0 (MonoCLIImageInfo, 1);
 	image-image_info = iinfo;
 	image-name = canonicalize_path (fname);
+	

[Mono-devel-list] [Patch] Define Version for AssemblyBuilder

2005-06-07 Thread Carlos Alberto Cortez
Hi,

Currently when an AssemblyBuilder is created, and then its AssemblyName
is retrieved, the Version is always returned as 0.0.0.0, even when it -
the Version- was defined.

The attached patch defines it, and also minor changes to the tests are
attached.

Carlos.
Index: reflection.c
===
--- reflection.c	(revisin: 45600)
+++ reflection.c	(copia de trabajo)
@@ -4334,6 +4334,22 @@
 	else
 		assembly-assembly.aname.culture = g_strdup ();
 
+if (assemblyb-version) {
+char **version = g_strsplit (mono_string_to_utf8 (assemblyb-version), ., 4);
+char **parts = version;
+assembly-assembly.aname.major = atoi (*parts++);
+assembly-assembly.aname.minor = atoi (*parts++);
+assembly-assembly.aname.build = *parts != NULL ? atoi (*parts++) : 0;
+assembly-assembly.aname.revision = *parts != NULL ? atoi (*parts) : 0;
+
+g_strfreev (version);
+} else {
+assembly-assembly.aname.major = 0;
+assembly-assembly.aname.minor = 0;
+assembly-assembly.aname.build = 0;
+assembly-assembly.aname.revision = 0;
+}
+
 	assembly-run = assemblyb-access != 2;
 	assembly-save = assemblyb-access != 1;
 
Index: ChangeLog
===
--- ChangeLog	(revisin: 45600)
+++ ChangeLog	(copia de trabajo)
@@ -1,4 +1,8 @@
+2005-06-07  Carlos Alberto Cortez [EMAIL PROTECTED]
 
+	* reflection.c (mono_image_basic_init): Define
+	Version in MonoDynamicAssembly. 
+
 2005-06-06  Michael Meeks  [EMAIL PROTECTED]
 
 	* object.c (extend_interface_array): fix really silly
Index: AssemblyNameTest.cs
===
--- AssemblyNameTest.cs	(revisin: 45568)
+++ AssemblyNameTest.cs	(copia de trabajo)
@@ -283,6 +283,15 @@
 		return Assembly.LoadFrom (Path.Combine (tempDir, name.Name + .dll));
 	}
 
+	private AssemblyBuilder GenerateDynamicAssembly (AssemblyName name)
+	{
+		AssemblyBuilder ab = domain.DefineDynamicAssembly (
+name,
+AssemblyBuilderAccess.Run);
+
+		return ab;
+	}
+
 	[Test]
 	public void TestCultureInfo ()
 	{
@@ -302,17 +311,26 @@
 		Assembly a = GenerateAssembly (name);
 		Assert.AreEqual (1.2.3.4, a.GetName ().Version.ToString ());
 
+		AssemblyBuilder ab = GenerateDynamicAssembly (name);
+		Assert.AreEqual (1.2.3.4, ab.GetName ().Version.ToString ());
+
 		name = GenAssemblyName ();
 		name.Version = new Version (1, 2, 3);
 
 		a = GenerateAssembly (name);
 		Assert.AreEqual (1.2.3.0, a.GetName ().Version.ToString ());
 
+		ab = GenerateDynamicAssembly (name);
+		Assert.AreEqual (1.2.3.0, ab.GetName ().Version.ToString ());
+
 		name = GenAssemblyName ();
 		name.Version = new Version (1, 2);
 
 		a = GenerateAssembly (name);
 		Assert.AreEqual (1.2.0.0, a.GetName ().Version.ToString ());
+
+		ab = GenerateDynamicAssembly (name);
+		Assert.AreEqual (1.2.0.0, ab.GetName ().Version.ToString ());
 	}
 
 	[Test]
Index: ChangeLog
===
--- ChangeLog	(revisin: 45568)
+++ ChangeLog	(copia de trabajo)
@@ -1,3 +1,9 @@
+2005-06-07  Carlos Alberto Cortez [EMAIL PROTECTED]
+
+	* AssemblyNameTest.cs: Added tests to Version method,
+	in order to do additional checks with AssemblyBuilder
+	version.
+	
 2005-06-07 Gonzalo Paniagua Javier [EMAIL PROTECTED]
 
 	* AssemblyTest.cs: put back GetEntryAssembly, but this one is working.
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-devel-list] Re: [Mono-patches] r45553 - trunk/mcs/class/corlib/System.Reflection

2005-06-06 Thread Carlos Alberto Cortez
Hey Martin,

thanks for the info.

I will try to commit this patch when the problem is fixed.

Carlos.

El mar, 07-06-2005 a las 05:37 +0200, Martin Baulig escribi:
 Hi,
 
 please do not commit such patches to corlib without first testing them.
 
 There is an open bug report (#75136) about this issue, but we can't just
 keep the build broken until that's fixed.
 
 Thanks,
 Martin
 
 On Mon, 2005-06-06 at 20:14 -0400, Carlos Alberto Cortes  wrote:
  Author: calberto
  Date: 2005-06-06 20:14:13 -0400 (Mon, 06 Jun 2005)
  New Revision: 45553
  
  Modified:
 trunk/mcs/class/corlib/System.Reflection/ChangeLog
 trunk/mcs/class/corlib/System.Reflection/CustomAttributeData.cs
 trunk/mcs/class/corlib/System.Reflection/CustomAttributeNamedArgument.cs
 trunk/mcs/class/corlib/System.Reflection/CustomAttributeTypedArgument.cs
  Log:
  2005-06-07  Carlos Alberto Cortez [EMAIL PROTECTED]
  
  * CustomAttributeData.cs: Implemented.
  
  * CustomAttributeDataNamedArgument.cs: Implemented.
  
  * CustomAttrbuteDataTypedArgument.cs: Implemented.
  
  
  
  Modified: trunk/mcs/class/corlib/System.Reflection/ChangeLog
  ===
  --- trunk/mcs/class/corlib/System.Reflection/ChangeLog  2005-06-07 
  00:12:21 UTC (rev 45552)
  +++ trunk/mcs/class/corlib/System.Reflection/ChangeLog  2005-06-07 
  00:14:13 UTC (rev 45553)
  @@ -1,3 +1,11 @@
  +2005-06-07  Carlos Alberto Cortez [EMAIL PROTECTED]
  +
  +   * CustomAttributeData.cs: Implemented.
  +
  +   * CustomAttributeDataNamedArgument.cs: Implemented.
  +
  +   * CustomAttrbuteDataTypedArgument.cs: Implemented.
  +   
   2005-06-06  Zoltan Varga  [EMAIL PROTECTED]
   
  * Assembly.cs ExceptionHandlingClause.cs: Fix build.
  
  Modified: trunk/mcs/class/corlib/System.Reflection/CustomAttributeData.cs
  ===
  --- trunk/mcs/class/corlib/System.Reflection/CustomAttributeData.cs 
  2005-06-07 00:12:21 UTC (rev 45552)
  +++ trunk/mcs/class/corlib/System.Reflection/CustomAttributeData.cs 
  2005-06-07 00:14:13 UTC (rev 45553)
  @@ -3,6 +3,7 @@
   //
   // Author:
   //   Zoltan Varga ([EMAIL PROTECTED])
  +//   Carlos Alberto Cortez ([EMAIL PROTECTED])
   //
   // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
   //
  @@ -32,6 +33,7 @@
   using System.Collections.Generic;
   using System.Runtime.CompilerServices;
   using System.Runtime.InteropServices;
  +using System.Text;
   
   namespace System.Reflection {
   
  @@ -39,47 +41,87 @@
  [ComVisible (true)]
   #endif
  public sealed class CustomAttributeData {
  +   ConstructorInfo ctorInfo;
  +   IListCustomAttributeTypedArgument ctorArgs;
  +   IListCustomAttributeNamedArgument namedArgs;
   
  -   [MonoTODO]
  +   internal CustomAttributeData (ConstructorInfo ctorInfo, object 
  [] ctorArgs, object [] namedArgs)
  +   {
  +   this.ctorInfo = ctorInfo;
  +   
  +   this.ctorArgs = 
  Array.AsReadOnlyCustomAttributeTypedArgument 
  +   (ctorArgs != null ? 
  UnboxValuesCustomAttributeTypedArgument (ctorArgs) : new 
  CustomAttributeTypedArgument [0]);
  +   
  +   this.namedArgs = 
  Array.AsReadOnlyCustomAttributeNamedArgument 
  +   (namedArgs != null ? 
  UnboxValuesCustomAttributeNamedArgument (namedArgs) : new 
  CustomAttributeNamedArgument [0]);
  +   }
  +
  public ConstructorInfo Constructor {
  get {
  -   throw new NotImplementedException ();
  +   return ctorInfo;
  }
  }
   
  -   [MonoTODO]
  public IListCustomAttributeTypedArgument ConstructorArguments 
  {
  get {
  -   throw new NotImplementedException ();
  +   return ctorArgs;
  }
  }
   
  -   [MonoTODO]
  public IListCustomAttributeNamedArgument NamedArguments {
  get {
  -   throw new NotImplementedException ();
  +   return namedArgs;
  }
  }
   
  -   [MonoTODO]
  -   public static IListCustomAttributeData GetCustomAttributes 
  (Assembly yarget) {
  -   throw new NotImplementedException ();
  +   public static IListCustomAttributeData GetCustomAttributes 
  (Assembly target) {
  +   return MonoCustomAttrs.GetCustomAttributesData (target);
  }
   
  -   [MonoTODO]
  public static IListCustomAttributeData GetCustomAttributes 
  (MemberInfo target) {
  -   throw new NotImplementedException ();
  +   return

Re: [Mono-devel-list] [Patch] AssemblyName changes

2005-05-19 Thread Carlos Alberto Cortez
Hey,


 Does this fix
 
 http://bugzilla.ximian.com/show_bug.cgi?id=59891
 
 -- Ben
 

It is not exactly a patch for that error (I'm not getting that error,
however), but to correct the problem of always having something like:

AssemblyName aname = new AssemblyName ();
aname.Name = Something;

and getting in Mono with FullName:

Something, Version=0.0.0.0

but with .Net

Something

By the way, I've rebuilt my tree, and no problems appear.

Can I commit?

Carlos.

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-devel-list] [Patch] AssemblyName changes

2005-05-18 Thread Carlos Alberto Cortez
Hey there,

I made some changes to at icall.c and AssemblyName.cs to correct some
incorrect behavior of AssemblyName class. With these changes, all the
tests at AssemblyNameTest.cs run ok, and I even could make a bootstrap.

Any comment?

Carlos.
Index: icall.c
===
--- icall.c	(revisin: 44715)
+++ icall.c	(copia de trabajo)
@@ -3477,11 +3477,14 @@
 ves_icall_System_Reflection_Assembly_GetReferencedAssemblies (MonoReflectionAssembly *assembly) 
 {
 	static MonoClass *System_Reflection_AssemblyName;
+	static MonoClass *System_Version;
 	MonoArray *result;
 	MonoDomain *domain = mono_object_domain (assembly);
 	int i, count = 0;
 	static MonoMethod *create_culture = NULL;
+	static MonoMethod *create_version = NULL;
 	MonoTableInfo *t;
+	gpointer args [4];
 
 	MONO_ARCH_SAVE_REGS;
 
@@ -3489,6 +3492,12 @@
 		System_Reflection_AssemblyName = mono_class_from_name (
 			mono_defaults.corlib, System.Reflection, AssemblyName);
 
+	if (!System_Version) {
+		System_Version = mono_class_from_name (
+mono_defaults.corlib, System, Version);
+		g_assert (System_Version);
+	}
+
 	t = assembly-assembly-image-tables [MONO_TABLE_ASSEMBLYREF];
 	count = t-rows;
 
@@ -3502,6 +3511,13 @@
 		mono_method_desc_free (desc);
 	}
 
+	if (count  0  !create_version) {
+		MonoMethodDesc *desc = mono_method_desc_new (:.ctor(int,int,int,int), FALSE);
+		create_version = mono_method_desc_search_in_class (desc, System_Version);
+		g_assert (create_version);
+		mono_method_desc_free (desc);
+	}
+
 	for (i = 0; i  count; i++) {
 		MonoAssembly *assem;
 		MonoReflectionAssemblyName *aname;
@@ -3530,6 +3546,13 @@
 		aname-flags = assem-aname.flags;
 		aname-versioncompat = 1; /* SameMachine (default) */
 
+		args [0] = assem-aname.major;
+		args [1] = assem-aname.minor;
+		args [2] = assem-aname.build;
+		args [3] = assem-aname.revision;
+		aname-version = mono_object_new (domain, System_Version);
+		mono_runtime_invoke (create_version, aname-version, args, NULL);
+
 		if (create_culture) {
 			gpointer args [1];
 			args [0] = mono_string_new (domain, assem-aname.culture);
@@ -3929,8 +3952,11 @@
 static void
 fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *aname, MonoAssemblyName *name, const char *absolute)
 {
+	static MonoClass *System_Version = NULL;
 	static MonoMethod *create_culture = NULL;
+	static MonoMethod *create_version = NULL;
 	gpointer args [1];
+	gpointer vargs [4];
 	guint32 pkey_len;
 	const char *pkey_ptr;
 	gchar *codebase;
@@ -3944,6 +3970,25 @@
 	aname-revision = name-revision;
 	aname-hashalg = name-hash_alg;
 
+	if (!System_Version) {
+		System_Version = mono_class_from_name (mono_defaults.corlib, System, Version);
+		g_assert (System_Version);
+	}
+	
+	if (!create_version) {
+		MonoMethodDesc *desc = mono_method_desc_new (:.ctor(int,int,int,int), FALSE);
+		create_version = mono_method_desc_search_in_class (desc, System_Version);
+		g_assert (create_version);
+		mono_method_desc_free (desc);
+	}
+
+	vargs [0] = aname-major;
+	vargs [1] = aname-minor;
+	vargs [2] = aname-build;
+	vargs [3] = aname-revision;
+	aname-version = mono_object_new (domain, System_Version);
+	mono_runtime_invoke (create_version, aname-version, vargs, NULL);
+	
 	codebase = g_filename_to_uri (absolute, NULL, NULL);
 	if (codebase) {
 		aname-codebase = mono_string_new (domain, codebase);
Index: AssemblyName.cs
===
--- AssemblyName.cs	(revisin: 44717)
+++ AssemblyName.cs	(copia de trabajo)
@@ -123,7 +123,7 @@
 	return null;
 StringBuilder fname = new StringBuilder ();
 fname.Append (name);
-if (Version.ToString () != 0.0.0.0) {
+if (Version != null) {
 	fname.Append (, Version=);
 	fname.Append (Version.ToString ());
 }
@@ -160,27 +160,19 @@
 
 		public Version Version {
 			get {
-if (version != null) return version;
-
-if (name == null)
-	return null;
-if (build == -1)
-	version = new Version (major, minor);
-else
-	if (revision == -1)
-		version = new Version (major, minor, build);
-else
-	version = new Version (major, minor, build, revision);
-
 return version;
 			}
 
 			set {
-major = value.Major;
-minor = value.Minor;
-build = value.Build;
-revision = value.Revision;
 version = value;
+if (value == null)
+	major = minor = build = revision = 0;
+else {
+	major = value.Major;
+	minor = value.Minor;
+	build = value.Build;
+	revision = value.Revision;
+}
 			}
 		}
 
@@ -272,6 +264,7 @@
 			an.minor = minor;
 			an.build = build;
 			an.revision = revision;
+			an.version = version != null ? (Version) version.Clone () : null;
 			an.cultureinfo = cultureinfo;
 			an.flags = flags;
 			an.hashalg = hashalg;
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com

Re: [Mono-devel-list] [Patch] AssemblyName changes

2005-05-18 Thread Carlos Alberto Cortez
Hey, 

I noticed this too, but in the MS impl, a new Version instance is
created. We could however, use the same.

Carlos.

El mi, 18-05-2005 a las 18:25 -0400, Ben Maurer escribi:
 On Wed, 2005-05-18 at 17:25 -0500, Carlos Alberto Cortez wrote:
  Hey there,
  
  I made some changes to at icall.c and AssemblyName.cs to correct some
  incorrect behavior of AssemblyName class. With these changes, all the
  tests at AssemblyNameTest.cs run ok, and I even could make a bootstrap.
  
  Any comment?
 
 
 
  +  an.version = version != null ? (Version) version.Clone () : null;
 
 version is a readonly class (modifications can not be made to an
 existing Version. So the clone thing is totally unneeded.
 
 Does this fix
 
 http://bugzilla.ximian.com/show_bug.cgi?id=59891
 
 -- Ben
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-devel-list] [Path] AssemblyName changes

2005-04-21 Thread Carlos Alberto Cortez
Hey,

Attached is a patch with changes for AssemblyName, to behave like
the .Net impl.

I still don't know which was the intention of that code in Version
property, anyway.

Any comments?

Carlos.
Index: AssemblyName.cs
===
--- AssemblyName.cs	(revisin: 43348)
+++ AssemblyName.cs	(copia de trabajo)
@@ -123,7 +123,7 @@
 	return null;
 StringBuilder fname = new StringBuilder ();
 fname.Append (name);
-if (Version.ToString () != 0.0.0.0) {
+if (Version != null) {
 	fname.Append (, Version=);
 	fname.Append (Version.ToString ());
 }
@@ -160,18 +160,6 @@
 
 		public Version Version {
 			get {
-if (version != null) return version;
-
-if (name == null)
-	return null;
-if (build == -1)
-	version = new Version (major, minor);
-else
-	if (revision == -1)
-		version = new Version (major, minor, build);
-else
-	version = new Version (major, minor, build, revision);
-
 return version;
 			}
 
@@ -192,7 +180,11 @@
 		public override string ToString ()
 		{
 			string name = FullName;
+#if NET_2_0
+			return name;
+#else
 			return (name != null) ? name : base.ToString ();
+#endif
 		}
 
 		public byte[] GetPublicKey() 


[Mono-devel-list] [Patch] CustomAttributeData support

2005-04-19 Thread Carlos Alberto Cortez
 GetCustomAttributes (obj, null, inherit);
 		}
 
+#if NET_2_0
+		[MethodImplAttribute (MethodImplOptions.InternalCall)]
+		static extern CustomAttributeData [] GetCustomAttributesDataInternal (ICustomAttributeProvider obj);
+
+		internal static IListCustomAttributeData GetCustomAttributesData (ICustomAttributeProvider obj)
+		{
+			if (obj == null)
+throw new ArgumentNullException (obj);
+
+			CustomAttributeData [] attrs = GetCustomAttributesDataInternal (obj);
+			return Array.AsReadOnlyCustomAttributeData (attrs);
+		}
+#endif
+
 		internal static bool IsDefined (ICustomAttributeProvider obj, Type attributeType, bool inherit)
 		{
 			object [] res = GetCustomAttributesBase (obj);
Index: CustomAttributeData.cs
===
--- CustomAttributeData.cs	(revisin: 43304)
+++ CustomAttributeData.cs	(copia de trabajo)
@@ -3,6 +3,7 @@
 //
 // Author:
 //   Zoltan Varga ([EMAIL PROTECTED])
+//   Carlos Alberto Cortez ([EMAIL PROTECTED])
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
@@ -32,57 +33,98 @@
 using System.Collections.Generic;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
+using System.Text;
 
 namespace System.Reflection {
 
 	public sealed class CustomAttributeData {
+		ConstructorInfo ctorInfo;
+		IListCustomAttributeTypedArgument ctorArgs;
+		IListCustomAttributeNamedArgument namedArgs;
 
-		[MonoTODO]
+		internal CustomAttributeData (ConstructorInfo ctorInfo, object [] ctorArgs, object [] namedArgs)
+		{
+			this.ctorInfo = ctorInfo;
+			
+			this.ctorArgs = Array.AsReadOnlyCustomAttributeTypedArgument 
+(ctorArgs != null ? UnboxValuesCustomAttributeTypedArgument (ctorArgs) : new CustomAttributeTypedArgument [0]);
+			
+			this.namedArgs = Array.AsReadOnlyCustomAttributeNamedArgument 
+(namedArgs != null ? UnboxValuesCustomAttributeNamedArgument (namedArgs) : new CustomAttributeNamedArgument [0]);
+		}
+
 		public ConstructorInfo Constructor {
 			get {
-throw new NotImplementedException ();
+return ctorInfo;
 			}
 		}
 
-		[MonoTODO]
 		[CLSCompliant (false)]
 		public IListCustomAttributeTypedArgument ConstructorArguments {
 			get {
-throw new NotImplementedException ();
+return ctorArgs;
 			}
 		}
 
-		[MonoTODO]
 		[CLSCompliant (false)]
 		public IListCustomAttributeNamedArgument NamedArguments {
 			get {
-throw new NotImplementedException ();
+return namedArgs;
 			}
 		}
 
-		[MonoTODO]
 		[CLSCompliant (false)]
-		public static IListCustomAttributeData GetCustomAttributes (Assembly yarget) {
-			throw new NotImplementedException ();
+		public static IListCustomAttributeData GetCustomAttributes (Assembly target) {
+			return MonoCustomAttrs.GetCustomAttributesData (target);
 		}
 
-		[MonoTODO]
 		[CLSCompliant (false)]
 		public static IListCustomAttributeData GetCustomAttributes (MemberInfo target) {
-			throw new NotImplementedException ();
+			return MonoCustomAttrs.GetCustomAttributesData (target);
 		}
 
-		[MonoTODO]
 		[CLSCompliant (false)]
 		public static IListCustomAttributeData GetCustomAttributes (Module target) {
-			throw new NotImplementedException ();
+			return MonoCustomAttrs.GetCustomAttributesData (target);
 		}
 
-		[MonoTODO]
 		[CLSCompliant (false)]
 		public static IListCustomAttributeData GetCustomAttributes (ParameterInfo target) {
-			throw new NotImplementedException ();
+			return MonoCustomAttrs.GetCustomAttributesData (target);
 		}
+
+		public override string ToString ()
+		{
+			StringBuilder sb = new StringBuilder ();
+
+			sb.Append ([ + ctorInfo.DeclaringType.Name +  ();
+			for (int i = 0; i  ctorArgs.Count; i++) {
+sb.Append (ctorArgs [i].ToString ());
+if (i + 1  ctorArgs.Count)
+	sb.Append (, );
+			}
+
+			if (namedArgs.Count  0)
+sb.Append (, );
+			
+			for (int j = 0; j  namedArgs.Count; j++) {
+sb.Append (namedArgs [j].ToString ());
+if (j + 1  namedArgs.Count)
+	sb.Append (, );
+			}
+			sb.AppendFormat ()]);
+
+			return sb.ToString ();
+		}
+
+		static T [] UnboxValuesT (object [] values)
+		{
+			T [] retval = new T [values.Length];
+			for (int i = 0; i  values.Length; i++)
+retval [i] = (T) values [i];
+
+			return retval;
+		}
 	}
 
 }
Index: CustomAttributeTypedArgument.cs
===
--- CustomAttributeTypedArgument.cs	(revisin: 43304)
+++ CustomAttributeTypedArgument.cs	(copia de trabajo)
@@ -3,6 +3,7 @@
 //
 // Author:
 //   Zoltan Varga ([EMAIL PROTECTED])
+//   Carlos Alberto Cortez ([EMAIL PROTECTED])
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
@@ -33,20 +34,37 @@
 namespace System.Reflection {
 
 	public struct CustomAttributeTypedArgument {
+		Type argumentType;
+		object value;
 
-		[MonoTODO]
+		internal CustomAttributeTypedArgument (Type argumentType, object value)
+		{
+			this.argumentType = argumentType;
+			this.value = value;
+		}
+
 		public Type ArgumentType {
 			get

Re: [Mono-devel-list] Problems with Array.AsReadOnly

2005-04-14 Thread Carlos Alberto Cortez
It's working now smoothly :-)

Carlos.

 Hi Carlos,
 
 I think this is already fixed. I'm running your sample from svn of
 2005-04-13 23:55, localtime GMT-3 and I get the expected result: 10
 
 Please, update your svn and give it a try.
 
 Thanks for reporting.
 
 
 - --
 Regards,
 
 Francisco Figueiredo Jr.
 Npgsql Lead Developer
 http://gborg.postgresql.org/project/npgsql
 MonoBrasil Project Founder Member
 http://monobrasil.softwarelivre.org
 
 
 - -
 Science without religion is lame;
 religion without science is blind.
 
   ~ Albert Einstein
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.2.6 (GNU/Linux)
 Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
 
 iQEVAwUBQl3fHf7iFmsNzeXfAQI1pgf/QmdAna8YNHC5Z4JjBOjjscQa/iqkVnnx
 1hTNZoxvNEaAyUU0T9l2AmWtrzcIfBay4pACpQ/PYPvQS8t0rVZQUsZVQCF/K4US
 2hl4xyAK72znxvgXxf/t6fDMqhNuxY9y4ItjxZyXzhDkGSxhekUcphpa53YKWqHu
 T74YRF/ntZkWMBPmj6RHCMHyezMyYBR0iYfToc3j3SMVZeUt40vGfcBVtVNPER4y
 +77ntCn5LGwTPyMDRN5msOOlioYIAbyeuLiX4mKNP47qvtQUBOsQLGvlwqSboOM5
 kVtfhSZZ7/GTr4S7pXPbhJOaAW4fXqjht6W2IdAxZj9CyYv31Br0rg==
 =TKr7
 -END PGP SIGNATURE-
 
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[Mono-devel-list] Problems with Array.AsReadOnly

2005-04-13 Thread Carlos Alberto Cortez
Hello,

With mono from svn (updated a day ago) I'm getting a NullReferenceError
when trying to use a IList returned by Array.AsReadOnlyT. 

I've tried to see what happend, and ReadOnlyArray (internal
representation) is working well, so I can only think that something is
working bad in the runtime.

Attached is a sample.

Carlos.

using System;
using System.Collections.Generic;

 public class Test {

	 public static void Main ()
	 {
		 int [] data = new int [10];
		 IListint ro = Array.AsReadOnlyint (data);
		 Console.WriteLine (ro.Count);
	 }

 }



  1   2   >