X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libobjc%2Fgc.c;h=d009230b78fc04b6d456dcbe50faa8f61324a728;hb=9a436c591beed49dcb370fcc9f9bbf6c8917f1fd;hp=399d1aa8d734b84b891433f869676bf584228344;hpb=e23e7a9155a79d326a25567faa2d6b870d5f3423;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libobjc/gc.c b/libobjc/gc.c index 399d1aa8d73..d009230b78f 100644 --- a/libobjc/gc.c +++ b/libobjc/gc.c @@ -1,12 +1,13 @@ /* Basic data types for Objective C. - Copyright (C) 1998, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 1998, 2002, 2004, 2005, 2006, 2009, 2010 + Free Software Foundation, Inc. Contributed by Ovidiu Predescu. This file is part of GCC. 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) +the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, @@ -14,26 +15,27 @@ 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 GCC; see the file COPYING. If not, write to -the Free Software Foundation, 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. */ +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. -/* As a special exception, if you link this library with files - compiled with GCC to produce an executable, this does not cause - the resulting executable to be covered by the GNU General Public License. - This exception does not however invalidate any other reasons why - the executable file might be covered by the GNU General Public License. */ +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ -#include "tconfig.h" +#include "objc-private/common.h" #include "objc/objc.h" -#include "objc/encoding.h" +#if OBJC_WITH_GC + +#include "tconfig.h" #include +#include /* For isdigit. */ #include #include - -#if OBJC_WITH_GC +#include "objc/runtime.h" +#include "objc-private/module-abi-8.h" #include #include @@ -302,7 +304,7 @@ __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 *)) + bits_no = (ROUND (class_getInstanceSize (class), sizeof (void *)) / sizeof (void *)); size = ROUND (bits_no, BITS_PER_WORD) / BITS_PER_WORD; mask = objc_atomic_malloc (size * sizeof (int)); @@ -397,32 +399,40 @@ 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)) 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)) 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)); - strcat (new_type, "!"); - strcat (new_type, type); + /* The variable is gc visible so we make it gc_invisible. */ + new_type = objc_malloc (strlen(ivar->ivar_type) + 2); + + /* Copy the variable name. */ + len = (type - ivar->ivar_type); + memcpy (new_type, ivar->ivar_type, len); + /* Add '!'. */ + new_type[len++] = _C_GCINVISIBLE; + /* Copy the original types. */ + strcpy (new_type + len, type); + ivar->ivar_type = new_type; }