[Mono-list] Problem with while loop and Main returning void

Leigh Dyer leigh@eclinic.com.au
03 Jul 2002 16:29:49 +1000


--=-wfTJi1Q9oMj8wBzrMAPi
Content-Type: multipart/mixed; boundary="=-ewr73hCBkCnG79+lyYC2"


--=-ewr73hCBkCnG79+lyYC2
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Hey guys,

I think I've found a minor bug in either mcs or the runtime. I was
writing a small app that has just has a Main() and a small while(true)
loop, with a break condition inside it. However, when I compiled my app
with mcs and ran it with mono, after breaking out of the while(true)
loop my program kept running - it seems to just keep re-running Main().
Running with mint exits at the end of the first run, but with a
"Trace/breakpoint trap" message.

However, if I change my Main() so that it returns int instead of void,
and add a "return 0;" to the end, everything works as expected.

I tried to isolate the problem with a small test case, and while it
doesn't exhibit exactly the same behaviour, it still doesn't work as
expected with Main() returning void - mint segfaults and mono returns
the following error:

** (process:18686): WARNING (recursed) **: unhandled exception
System.NullReferenceException: "A null value was found where an object
instance was required"

RESULT: -1

and then needs to be sent a ctrl-c.

I'm running the mono CVS debs from http://www.atoker.com/mono/ as of
yesterday on a Debian sid system.

I've attached both my small test case and the original app (it's very
small - all it does is iterate over the bytes of a text file looking for
non-ascii chars) - I hope they're of some use.

Thanks
Leigh

--=-ewr73hCBkCnG79+lyYC2
Content-Disposition: attachment; filename=breaktest.cs
Content-Type: text/plain; name=breaktest.cs; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

using System;

public class BreakTest
{
	public static void Main()
	//public static int Main()
	{
		while(true)
		{
			Console.WriteLine("Breaking...");
			break;
		}
		//return 0;
	}
}

--=-ewr73hCBkCnG79+lyYC2
Content-Disposition: attachment; filename=nonascii.cs
Content-Type: text/plain; name=nonascii.cs; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

using System;
using System.IO;

public class NonAscii
{
	public static void Main(string[] args)
	//public static int Main(string[] args)
	{
		FileStream s =3D new FileStream(args[0], FileMode.Open, FileAccess.Read);
		int line=3D0, ch=3D0;
		int x=3D0;
	=09
		while(true)
		{
			int c =3D s.ReadByte();
			Console.WriteLine("char " + x + ": " + c);
			if(c =3D=3D -1) break;

			if(c =3D=3D '\n')
			{
				line++; ch=3D0;
			} else {
				if(c > 127)
				{
					Console.WriteLine("Non-ASCII char: line " + line + ", char " + ch);
				}
				ch++;
			}
			x++;
		}
		//return 0;
	}
}

--=-ewr73hCBkCnG79+lyYC2--

--=-wfTJi1Q9oMj8wBzrMAPi
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQA9IpndIjZPyZAhT/oRArFMAKCCGV1QqkPfOZNPML8HYKHFZkcxTwCfZTkE
16raxkHeZERUB5FVfXxPo6Y=
=sx7Y
-----END PGP SIGNATURE-----

--=-wfTJi1Q9oMj8wBzrMAPi--