[Gtk-sharp-list] Patch for GType.Int64 and UInt64 support in GLib.Value

Jorge García jgarcia@ac.upc.es
Sat, 14 Aug 2004 21:49:55 +0200


--=-/jdtGMYsvDyuoBS6CAyZ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit


Hi,

attached is a patch to add support for GType.Int64 and UInt64 in
GLib.Value, and a program that shows the problem.

Jorge


--=-/jdtGMYsvDyuoBS6CAyZ
Content-Disposition: attachment; filename=TestGValue.cs
Content-Type: text/x-csharp; name=TestGValue.cs; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

using GLib;
using System;

public class TestGValue
{


  static void Main(string[] args)
  {

	  Gtk.Application.Init();

	  GLib.Value val = new Value((long) -9000000000000000000);
	  long l = (long) val;
	  Console.WriteLine(val.Val);
	  Console.WriteLine(l);

	  GLib.Value val2 = new Value((ulong) 9000000000000000000);
	  ulong l2 = (ulong) val2;
	  Console.WriteLine(val2.Val);
	  Console.WriteLine(l2);
  }
}

--=-/jdtGMYsvDyuoBS6CAyZ
Content-Disposition: attachment; filename=file.diff
Content-Type: text/x-patch; name=file.diff; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

? file.diff
Index: ChangeLog
===================================================================
RCS file: /mono/gtk-sharp/ChangeLog,v
retrieving revision 1.885
diff -u -r1.885 ChangeLog
--- ChangeLog	13 Aug 2004 19:39:33 -0000	1.885
+++ ChangeLog	14 Aug 2004 19:38:11 -0000
@@ -1,3 +1,10 @@
+
+2004-08-14  Jorge Garcia <jgarcia@ac.upc.es>
+
+	* glib/Type.cs:          add Int64 and UInt64 support.
+	* glib/TypeConverter.cs: add Int64 and UInt64 support.
+	* glib/Value.cs:         add Int64 and UInt64 support.
+	
 2004-08-13  John Luke  <john.luke@gmail.com>
 
 	* gtk/Gtk.metadata: mark Gtk.StockManager.Lookup param as ref
Index: glib/Type.cs
===================================================================
RCS file: /mono/gtk-sharp/glib/Type.cs,v
retrieving revision 1.5
diff -u -r1.5 Type.cs
--- glib/Type.cs	9 Jul 2004 15:25:39 -0000	1.5
+++ glib/Type.cs	14 Aug 2004 19:38:16 -0000
@@ -39,6 +39,9 @@
 		public static readonly GType String = new GType ((IntPtr) TypeFundamentals.TypeString);
 		public static readonly GType Boolean = new GType ((IntPtr) TypeFundamentals.TypeBoolean);
 		public static readonly GType Int = new GType ((IntPtr) TypeFundamentals.TypeInt);
+		public static readonly GType Int64 = new GType ((IntPtr) TypeFundamentals.TypeInt64);
+		public static readonly GType UInt64 = new GType ((IntPtr) TypeFundamentals.TypeUInt64);
+
 		public static readonly GType Double = new GType ((IntPtr) TypeFundamentals.TypeDouble);
 		public static readonly GType Float = new GType ((IntPtr) TypeFundamentals.TypeFloat);
 		public static readonly GType Char = new GType ((IntPtr) TypeFundamentals.TypeChar);
Index: glib/TypeConverter.cs
===================================================================
RCS file: /mono/gtk-sharp/glib/TypeConverter.cs,v
retrieving revision 1.10
diff -u -r1.10 TypeConverter.cs
--- glib/TypeConverter.cs	25 Jun 2004 18:42:17 -0000	1.10
+++ glib/TypeConverter.cs	14 Aug 2004 19:38:17 -0000
@@ -36,6 +36,10 @@
 				return GType.Boolean;
 			if (type.Equals (typeof (int)))
 				return GType.Int;
+			if (type.Equals (typeof (long)))
+				return GType.Int64;
+			if (type.Equals (typeof (ulong)))
+				return GType.UInt64;
 			if (type.Equals (typeof (double)))
 				return GType.Double;
 			if (type.Equals (typeof (float)))
Index: glib/Value.cs
===================================================================
RCS file: /mono/gtk-sharp/glib/Value.cs,v
retrieving revision 1.49
diff -u -r1.49 Value.cs
--- glib/Value.cs	23 Jul 2004 14:54:48 -0000	1.49
+++ glib/Value.cs	14 Aug 2004 19:38:17 -0000
@@ -129,6 +129,23 @@
 		}
 
 		[DllImport("libgobject-2.0-0.dll")]
+		static extern void g_value_set_int64 (ref Value val, long data);
+
+		public Value (long val) : this (GType.Int64)
+		{
+			g_value_set_int64 (ref this, val);
+		}
+
+		[DllImport("libgobject-2.0-0.dll")]
+		static extern void g_value_set_uint64 (ref Value val, ulong data);
+
+		public Value (ulong val) : this (GType.UInt64)
+		{
+			g_value_set_uint64 (ref this, val);
+		}
+
+
+		[DllImport("libgobject-2.0-0.dll")]
 		static extern void g_value_set_object (ref Value val, IntPtr data);
 
 		public Value (GLib.Object val) : this (val == null ? GType.Object : val.NativeType)
@@ -244,6 +261,23 @@
 		}
 
 		[DllImport("libgobject-2.0-0.dll")]
+		static extern long g_value_get_int64 (ref Value val);
+
+		public static explicit operator long (Value val)
+		{
+			return g_value_get_int64 (ref val);
+		}
+
+		[DllImport("libgobject-2.0-0.dll")]
+		static extern ulong g_value_get_uint64 (ref Value val);
+
+		public static explicit operator ulong (Value val)
+		{
+			return g_value_get_uint64 (ref val);
+		}
+
+
+		[DllImport("libgobject-2.0-0.dll")]
 		static extern IntPtr g_value_get_object (ref Value val);
 
 		public static explicit operator GLib.Object (Value val)
@@ -317,6 +351,10 @@
 					return (bool) this;
 				else if (type == GType.Int)
 					return (int) this;
+				else if (type == GType.Int64)
+					return (long) this;
+				else if (type == GType.UInt64)
+					return (ulong) this;
 				else if (type == GType.Double)
 					return (double) this;
 				else if (type == GType.Float)
@@ -341,6 +379,10 @@
 					g_value_set_boolean (ref this, (bool) value);
 				else if (type == GType.Int)
 					g_value_set_int (ref this, (int) value);
+				else if (type == GType.Int64)
+					g_value_set_int64 (ref this, (long) value);
+				else if (type == GType.UInt64)
+					g_value_set_uint64 (ref this, (ulong) value);
 				else if (type == GType.Double)
 					g_value_set_double (ref this, (double) value);
 				else if (type == GType.Float)

--=-/jdtGMYsvDyuoBS6CAyZ--