From 115659f46b2ee3b592121c806515f59f5592838d Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 31 May 2013 19:38:35 +0200 Subject: [PATCH] generator: fixed Equals/GetHashCode for no fields or padding Fixed Equals/GetHashCode methods when struct has no fields, or field is padding. --- generator/StructBase.cs | 14 +++++++++----- generator/StructField.cs | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 63ace754e..4c8833c69 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -115,12 +115,16 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name); sw.WriteLine ("\t\t{"); + sw.WriteLine ("\t\t\tbool isEqual = true;"); + sb.Append ("this.GetType ().FullName.GetHashCode ()"); foreach (StructField field in fields) { + if (field.IsPadding) + continue; if (field.IsBitfield) { if (need_field) { - sw.WriteLine ("\t\tif (!_bitfield{0}.Equals (other._bitfield{0})) return false;", bitfields); - if (sb.Length > 0) + sw.WriteLine ("\t\t\tisEqual &= bitfield{0}.Equals (other._bitfield{0});", bitfields); + //if (sb.Length > 0) sb.Append (" ^ "); sb.Append ("_bitfield"); sb.Append (bitfields++); @@ -129,14 +133,14 @@ namespace GtkSharp.Generation { } } else { need_field = true; - sw.WriteLine ("\t\t\tif (!{0}.Equals (other.{0})) return false;", field.EqualityName); - if (sb.Length > 0) + sw.WriteLine ("\t\t\tisEqual &= {0}.Equals (other.{0});", field.EqualityName); + //if (sb.Length > 0) sb.Append (" ^ "); sb.Append (field.EqualityName); sb.Append (".GetHashCode ()"); } } - sw.WriteLine ("\t\t\treturn true;"); + sw.WriteLine ("\t\t\treturn isEqual;"); sw.WriteLine ("\t\t}"); sw.WriteLine (); sw.WriteLine ("\t\tpublic override bool Equals (object other)"); diff --git a/generator/StructField.cs b/generator/StructField.cs index 7b62cabd0..ac885038e 100644 --- a/generator/StructField.cs +++ b/generator/StructField.cs @@ -89,7 +89,7 @@ namespace GtkSharp.Generation { } } - bool IsPadding { + public bool IsPadding { get { return (CName.StartsWith ("dummy") || CName.StartsWith ("padding")); }