From b04641a6a865c1862eb8b2c687f22e4295c88568 Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 8 Mar 2011 12:49:34 +0000 Subject: [PATCH] fix for non-fragile abi git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32501 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++++++ Source/GSInternal.h | 15 ++++++++++++++- Source/NSDateFormatter.m | 4 +--- Source/NSNumberFormatter.m | 4 +--- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2106ceff5..bed913acc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-03-08 Richard Frith-Macdonald + + * Source/GSInternal.h: + * Source/NSDateFormatter.m: + * Source/NSNumberFormatter.m: + Fix for object copying in non-fragile-ivar build spotted by + Chris Armstrong. + 2011-03-06 Richard Frith-Macdonald * Source/Additions/GSObjCRuntime.m: diff --git a/Source/GSInternal.h b/Source/GSInternal.h index 40aecb4d7..0bd438f9d 100644 --- a/Source/GSInternal.h +++ b/Source/GSInternal.h @@ -67,6 +67,9 @@ * You use GS_CREATE_INTERNAL() in your intialiser to create the object * holding the internal instance variables, and GS_DESTROY_INTERNAL() to * get rid of that object in your -dealloc method. + * You use GS_COPY_INTERNAL() in your implementations of -copyWithZone: + * and -mutableCopyWithZone: in order to get the default copying behavior + * for the internal class (a single copy of all the instance variables). * * Instance variables are referenced using the 'internal->ivar' suntax or * the GSIV(classname,object,ivar) macro. @@ -99,11 +102,19 @@ _internal = [name ## Internal new]; #define GS_DESTROY_INTERNAL(name) \ if (nil != _internal) {[_internal release]; _internal = nil; } +/* Create a new copy of the current object's internal class and place + * it in the destination instance. This poduces a bitwise copy, and you + * may wish to perform further action to deepen the copy after using this + * macro. + * Use this only where D is a new copy of the current instance. + */ +#define GS_COPY_INTERNAL(D,Z) (D)->_internal = NSCopyObject(_internal, 0, (Z)); + #undef internal #define internal ((GSInternal*)_internal) #undef GSIVar -#define GSIVar(X,Y) (((GSInternal*)(X->_internal))->Y) +#define GSIVar(X,Y) (((GSInternal*)((X)->_internal))->Y) #else /* GS_NONFRAGILE */ @@ -116,6 +127,8 @@ if (nil != _internal) {[_internal release]; _internal = nil; } #define GS_DESTROY_INTERNAL(name) +#define GS_COPY_INTERNAL(D,Z) + /* Define constant to reference internal ivars. */ #undef internal diff --git a/Source/NSDateFormatter.m b/Source/NSDateFormatter.m index 2d7f5b634..7258d86e6 100644 --- a/Source/NSDateFormatter.m +++ b/Source/NSDateFormatter.m @@ -160,9 +160,7 @@ static NSDateFormatterBehavior _defaultBehavior = 0; IF_NO_GC(RETAIN(o->_dateFormat)); if (0 != internal) { - o->GS_CREATE_INTERNAL(NSDateFormatter) - - memcpy(o->_internal, internal, sizeof(NSDateFormatterInternal)); + GS_COPY_INTERNAL(o, zone) IF_NO_GC(RETAIN(GSIVar(o,_locale));) #if GS_USE_ICU == 1 { diff --git a/Source/NSNumberFormatter.m b/Source/NSNumberFormatter.m index 1b3682599..088fda607 100644 --- a/Source/NSNumberFormatter.m +++ b/Source/NSNumberFormatter.m @@ -303,9 +303,7 @@ static NSUInteger _defaultBehavior = NSNumberFormatterBehavior10_4; IF_NO_GC(RETAIN(o->_attributedStringForZero);) if (0 != internal) { - o->_internal = GS_CREATE_INTERNAL(NSNumberFormatter) - - memcpy(o->_internal, internal, sizeof(NSNumberFormatterInternal)); + GS_COPY_INTERNAL(o, zone) IF_NO_GC(RETAIN(GSIVar(o,_locale));) #if GS_USE_ICU == 1 {