[Mono-list] mono and mcs Patches for Single ToString
Daniel Morgan
danmorg@sc.rr.com
Thu, 9 May 2002 02:36:31 -0400
This is a multi-part message in MIME format.
------=_NextPart_000_0029_01C1F702.546CDB60
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: 7bit
Since I have not provided a patch for the mono runtime nor the mcs
corlib, I thought I provide my patches to the list first.
I implemented the ToString method in System.Single. Basically, it is
just a copy of the same method from System.Double, but modified for
Single. Same thing with the runtime in icall.c, I copied the
ToStringImpl for Double and modified it for Single.
Formatting still needs to be done for Single and Double though.
Is it okay to cvs commit this?
Thanks,
Daniel
------=_NextPart_000_0029_01C1F702.546CDB60
Content-Type: text/plain;
name="mcs-single-diff.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="mcs-single-diff.txt"
Index: class/System.Data/System.Data.SqlClient/PostgresLibrary.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: =
/cvs/public/mcs/class/System.Data/System.Data.SqlClient/PostgresLibrary.c=
s,v=0A=
retrieving revision 1.8=0A=
diff -u -r1.8 PostgresLibrary.cs=0A=
--- class/System.Data/System.Data.SqlClient/PostgresLibrary.cs 4 May =
2002 20:23:28 -0000 1.8=0A=
+++ class/System.Data/System.Data.SqlClient/PostgresLibrary.cs 9 May =
2002 02:39:44 -0000=0A=
@@ -14,6 +14,8 @@=0A=
// (C) Ximian, Inc 2002=0A=
//=0A=
=0A=
+// #define DEBUG_PostgresLibrary=0A=
+=0A=
using System;=0A=
using System.Data;=0A=
using System.Runtime.InteropServices;=0A=
@@ -68,6 +70,8 @@=0A=
public static DbType TypnameToSqlDbType(string typname) {
DbType sqlType;
=09
+ // FIXME: use hashtable here?
+
switch(typname) {
=20
case "abstime":
@@ -238,33 +242,44 @@=0A=
// from PostgreSQL oid type=0A=
// to .NET System.<type>=0A=
=0A=
+ // TODO: need to handle a NULL for each type=0A=
+ // maybe setting obj to System.DBNull.Value ?=0A=
+=0A=
+#if DEBUG_PostgresLibrary=0A=
+ Console.WriteLine("ConvertDbTypeToSystem typ: " + =0A=
+ typ + " value: " + value);=0A=
+#endif // DEBUG_PostgresLibrary=0A=
+=0A=
switch(typ) {=0A=
case DbType.String:=0A=
- obj =3D (object) String.Copy(value); =0A=
+ obj =3D String.Copy(value); =0A=
break;=0A=
case DbType.Boolean:=0A=
- obj =3D (object) Boolean.Parse(value);=0A=
+ if(value.Equals("t"))=0A=
+ obj =3D Boolean.Parse("true");=0A=
+ else=0A=
+ obj =3D Boolean.Parse("false");=0A=
break;=0A=
case DbType.Int16:
- obj =3D (object) Int16.Parse(value);
+ obj =3D Int16.Parse(value);
break;
case DbType.Int32:
- obj =3D (object) Int32.Parse(value);
+ obj =3D Int32.Parse(value);
break;
case DbType.Int64:
- obj =3D (object) Int64.Parse(value);
+ obj =3D Int64.Parse(value);
break;
case DbType.Decimal:
- obj =3D (object) Decimal.Parse(value);
+ obj =3D Decimal.Parse(value);
break;
case DbType.Single:
- obj =3D (object) Single.Parse(value);
+ obj =3D Single.Parse(value);
break;
case DbType.Double:
- obj =3D (object) Double.Parse(value);
+ obj =3D Double.Parse(value);
break;
default:
- obj =3D (object) String.Copy(value);
+ obj =3D String.Copy(value);
break;
}=0A=
=0A=
Index: class/System.Data/System.Data.SqlClient/SqlConnection.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: =
/cvs/public/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs,=
v=0A=
retrieving revision 1.12=0A=
diff -u -r1.12 SqlConnection.cs=0A=
--- class/System.Data/System.Data.SqlClient/SqlConnection.cs 4 May 2002 =
20:23:28 -0000 1.12=0A=
+++ class/System.Data/System.Data.SqlClient/SqlConnection.cs 9 May 2002 =
02:39:44 -0000=0A=
@@ -561,34 +561,32 @@=0A=
=0A=
String value;=0A=
=0A=
- int r, c;=0A=
+ int r;=0A=
for(r =3D 0; r < nRows; r++) {=0A=
PostgresType pgType =3D =0A=
new PostgresType();=0A=
=0A=
- for(c =3D 0; c < nFields; c++) {=0A=
- // get data value=0A=
- value =3D PostgresLibrary.=0A=
- PQgetvalue(=0A=
+ // get data value (oid)=0A=
+ value =3D PostgresLibrary.=0A=
+ PQgetvalue(=0A=
pgResult,=0A=
- r, c);=0A=
+ r, 0);=0A=
=0A=
- if(c =3D=3D 0) {
- pgType.oid =3D Int32.Parse(value);
- }
- else if(c =3D=3D 1) {
- pgType.typname =3D String.Copy(value);
- pgType.dbType =3D PostgresHelper.
- TypnameToSqlDbType(
+ pgType.oid =3D Int32.Parse(value);
+
+ // get data value (typname)
+ value =3D PostgresLibrary.=0A=
+ PQgetvalue(=0A=
+ pgResult,=0A=
+ r, 1);=09
+ pgType.typname =3D String.Copy(value);
+ pgType.dbType =3D PostgresHelper.
+ TypnameToSqlDbType(
pgType.typname);
=20
- pgTypes.Add(pgType);
- }
- // FIXME: needs to be Read Only
- // pgTypes =3D ArrayList.ReadOnly(pgTypes);=0A=
-=0A=
- }=0A=
+ pgTypes.Add(pgType);=0A=
}=0A=
+ pgTypes =3D ArrayList.ReadOnly(pgTypes);=0A=
}=0A=
=0A=
internal void Load() {=0A=
Index: class/System.Data/Test/PostgresTest.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/public/mcs/class/System.Data/Test/PostgresTest.cs,v=0A=
retrieving revision 1.3=0A=
diff -u -r1.3 PostgresTest.cs=0A=
--- class/System.Data/Test/PostgresTest.cs 6 May 2002 04:52:33 -0000 1.3=0A=
+++ class/System.Data/Test/PostgresTest.cs 9 May 2002 02:39:44 -0000=0A=
@@ -48,7 +48,7 @@=0A=
"int2_value smallint, " +=0A=
"int4_value integer, " +=0A=
"bigint_value bigint, " +=0A=
- "float_value real, " +=0A=
+ "float_value real, " + =0A=
"double_value double precision, " +=0A=
"numeric_value numeric(15, 3), " +=0A=
"char_value char(50), " +=0A=
@@ -129,9 +129,12 @@=0A=
=0A=
selectCommand.CommandText =3D =0A=
"select " + =0A=
+ "boolean_value, " +=0A=
"int2_value, " +=0A=
"int4_value, " +=0A=
"bigint_value, " +=0A=
+ "float_value, " + =0A=
+ "double_value, " +=0A=
"char_value, " +=0A=
"varchar_value, " +=0A=
"text_value " +=0A=
@@ -142,10 +145,49 @@=0A=
return reader;=0A=
}=0A=
=0A=
+ static void UpdateData (IDbConnection cnc) {=0A=
+ =0A=
+ IDbCommand updateCommand =3D cnc.CreateCommand(); =0A=
+ =0A=
+ updateCommand.CommandText =3D =0A=
+ "update mono_postgres_test " + =0A=
+ "set " +=0A=
+ "boolean_value =3D 'F', " +=0A=
+ "int2_value =3D 5, " +=0A=
+ "int4_value =3D 3, " +=0A=
+ "bigint_value =3D 9, " +=0A=
+ "char_value =3D 'Mono.Data!' , " +=0A=
+ "varchar_value =3D 'It was not me!', " +=0A=
+ "text_value =3D 'We got data!' " +=0A=
+ "where int2_value =3D -22";=0A=
+=0A=
+ updateCommand.ExecuteNonQuery (); =0A=
+ }=0A=
+=0A=
+ // used to do a min(), max(), count(), sum(), or avg()=0A=
+ static object SelectAggregate (IDbConnection cnc, String agg) {=0A=
+ =0A=
+ IDbCommand selectCommand =3D cnc.CreateCommand();=0A=
+ object data;=0A=
+=0A=
+ Console.WriteLine("Aggregate: " + agg);=0A=
+=0A=
+ selectCommand.CommandText =3D =0A=
+ "select " + agg +=0A=
+ "from mono_postgres_test";=0A=
+=0A=
+ data =3D selectCommand.ExecuteScalar ();=0A=
+=0A=
+ Console.WriteLine("Agg Result: " + data);=0A=
+=0A=
+ return data;=0A=
+ }=0A=
+=0A=
/* Postgres provider tests */=0A=
static void DoPostgresTest (IDbConnection cnc) {=0A=
=0A=
IDataReader reader;=0A=
+ Object oDataValue;=0A=
=0A=
Console.WriteLine ("\tPostgres provider specific tests...\n");=0A=
=0A=
@@ -156,7 +198,7 @@=0A=
Console.WriteLine ("OK");=0A=
}=0A=
catch (SqlException e) {=0A=
- Console.WriteLine("Error (don't worry about this one): + e");=0A=
+ Console.WriteLine("Error (don't worry about this one)" + e);=0A=
}=0A=
=0A=
try {=0A=
@@ -169,7 +211,24 @@=0A=
Console.WriteLine ("\t\tInsert values for all known types: ");=0A=
InsertData (cnc);=0A=
Console.WriteLine ("OK");=0A=
- =0A=
+=0A=
+ /* Update values */=0A=
+ Console.WriteLine ("\t\tUpdate values: ");=0A=
+ UpdateData (cnc);=0A=
+ Console.WriteLine ("OK");=0A=
+=0A=
+ /* Inserts values */=0A=
+ Console.WriteLine ("\t\tInsert values for all known types: ");=0A=
+ InsertData (cnc);=0A=
+ Console.WriteLine ("OK"); =0A=
+=0A=
+ /* Select aggregates */=0A=
+ SelectAggregate (cnc, "count(*)");=0A=
+ // SelectAggregate (cnc, "avg(int4_value)");=0A=
+ SelectAggregate (cnc, "min(text_value)");=0A=
+ SelectAggregate (cnc, "max(int4_value)");=0A=
+ SelectAggregate (cnc, "sum(int4_value)");=0A=
+=0A=
/* Select values */=0A=
Console.WriteLine ("\t\tSelect values from the database: ");=0A=
reader =3D SelectData (cnc);=0A=
@@ -203,7 +262,7 @@=0A=
" Col " +=20
c + ": " +=20
dt.Columns[c].ColumnName +=20
- " - " +
+ ": " +
reader.GetValue(c));
}
=09
Index: class/corlib/System/Single.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/public/mcs/class/corlib/System/Single.cs,v=0A=
retrieving revision 1.11=0A=
diff -u -r1.11 Single.cs=0A=
--- class/corlib/System/Single.cs 8 May 2002 13:21:11 -0000 1.11=0A=
+++ class/corlib/System/Single.cs 9 May 2002 02:39:55 -0000=0A=
@@ -8,6 +8,7 @@=0A=
//=0A=
=0A=
using System.Globalization;=0A=
+using System.Runtime.CompilerServices;=0A=
=0A=
namespace System {=0A=
=0A=
@@ -84,10 +85,68 @@=0A=
}=0A=
=0A=
[MonoTODO]=0A=
- public static float Parse (string s, NumberStyles style, =
IFormatProvider fp)=0A=
+ public static float Parse (string s, NumberStyles style, =
IFormatProvider fp) =0A=
{=0A=
- // TODO: Implement me=0A=
- throw new NotImplementedException ();=0A=
+ // FIXME: I copied this method from System.Double=0A=
+ // fix it for System.Single=0A=
+ =0A=
+ if (s =3D=3D null) throw new ArgumentNullException();=0A=
+ if (style > NumberStyles.Any) {=0A=
+ throw new ArgumentException();=0A=
+ }=0A=
+ NumberFormatInfo format =3D NumberFormatInfo.GetInstance(fp);=0A=
+ if (format =3D=3D null) throw new Exception("How did this happen?");=0A=
+ if (s =3D=3D format.NaNSymbol) return Single.NaN;=0A=
+ if (s =3D=3D format.PositiveInfinitySymbol) return =
Single.PositiveInfinity;=0A=
+ if (s =3D=3D format.NegativeInfinitySymbol) return =
Single.NegativeInfinity;=0A=
+ string[] sl;=0A=
+ long integral =3D 0;=0A=
+ long fraction =3D 0;=0A=
+ long exponent =3D 1;=0A=
+ float retval =3D 0;=0A=
+ if ((style & NumberStyles.AllowLeadingWhite) !=3D 0) {=0A=
+ s.TrimStart(null);=0A=
+ }=0A=
+ if ((style & NumberStyles.AllowTrailingWhite) !=3D 0) {=0A=
+ s.TrimEnd(null);=0A=
+ }=0A=
+ sl =3D s.Split(new Char[] {'e', 'E'}, 2);=0A=
+ if (sl.Length > 1) {=0A=
+ if ((style & NumberStyles.AllowExponent) =3D=3D 0) {=0A=
+ throw new FormatException();=0A=
+ }=0A=
+ exponent =3D long.Parse(sl[1], NumberStyles.AllowLeadingSign, =
format);=0A=
+ }=0A=
+ s =3D sl[0];=0A=
+ sl =3D s.Split(format.NumberDecimalSeparator.ToCharArray(), 2);=0A=
+ if (sl.Length > 1) {=0A=
+ if ((style & NumberStyles.AllowDecimalPoint) =3D=3D 0) {=0A=
+ throw new FormatException();=0A=
+ }=0A=
+ fraction =3D long.Parse(sl[1], NumberStyles.None, format);=0A=
+ }=0A=
+ NumberStyles tempstyle =3D NumberStyles.None;=0A=
+ if ((style & NumberStyles.AllowLeadingSign) !=3D 0){=0A=
+ tempstyle =3D NumberStyles.AllowLeadingSign;=0A=
+ }=0A=
+=0A=
+ if (sl[0].Length > 0)=0A=
+ integral =3D long.Parse(sl[0], tempstyle, format);=0A=
+ else=0A=
+ integral =3D 0;=0A=
+=0A=
+ retval =3D fraction;=0A=
+=0A=
+ // FIXME: what about the zeros between the decimal point =0A=
+ // and the first non-zero digit?=0A=
+ while (retval >1) retval /=3D 10;=0A=
+ if (integral < 0){=0A=
+ retval -=3D integral;=0A=
+ retval =3D -retval;=0A=
+ }=0A=
+ else retval +=3D integral;=0A=
+ if (exponent !=3D 1) retval *=3D (float) Math.Pow(10, exponent);=0A=
+ return retval;=0A=
}=0A=
=0A=
public override string ToString ()=0A=
@@ -108,9 +167,12 @@=0A=
[MonoTODO]=0A=
public string ToString (string format, IFormatProvider fp)=0A=
{=0A=
- // TODO: Implement me.=0A=
- throw new NotImplementedException ();=0A=
+ // FIXME: Need to pass format and provider info to this call too.=0A=
+ return ToStringImpl(value);=0A=
}=0A=
+=0A=
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]=0A=
+ private static extern string ToStringImpl (float value);=0A=
=0A=
// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D IConvertible Methods =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D //=0A=
=0A=
------=_NextPart_000_0029_01C1F702.546CDB60
Content-Type: text/plain;
name="mono-single-diff.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="mono-single-diff.txt"
? autom4te.cache=0A=
? stamp-h1=0A=
? docs/Makefile=0A=
? docs/Makefile.in=0A=
? mono/arch/sparc/.deps=0A=
Index: mono/metadata/icall.c=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/public/mono/mono/metadata/icall.c,v=0A=
retrieving revision 1.138=0A=
diff -u -r1.138 icall.c=0A=
--- mono/metadata/icall.c 4 May 2002 09:14:52 -0000 1.138=0A=
+++ mono/metadata/icall.c 9 May 2002 02:40:39 -0000=0A=
@@ -52,6 +52,15 @@=0A=
return mono_string_new (mono_domain_get (), retVal);=0A=
}=0A=
=0A=
+static MonoString *=0A=
+mono_float_ToStringImpl (float value)=0A=
+{=0A=
+ /* FIXME: Handle formats, etc. */=0A=
+ const gchar *retVal;=0A=
+ retVal =3D g_strdup_printf ("%f", value);=0A=
+ return mono_string_new (mono_domain_get (), retVal);=0A=
+}=0A=
+=0A=
static MonoObject *=0A=
ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)=0A=
{=0A=
@@ -2212,6 +2221,11 @@=0A=
* System.Double=0A=
*/=0A=
"System.Double::ToStringImpl", mono_double_ToStringImpl,=0A=
+=0A=
+ /*=0A=
+ * System.Single=0A=
+ */=0A=
+ "System.Single::ToStringImpl", mono_float_ToStringImpl,=0A=
=0A=
/*=0A=
* System.Decimal=0A=
------=_NextPart_000_0029_01C1F702.546CDB60--