]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/gcc-tumbl.git/commitdiff
In libobjc/:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 24 Dec 2010 18:41:05 +0000 (18:41 +0000)
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 24 Dec 2010 18:41:05 +0000 (18:41 +0000)
2010-12-24  Nicola Pero  <nicola.pero@meta-innovation.com>

* objc/runtime.h (class_addIvar): Updated documentation.  The
alignment is actually the log_2 of the alignment in bytes.
* ivars.c (class_addIvar): Corresponding change to the
implementation.

In gcc/testsuite/:
2010-12-24  Nicola Pero  <nicola.pero@meta-innovation.com>

* objc.dg/gnu-api-2-class.m: Updated test to pass log_2 of the
alignment to class_addIvar, instead of the alignment itself.
* obj-c++.dg/gnu-api-2-class.mm: Same change.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@168230 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm
gcc/testsuite/objc.dg/gnu-api-2-class.m
libobjc/ChangeLog
libobjc/ivars.c
libobjc/objc/runtime.h

index 0140ced82d4f1cdbab0b3dd3bb1021f140300357..2e68afa4f213a1475f7bd6e2ab4e457a0996dae9 100644 (file)
@@ -1,3 +1,9 @@
+2010-12-24  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * objc.dg/gnu-api-2-class.m: Updated test to pass log_2 of the
+       alignment to class_addIvar, instead of the alignment itself.
+       * obj-c++.dg/gnu-api-2-class.mm: Same change.
+
 2010-12-24  Nicola Pero  <nicola.pero@meta-innovation.com>
 
        * objc.dg/gnu-api-2-sel.m: Updated for renaming of sel_getType to
index b86396f2144aa35bb4d50651f5ee86210a54c9ec..18c3393fa1e905de4dae416135639712db301d7a 100644 (file)
 - (id) mySelf;
 @end
 
+/* Hack to calculate the log2 of a byte alignment.  */
+unsigned char
+log_2_of (unsigned int x)
+{
+  unsigned char result = 0;
+
+  /* We count how many times we need to divide by 2 before we reach 1.
+     This algorithm is good enough for the small numbers (such as 8,
+     16 or 64) that we have to deal with.  */
+  while (x > 1)
+    {
+      x = x / 2;
+      result++;
+    }
+
+  return result;
+}
+
 int main ()
 {
   /* Functions are tested in alphabetical order.  */
@@ -74,15 +92,15 @@ int main ()
       abort ();
     
     if (! class_addIvar (new_class, "variable2_ivar", sizeof (id),
-                        __alignof__ (id), @encode (id)))
+                        log_2_of (__alignof__ (id)), @encode (id)))
       abort ();
 
     if (! class_addIvar (new_class, "variable3_ivar", sizeof (unsigned char),
-                        __alignof__ (unsigned char), @encode (unsigned char)))
+                        log_2_of (__alignof__ (unsigned char)), @encode (unsigned char)))
       abort ();
 
     if (! class_addIvar (new_class, "variable4_ivar", sizeof (unsigned long),
-                        __alignof__ (unsigned long), @encode (unsigned long)))
+                        log_2_of (__alignof__ (unsigned long)), @encode (unsigned long)))
       abort ();
 
     objc_registerClassPair (new_class);    
@@ -135,7 +153,7 @@ int main ()
       abort ();
     
     if (! class_addIvar (new_class, "variable_ivar", sizeof (id),
-                        __alignof__ (id), @encode (id)))
+                        log_2_of (__alignof__ (id)), @encode (id)))
       abort ();
 
     if (! class_addMethod (new_class, @selector (setVariable:), method_getImplementation (method1),
index ff0425966cdc5252e62ef58f49333855dbfc25c3..3302fccbb17aeb628ddf247b676296a9a1969087 100644 (file)
 - (id) mySelf;
 @end
 
+/* Hack to calculate the log2 of a byte alignment.  */
+unsigned char
+log_2_of (unsigned int x)
+{
+  unsigned char result = 0;
+
+  /* We count how many times we need to divide by 2 before we reach 1.
+     This algorithm is good enough for the small numbers (such as 8,
+     16 or 64) that we have to deal with.  */
+  while (x > 1)
+    {
+      x = x / 2;
+      result++;
+    }
+
+  return result;
+}
+
 int main(int argc, void **args)
 {
   /* Functions are tested in alphabetical order.  */
@@ -74,15 +92,15 @@ int main(int argc, void **args)
       abort ();
     
     if (! class_addIvar (new_class, "variable2_ivar", sizeof (id),
-                        __alignof__ (id), @encode (id)))
+                        log_2_of (__alignof__ (id)), @encode (id)))
       abort ();
 
     if (! class_addIvar (new_class, "variable3_ivar", sizeof (unsigned char),
-                        __alignof__ (unsigned char), @encode (unsigned char)))
+                        log_2_of (__alignof__ (unsigned char)), @encode (unsigned char)))
       abort ();
 
     if (! class_addIvar (new_class, "variable4_ivar", sizeof (unsigned long),
-                        __alignof__ (unsigned long), @encode (unsigned long)))
+                        log_2_of (__alignof__ (unsigned long)), @encode (unsigned long)))
       abort ();
 
     objc_registerClassPair (new_class);    
@@ -135,7 +153,7 @@ int main(int argc, void **args)
       abort ();
     
     if (! class_addIvar (new_class, "variable_ivar", sizeof (id),
-                        __alignof__ (id), @encode (id)))
+                        log_2_of (__alignof__ (id)), @encode (id)))
       abort ();
 
     if (! class_addMethod (new_class, @selector (setVariable:), method_getImplementation (method1),
index e028b58fc234f11fb5f5b8f10ec03c85b6fd9594..d8f23f74c9a1c4c2d981b83696c5226ae87d4d87 100644 (file)
@@ -1,3 +1,10 @@
+2010-12-24  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * objc/runtime.h (class_addIvar): Updated documentation.  The
+       alignment is actually the log_2 of the alignment in bytes.
+       * ivars.c (class_addIvar): Corresponding change to the
+       implementation.
+       
 2010-12-24  Nicola Pero  <nicola.pero@meta-innovation.com>
 
        * objc/runtime.h (sel_getType): Renamed to sel_getTypeEncoding to
index 7527df804d2505c3da8422e825b7da61eca9e10d..6111a03ea165d11542d55b87c7214b80bc16e41d 100644 (file)
@@ -212,7 +212,7 @@ struct objc_ivar ** class_copyIvarList (Class class_, unsigned int *numberOfRetu
 
 BOOL
 class_addIvar (Class class_, const char * ivar_name, size_t size,
-              unsigned char alignment, const char *type)
+              unsigned char log_2_of_alignment, const char *type)
 {
   struct objc_ivar_list *ivars;
 
@@ -270,6 +270,7 @@ class_addIvar (Class class_, const char * ivar_name, size_t size,
      size. */
   {
     struct objc_ivar *ivar = &(ivars->ivar_list[ivars->ivar_count - 1]);
+    unsigned int alignment = 1 << log_2_of_alignment;
     int misalignment;
     
     ivar->ivar_name = objc_malloc (strlen (ivar_name) + 1);
index 18fc8726dc4242e6a5f44dfdb6711eea7b78647b..9332f7be0692cf080af88e5eb9083f3b646a50e4 100644 (file)
@@ -352,14 +352,16 @@ objc_EXPORT Ivar * class_copyIvarList (Class class_, unsigned int *numberOfRetur
    using objc_allocateClassPair() and has not been registered with the
    runtime using objc_registerClassPair() yet.  You can not add
    instance variables to classes already registered with the runtime.
-   'size' is the size of the instance variable, 'alignment' the
-   alignment, and 'type' the type encoding of the variable type.  You
-   can use sizeof(), __alignof__() and @encode() to determine the
-   right 'size', 'alignment' and 'type' for your instance variable.
-   For example, to add an instance variable name "my_variable" and of
-   type 'id', you can use:
-
-   class_addIvar (class, "my_variable", sizeof (id), __alignof__ (id), 
+   'size' is the size of the instance variable, 'log_2_of_alignment'
+   the alignment as a power of 2 (so 0 means alignment to a 1 byte
+   boundary, 1 means alignment to a 2 byte boundary, 2 means alignment
+   to a 4 byte boundary, etc), and 'type' the type encoding of the
+   variable type.  You can use sizeof(), log2(__alignof__()) and
+   @encode() to determine the right 'size', 'alignment' and 'type' for
+   your instance variable.  For example, to add an instance variable
+   name "my_variable" and of type 'id', you can use:
+
+   class_addIvar (class, "my_variable", sizeof (id), log2 ( __alignof__ (id)),
                   @encode (id));
 
    Return YES if the variable was added, and NO if not.  In
@@ -368,7 +370,7 @@ objc_EXPORT Ivar * class_copyIvarList (Class class_, unsigned int *numberOfRetur
    'type' is NULL, or 'size' is 0.
  */
 objc_EXPORT BOOL class_addIvar (Class class_, const char * ivar_name, size_t size,
-                               unsigned char alignment, const char *type);
+                               unsigned char log_2_of_alignment, const char *type);
 
 /* Return the name of the property.  Return NULL if 'property' is
    NULL.  */