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]

Re: 3.0.1 PATCH: Avoid link failure of Objective-C testsuite on Solaris2/Intel



> > Here is a complete patch fixing libobjc:
> 
> I've tried your patch on all configurations used to verify my patch to allow
> a shared libobjc to work on Solaris
> 
> 	http://gcc.gnu.org/ml/gcc-patches/2001-06/msg01785.html
> 
> and it fixes all the testsuite differences between the static and shared
> cases reported there, so it looks very good.

Thanks for the testing.

 
> A few stylistic comments on the patch, though:

Ok - at the end of this mail there is a new patch taking into account your
comments on style.  Btw, I also generated better testcases, much more
convincing, they are included as well, please would you commit those
instead of the other one as they are much cooler :-)

> Btw, the whole file (objc/objc-api.h) is full of GCS violations.  Would you
> mind providing a patch (probably mainline only) to fix this?

Yes - I wouldn't mind - once the real patch which fixes the bug has been
applied then I promise I'll submit one to reindent the file. :-)

here is the code - should be pretty definitive now - waiting for something
to approve and apply the following stuff - 

Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libobjc/ChangeLog,v
retrieving revision 1.63
diff -u -r1.63 ChangeLog
--- ChangeLog	2001/06/09 20:32:56	1.63
+++ ChangeLog	2001/07/03 09:49:54
@@ -1,3 +1,10 @@
+Tue Jul  3 10:49:38 2001  Nicola Pero  <nicola@brainstorm.co.uk>
+
+	* objc/objc-api.h (object_is_class): Fixed - buggy code was trying
+	to cast an id to a Class, which can not be done.  Make the check
+	by using CLS_ISMETA on the class pointer instead.
+	(object_is_meta_class): Similar fix.
+
 2001-06-09  Alexandre Oliva  <aoliva@redhat.com>, Stephen L Moshier  <moshier@mediaone.net>
 
 	* configure.in (AC_EXEEXT): Work around in case it expands to
Index: objc/objc-api.h
===================================================================
RCS file: /cvs/gcc/gcc/libobjc/objc/objc-api.h,v
retrieving revision 1.3
diff -u -r1.3 objc-api.h
--- objc-api.h	2001/01/03 08:49:34	1.3
+++ objc-api.h	2001/07/03 09:49:55
@@ -578,22 +578,25 @@
 }
 
 static inline BOOL
-object_is_class(id object)
+object_is_class (id object)
 {
-  return CLS_ISCLASS((Class)object);
+  return ((object != nil)  &&  CLS_ISMETA (object->class_pointer));
 }
 
 static inline BOOL
-object_is_instance(id object)
+object_is_instance (id object)
 {
-  return (object!=nil)&&CLS_ISCLASS(object->class_pointer);
+  return ((object != nil)  &&  CLS_ISCLASS (object->class_pointer));
 }
 
 static inline BOOL
-object_is_meta_class(id object)
+object_is_meta_class (id object)
 {
-  return CLS_ISMETA((Class)object);
+  return ((object != nil)
+	  &&  !object_is_instance (object)  
+	  &&  !object_is_class (object));
 }
+
 
 struct sarray* 
 objc_get_uninstalled_dtable(void);


And now the testcase:
=====================

object_is_class.m:
==================

/* Contributed by Nicola Pero - Tue Jul  3 10:55:21 BST 2001 */
#include <objc/objc.h>
#include <objc/objc-api.h>
#include <objc/Object.h>

/* This test demonstrate a failure in object_is_class which was fixed */

/* Create a class whose instance variables mirror the struct used for
   Class structures in the runtime ... yes we're feeling evil today */
@interface EvilClass : Object
{
  Class super_class;
  const char* name;
  long version;
  unsigned long info;    
}
@end

@implementation EvilClass
- (id) init
{
  self = [super init];
  /* The following one is used in the runtime to mark classes */
  info = 0x1L;
  return self;
}
@end

int main (void)
{
  /* Create an object of our EvilClass */
  EvilClass *evilObject = [EvilClass new];
  
  /* Now check that the object is not a class object */
  if (object_is_class (evilObject))
    {
      printf ("object_is_class failed\n");
      abort ();
    }

  return 0;
}

object_is_meta_class.m:
=======================

/* Contributed by Nicola Pero - Tue Jul  3 10:55:21 BST 2001 */
#include <objc/objc.h>
#include <objc/objc-api.h>
#include <objc/Object.h>

/* This test demonstrate a failure in object_is_meta_class which was fixed */

@interface EvilClass : Object
{
  Class super_class;
  const char* name;
  long version;
  unsigned long info;    
}
@end

@implementation EvilClass
- (id) init
{
  self = [super init];
  /* The following one is used in the runtime to mark meta classes */
  info = 0x2L;
  return self;
}
@end

int main (void)
{
  /* Create an object of our EvilClass */
  EvilClass *evilObject = [EvilClass new];
  
  /* Now check that the object is not a meta class object */
  if (object_is_meta_class (evilObject))
    {
      printf ("object_is_meta_class failed\n");
      abort ();
    }

  return 0;
}



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