From d6d1029a3e14e226602e4bdfeaa3e9992e83a686 Mon Sep 17 00:00:00 2001 From: Manuel Guesdon Date: Tue, 23 Aug 2005 14:40:44 +0000 Subject: [PATCH] * EOControl/EOGenericRecord.m: fix -willChange call (don't call it for takeStoredValue:forKey and for -setXX method). * EOControl/EOClassDescription.m: check if value is not already set before adding/setting it in _setObject:forBothSidesOfRelationshipWithKey: and addObject:toBothSidesOfRelationshipWithKey: * EOAccess/EOAttribute.m: log in -validateValue: git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@21669 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 10 ++++ EOAccess/EOAttribute.m | 4 ++ EOControl/EOClassDescription.m | 95 +++++++++++++++------------------- EOControl/EOGenericRecord.m | 41 +++++++++++---- 4 files changed, 88 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index 276d082..862880a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-08-23 Manuel Guesdon + + * EOControl/EOGenericRecord.m: fix -willChange call (don't call + it for takeStoredValue:forKey and for -setXX method). + * EOControl/EOClassDescription.m: check if value is not + already set before adding/setting it in + _setObject:forBothSidesOfRelationshipWithKey: and + addObject:toBothSidesOfRelationshipWithKey: + * EOAccess/EOAttribute.m: log in -validateValue: + 2005-08-17 David Ayers * COPYING.LIB: Update to LGPL 2.1. diff --git a/EOAccess/EOAttribute.m b/EOAccess/EOAttribute.m index e4e1b87..e6cfa5d 100644 --- a/EOAccess/EOAttribute.m +++ b/EOAccess/EOAttribute.m @@ -1596,6 +1596,8 @@ More details: { NSException *exception=nil; + EOFLOGObjectFnStart(); + NSAssert(valueP, @"No value pointer"); NSDebugMLog(@"In EOAttribute validateValue: value (class=%@) = %@ attribute = %@", @@ -1797,6 +1799,8 @@ More details: } } + EOFLOGObjectFnStop(); + return exception; } diff --git a/EOControl/EOClassDescription.m b/EOControl/EOClassDescription.m index 0f1b3e2..54f6c7f 100644 --- a/EOControl/EOClassDescription.m +++ b/EOControl/EOClassDescription.m @@ -1211,7 +1211,7 @@ fromInsertionInEditingContext: (EOEditingContext *)anEditingContext NSDebugMLLog(@"gsdb", @"TOMANY snap=%p key=%@ ==> value %p=%@", snapshot, key, value, value); - + value = AUTORELEASE([(NSArray *)value shallowCopy]); NSDebugMLLog(@"gsdb", @"TOMANY snap=%p key=%@ ==> value %p=%@", @@ -1475,6 +1475,10 @@ toPropertyWithKey: (NSString *)key } else { + NSDebugMLLog(@"gsdb", + @"Object %p not already in too many val=%@ (%@)", + object, val, [val class]); + if ([val isKindOfClass: GDL2_NSMutableArrayClass]) { EOFLOGObjectLevel(@"gsdb", @"to many2"); @@ -1619,10 +1623,9 @@ toPropertyWithKey: (NSString *)key forBothSidesOfRelationshipWithKey: (NSString*)key { //Near OK - NSString *inverseKey; - id oldObject; EOFLOGObjectFnStart(); + NSDebugMLLog(@"gsdb", @"self=%@", self); NSDebugMLLog(@"gsdb", @"object=%@", object); NSDebugMLLog(@"gsdb", @"key=%@", key); @@ -1633,51 +1636,33 @@ forBothSidesOfRelationshipWithKey: (NSString*)key } else { - inverseKey = [self inverseForRelationshipKey:key]; - NSDebugMLLog(@"gsdb", @"inverseKey=%@", inverseKey); - - oldObject = [self valueForKey: key]; + id oldObject = [self valueForKey: key]; NSDebugMLLog(@"gsdb", @"oldObject=%@", oldObject); - if (inverseKey) + if (object!=oldObject) // Don't put it again if it is already set { - if (oldObject==GDL2_EONull) - { - NSWarnMLog(@"Warning: oldObject is an EONull. self=%@ key=%@ object=%@",self,key,object); - } - else - { - [oldObject removeObject: self - fromPropertyWithKey: inverseKey]; - [object addObject: self - toPropertyWithKey: inverseKey]; - /* if ([object isToManyKey:inverseKey]) - { - //?? - EOFLOGObjectLevel(@"gsdb",@"Inverse is to many"); - [oldObject removeObject:self - fromPropertyWithKey:inverseKey]; - [object addObject:self - toPropertyWithKey:inverseKey]; - } - else - { - EOFLOGObjectLevel(@"gsdb",@"Inverse is not to many"); - //OK - //MIRKO if ((inverseKey = [oldObject inverseForRelationshipKey:key])) - //MIRKO [oldObject removeObject:self - // fromPropertyWithKey:inverseKey]; - [oldObject takeValue:nil - forKey:inverseKey]; - [object takeValue:self - forKey:inverseKey]; - }; - */ - } - } + NSString *inverseKey = NULL; + inverseKey = [self inverseForRelationshipKey:key]; + NSDebugMLLog(@"gsdb", @"inverseKey=%@", inverseKey); - [self takeValue: object - forKey: key]; + if (inverseKey) + { + if (oldObject==GDL2_EONull) + { + NSWarnMLog(@"Warning: oldObject is an EONull. self=%@ key=%@ object=%@",self,key,object); + } + else + { + [oldObject removeObject: self + fromPropertyWithKey: inverseKey]; + [object addObject: self + toPropertyWithKey: inverseKey]; + } + } + + [self takeValue: object + forKey: key]; + } } NSDebugMLLog(@"gsdb", @"self=%@", self); @@ -1741,16 +1726,20 @@ toBothSidesOfRelationshipWithKey: (NSString *)key NSDebugMLLog(@"gsdb", @"oldObject=%@", oldObject); - if (oldObject) + // Don't put it again if it already set + if (object!=oldObject) { - //TODO VERIFY - [object removeObject:oldObject - fromPropertyWithKey:inverseKey]; - } - - // Just set self into object relationship property - [object takeValue: self - forKey: inverseKey]; + if (oldObject) + { + //TODO VERIFY + [object removeObject:oldObject + fromPropertyWithKey:inverseKey]; + } + + // Just set self into object relationship property + [object takeValue: self + forKey: inverseKey]; + }; } } } diff --git a/EOControl/EOGenericRecord.m b/EOControl/EOGenericRecord.m index f8aa696..b02454a 100644 --- a/EOControl/EOGenericRecord.m +++ b/EOControl/EOGenericRecord.m @@ -307,8 +307,6 @@ static const char _c_id[2] = { _C_ID, 0 }; @"Super InstanceVar named %@: offset=%u", aKey, offset); - [self willChange]; - if (offset == UINT_MAX) { if (anObject) @@ -724,8 +722,12 @@ inline BOOL infoForInstanceVariableWithImpPtr(id object,GDL2IMP_BOOL* impPtr, - (void)smartTakeValue: (id)anObject forKey: (NSString *)aKey { - BOOL isToMany = [[classDescription toManyRelationshipKeys] - containsObject: aKey]; + BOOL isToMany = NO; + + EOFLOGObjectFnStartCond(@"EOGenericRecordKVC"); + + isToMany=[[classDescription toManyRelationshipKeys] + containsObject: aKey]; //NSDebugMLog(@"aKey=%@ rel=%@ anObject=%@", aKey, rel, anObject); //NSDebugMLog(@"[rel isBidirectional]=%d", [rel isBidirectional]); @@ -755,6 +757,8 @@ inline BOOL infoForInstanceVariableWithImpPtr(id object,GDL2IMP_BOOL* impPtr, else [self takeValue: anObject forKey: aKey]; + + EOFLOGObjectFnStopCond(@"EOGenericRecordKVC"); } //MG#if !FOUNDATION_HAS_KVC @@ -783,6 +787,10 @@ inline BOOL infoForInstanceVariableWithImpPtr(id object,GDL2IMP_BOOL* impPtr, GDL2IMP_BOOL rtsIMP=NULL; GDL2IMP_BOOL infoVarIMP=NULL; + // We'll call willChange if we modify ivar directly or call a _setMethod + // otherwise, the setMethod should do it + BOOL shouldCallWillChange=NO; //OXYMIUM + strcpy(buf, "_set"); [aKey getCString: &buf[4]]; lo = buf[4]; @@ -807,8 +815,12 @@ inline BOOL infoForInstanceVariableWithImpPtr(id object,GDL2IMP_BOOL* impPtr, aKey, buf); sel = GSSelectorFromName(buf); - if (sel == 0 || - GDL2_RespondsToSelectorWithImpPtr(self,&rtsIMP,sel) == NO) + if (sel != 0 && + GDL2_RespondsToSelectorWithImpPtr(self,&rtsIMP,sel) == YES) + { + shouldCallWillChange=YES; + } + else { sel = 0; @@ -832,7 +844,12 @@ inline BOOL infoForInstanceVariableWithImpPtr(id object,GDL2IMP_BOOL* impPtr, nil, // stringName &type, // retType &size, // retSize - &off)==NO) // retOffset + &off)==YES) // retOffset + { + // We'll call willChange + shouldCallWillChange=YES; + } + else { // Test key EOFLOGObjectLevelArgs(@"EOGenericRecordKVC", @@ -849,14 +866,20 @@ inline BOOL infoForInstanceVariableWithImpPtr(id object,GDL2IMP_BOOL* impPtr, &type, // retType &size, // retSize &off); // retOffset + // We'll call willChange + shouldCallWillChange=YES; } } } } EOFLOGObjectLevelArgs(@"EOGenericRecordKVC", - @"aKey=%@ sel=%@ offset=%u", - aKey, NSStringFromSelector(sel), off); + @"aKey=%@ sel=%@ offset=%u shouldCallWillChange=%d", + aKey, NSStringFromSelector(sel), off, + shouldCallWillChange); + + if (shouldCallWillChange) + [self willChange]; [self _setValueForKey: aKey object: anObject