X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libobjc%2Fgc.c;h=51019993f3d145cad51d253f047b335c9202f264;hb=bfa499856489c285acca24851eaca3f00103ee17;hp=761905cafab595ee0a010700f03e4b9b4af72d37;hpb=adff42e6a4389342740fc2ffe1a9e71798c87423;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libobjc/gc.c b/libobjc/gc.c index 761905cafab..51019993f3d 100644 --- a/libobjc/gc.c +++ b/libobjc/gc.c @@ -1,23 +1,23 @@ /* Basic data types for Objective C. - Copyright (C) 1998 Free Software Foundation, Inc. + Copyright (C) 1998, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. Contributed by Ovidiu Predescu. -This file is part of GNU CC. +This file is part of GCC. -GNU CC is free software; you can redistribute it and/or modify +GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. -GNU CC is distributed in the hope that it will be useful, +GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GNU CC; see the file COPYING. If not, write to -the Free Software Foundation, 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ +along with GCC; see the file COPYING. If not, write to +the Free Software Foundation, 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. */ /* As a special exception, if you link this library with files compiled with GCC to produce an executable, this does not cause @@ -26,31 +26,22 @@ Boston, MA 02111-1307, USA. */ the executable file might be covered by the GNU General Public License. */ #include "tconfig.h" -#include "objc.h" -#include "encoding.h" +#include "objc/objc.h" +#include "objc/encoding.h" #include #include +#include #if OBJC_WITH_GC #include +#include /* gc_typed.h uses the following but doesn't declare them */ typedef GC_word word; typedef GC_signed_word signed_word; - -#if BITS_PER_WORD == 32 -# define LOGWL 5 -# define modWORDSZ(n) ((n) & 0x1f) /* n mod size of word */ -#endif - -#if BITS_PER_WORD == 64 -# define LOGWL 6 -# define modWORDSZ(n) ((n) & 0x3f) /* n mod size of word */ -#endif - -#define divWORDSZ(n) ((n) >> LOGWL) /* divide n by size of word */ +#define BITS_PER_WORD (CHAR_BIT * sizeof (word)) #include @@ -58,11 +49,11 @@ typedef GC_signed_word signed_word; The offset is incremented with the size of the type. */ #define ROUND(V, A) \ - ({ typeof(V) __v=(V); typeof(A) __a=(A); \ - __a*((__v+__a-1)/__a); }) + ({ typeof (V) __v = (V); typeof (A) __a = (A); \ + __a * ((__v+__a - 1)/__a); }) #define SET_BIT_FOR_OFFSET(mask, offset) \ - GC_set_bit(mask, offset / sizeof (void*)) + GC_set_bit (mask, offset / sizeof (void *)) /* Some prototypes */ static void @@ -74,9 +65,9 @@ __objc_gc_setup_union (GC_bitmap mask, const char *type, int offset); static void __objc_gc_setup_array (GC_bitmap mask, const char *type, int offset) { - int i, len = atoi(type + 1); + int i, len = atoi (type + 1); - while (isdigit(*++type)) + while (isdigit (*++type)) /* do nothing */; /* skip the size of the array */ switch (*type) { @@ -138,8 +129,8 @@ __objc_gc_setup_struct (GC_bitmap mask, const char *type, int offset) case _C_PTR: case _C_CHARPTR: case _C_ATOM: - if (!gc_invisible) - SET_BIT_FOR_OFFSET(mask, position); + if (! gc_invisible) + SET_BIT_FOR_OFFSET (mask, position); break; case _C_ARY_B: @@ -178,11 +169,11 @@ __objc_gc_setup_union (GC_bitmap mask, const char *type, int offset) size = objc_sizeof_type (type); align = objc_alignof_type (type); - offset = ROUND(offset, align); - for (i = 0; i < size; i += sizeof (void*)) + offset = ROUND (offset, align); + for (i = 0; i < size; i += sizeof (void *)) { - SET_BIT_FOR_OFFSET(mask, offset); - offset += sizeof (void*); + SET_BIT_FOR_OFFSET (mask, offset); + offset += sizeof (void *); } } @@ -223,8 +214,8 @@ __objc_gc_type_description_from_type (GC_bitmap mask, const char *type) case _C_SEL: case _C_PTR: case _C_CHARPTR: - if (!gc_invisible) - SET_BIT_FOR_OFFSET(mask, offset); + if (! gc_invisible) + SET_BIT_FOR_OFFSET (mask, offset); break; case _C_ARY_B: @@ -254,12 +245,12 @@ __objc_class_structure_encoding (Class class, char **type, int *size, int *current) { int i, ivar_count; - struct objc_ivar_list* ivars; + struct objc_ivar_list *ivars; - if (!class) + if (! class) { strcat (*type, "{"); - *current++; + (*current)++; return; } @@ -267,7 +258,7 @@ __objc_class_structure_encoding (Class class, char **type, int *size, __objc_class_structure_encoding (class->super_class, type, size, current); ivars = class->ivars; - if (!ivars) + if (! ivars) return; ivar_count = ivars->ivar_count; @@ -282,7 +273,7 @@ __objc_class_structure_encoding (Class class, char **type, int *size, { /* Increase the size of the encoding string so that it contains this ivar's type. */ - *size = ROUND(*current + len + 1, 10); + *size = ROUND (*current + len + 1, 10); *type = objc_realloc (*type, *size); } strcat (*type + *current, ivar_type); @@ -302,7 +293,7 @@ __objc_generate_gc_type_description (Class class) int type_size = 10, current; char *class_structure_type; - if (!CLS_ISCLASS(class)) + if (! CLS_ISCLASS (class)) return; /* We have to create a mask in which each bit counts for a pointer member. @@ -311,9 +302,9 @@ __objc_generate_gc_type_description (Class class) /* The number of bits in the mask is the size of an instance in bytes divided by the size of a pointer. */ - bits_no = (ROUND(class_get_instance_size (class), sizeof(void*)) - / sizeof (void*)); - size = ROUND(bits_no, BITS_PER_WORD) / BITS_PER_WORD; + bits_no = (ROUND (class_get_instance_size (class), sizeof (void *)) + / sizeof (void *)); + size = ROUND (bits_no, BITS_PER_WORD) / BITS_PER_WORD; mask = objc_atomic_malloc (size * sizeof (int)); memset (mask, 0, size * sizeof (int)); @@ -342,7 +333,7 @@ __objc_generate_gc_type_description (Class class) puts (""); #endif - class->gc_object_type = (void*)GC_make_descriptor (mask, bits_no); + class->gc_object_type = (void *) GC_make_descriptor (mask, bits_no); } @@ -370,17 +361,17 @@ __objc_ivar_pointer (const char *type) This operation only makes sense on instance variables that are pointers. */ void -class_ivar_set_gcinvisible (Class class, const char* ivarname, +class_ivar_set_gcinvisible (Class class, const char *ivarname, BOOL gc_invisible) { int i, ivar_count; - struct objc_ivar_list* ivars; + struct objc_ivar_list *ivars; - if (!class || !ivarname) + if (! class || ! ivarname) return; ivars = class->ivars; - if (!ivars) + if (! ivars) return; ivar_count = ivars->ivar_count; @@ -390,7 +381,7 @@ class_ivar_set_gcinvisible (Class class, const char* ivarname, struct objc_ivar *ivar = &(ivars->ivar_list[i]); const char *type; - if (!ivar->ivar_name || strcmp (ivar->ivar_name, ivarname)) + if (! ivar->ivar_name || strcmp (ivar->ivar_name, ivarname)) continue; assert (ivar->ivar_type); @@ -406,30 +397,34 @@ class_ivar_set_gcinvisible (Class class, const char* ivarname, if (*type == _C_GCINVISIBLE) { char *new_type; + size_t len; - if (gc_invisible || !__objc_ivar_pointer (type)) + if (gc_invisible || ! __objc_ivar_pointer (type)) return; /* The type of the variable already matches the requested gc_invisible type */ - /* The variable is gc_invisible and we have to reverse it */ - new_type = objc_atomic_malloc (strlen (ivar->ivar_type)); - strncpy (new_type, ivar->ivar_type, - (size_t)(type - ivar->ivar_type)); + /* The variable is gc_invisible so we make it gc visible. */ + new_type = objc_atomic_malloc (strlen(ivar->ivar_type)); + len = (type - ivar->ivar_type); + memcpy (new_type, ivar->ivar_type, len); + new_type[len] = 0; strcat (new_type, type + 1); ivar->ivar_type = new_type; } else { char *new_type; + size_t len; - if (!gc_invisible || !__objc_ivar_pointer (type)) + if (! gc_invisible || ! __objc_ivar_pointer (type)) return; /* The type of the variable already matches the requested gc_invisible type */ - /* The variable is gc visible and we have to make it gc_invisible */ - new_type = objc_malloc (strlen (ivar->ivar_type) + 2); - strncpy (new_type, ivar->ivar_type, - (size_t)(type - ivar->ivar_type)); + /* The variable is gc visible so we make it gc_invisible. */ + new_type = objc_malloc (strlen(ivar->ivar_type) + 2); + len = (type - ivar->ivar_type); + memcpy (new_type, ivar->ivar_type, len); + new_type[len] = 0; strcat (new_type, "!"); strcat (new_type, type); ivar->ivar_type = new_type; @@ -451,7 +446,7 @@ __objc_generate_gc_type_description (Class class __attribute__ ((__unused__))) } void class_ivar_set_gcinvisible (Class class __attribute__ ((__unused__)), - const char* ivarname __attribute__ ((__unused__)), + const char *ivarname __attribute__ ((__unused__)), BOOL gc_invisible __attribute__ ((__unused__))) { }