This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] libobjc Protocol isEqual: test class


> > 2004-06-03  David Ayers  <d.ayers@inode.at>
> >
> > 	* Protocol.m ([-isEqual:]): Test the class of the argument.
> 
> This is OK.  I will install it tomorrow.

Thanks/Yes, I agree this is OK (thanks David!).

At some point in the past months I had already rewritten isEqual:, but
then got lost into testing it fully by trying to have Protocols objects
embedded into gnustep-base's NSDictionary (which didn't work for other
reasons), and got distracted and never committed the changes.  I had also
compared our implementation to Apple runtime's implementation, which is
available somewhere on the web.  Here is the stuff I had on my libobjc -

+/*
+ * Equality between formal protocols is only formal (nothing to do
+ * with actually checking the list of methods they have!).  Two formal
+ * Protocols are equal if and only if they have the same name.
+ *
+ * Please note (for comparisons with other implementations) that
+ * checking the names is equivalent to checking that Protocol A
+ * conforms to Protocol B and Protocol B conforms to Protocol A,
+ * because this happens iff they have the same name.  If they have
+ * different names, A conforms to B if and only if A includes B, but
+ * the situation where A includes B and B includes A is a circular
+ * dependency between Protocols which is forbidden by the compiler, so
+ * A conforms to B and B conforms to A with A and B having different
+ * names is an impossible case.
+ */
+- (BOOL) isEqual: (id)obj
+{
+  if (obj == self)
+    return YES;
+
+  if ([obj isKindOf: [Protocol class]])
+    {
+      if (strcmp (protocol_name, ((Protocol *)obj)->protocol_name) == 0)
+        return YES;
+    }
+  
+  return NO;
+}

(the comments highlight that our implementation is totally equivalent to
Apple runtime's one - which might be non-obvious -, but ours is a lot
faster [not that it does really matter much in real life]).

I've applied both David patch, and the few remaining changes I had on my
local copy on top of it.

I also committed David's new testcase, and since I was there I also wanted
to be more sure everything was Ok in our Protocol-isEqual:, so I added 3
new testcases to test Protocol -isEqual:, and committed them.

(It looks like I've also more symbols in libobjc.def in my local copy ?!  
I'll have a look at that maybe tomorrow.)

I tested all this stuff with the GNU runtime on i686-pc-linux-gnu and
everything seemed fine.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]