From c76a86efad6926a428677bdfc2da9b001afc032b Mon Sep 17 00:00:00 2001 From: David Ayers Date: Wed, 21 Jul 2004 19:01:48 +0000 Subject: [PATCH] * EOControl/EONSAddOns.h/m (GDL2_ActivateCategory, GDL2_ActivateAllGDL2Categories) (GDL2_DumpMethodList): New functions. * EOControl/EOKeyValueCoding.m (initialize): Make order of initialization more thread safe. (NilToNull): Remove helper class. ([NSObject -unableToSetNilForKey:]): Implement. ([NSObject -GDL2KVCNSObjectICategoryID]): New method. ([NSObject +load]): Ditto. ([NSDictionary -GDL2KVCNSDictionaryICategoryID]): Ditto. ([NSDictionary +load]): Ditto. ([NSMutableDictionary -GDL2KVCNSDictionaryICategoryID]): Ditto. ([NSMutableDictionary +load]): Ditto. * EOControl/EOClassDescription.m ([NSObject -GDL2CDNSObjectICategoryID]): New method. ([NSObject +load]): New method. ([NSObject -validateValue:forKey:]) Introduce temporary variable to allow correct formatting. ([NSObject -snapshot]): Reformat log string. ([NSObject -addObject], [NSObject -removeObject]) ([NSObject _setObject], [NSObject -editingContext]): Reformat. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@19760 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 26 ++++++++++ EOControl/EOClassDescription.m | 33 +++++++++---- EOControl/EOKeyValueCoding.m | 90 +++++++++++++++------------------- EOControl/EONSAddOns.h | 8 +++ EOControl/EONSAddOns.m | 56 +++++++++++++++++++++ 5 files changed, 153 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index d67e7c8..e81175a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2004-06-21 David Ayers + + * EOControl/EONSAddOns.h/m + (GDL2_ActivateCategory, GDL2_ActivateAllGDL2Categories) + (GDL2_DumpMethodList): New functions. + + * EOControl/EOKeyValueCoding.m + (initialize): Make order of initialization more thread safe. + (NilToNull): Remove helper class. + ([NSObject -unableToSetNilForKey:]): Implement. + ([NSObject -GDL2KVCNSObjectICategoryID]): New method. + ([NSObject +load]): Ditto. + ([NSDictionary -GDL2KVCNSDictionaryICategoryID]): Ditto. + ([NSDictionary +load]): Ditto. + ([NSMutableDictionary -GDL2KVCNSDictionaryICategoryID]): Ditto. + ([NSMutableDictionary +load]): Ditto. + + * EOControl/EOClassDescription.m + ([NSObject -GDL2CDNSObjectICategoryID]): New method. + ([NSObject +load]): New method. + ([NSObject -validateValue:forKey:]) Introduce temporary variable + to allow correct formatting. + ([NSObject -snapshot]): Reformat log string. + ([NSObject -addObject], [NSObject -removeObject]) + ([NSObject _setObject], [NSObject -editingContext]): Reformat. + 2004-06-04 Simon Stapelton * EOControl/EOAndQualifier.m, diff --git a/EOControl/EOClassDescription.m b/EOControl/EOClassDescription.m index cf68964..1a23099 100644 --- a/EOControl/EOClassDescription.m +++ b/EOControl/EOClassDescription.m @@ -711,6 +711,16 @@ fromInsertionInEditingContext: (EOEditingContext *)anEditingContext @implementation NSObject (EOClassDescriptionPrimitives) +- (void)GDL2CDNSObjectICategoryID +{ +} + ++ (void)load +{ + GDL2_ActivateCategory("NSObject", + @selector(GDL2CDNSObjectICategoryID), YES); +} + // when you enable the NSDebugMLLogs here you will have a loop. dave - (EOClassDescription *)classDescription { @@ -891,13 +901,15 @@ fromInsertionInEditingContext: (EOEditingContext *)anEditingContext forKey: key]; if (exception) { + NSDictionary *userInfo + = [NSDictionary dictionaryWithObjectsAndKeys: + self, @"EOValidatedObjectUserInfoKey", + key, @"EOValidatedPropertyUserInfoKey", + nil]; + exception = [NSException exceptionWithName: [exception name] reason: [exception reason] - userInfo: [NSDictionary - dictionaryWithObjectsAndKeys: - self, @"EOValidatedObjectUserInfoKey", - key, @"EOValidatedPropertyUserInfoKey", - nil, nil]]; + userInfo: userInfo]; } if (exception == nil) @@ -1065,7 +1077,8 @@ fromInsertionInEditingContext: (EOEditingContext *)anEditingContext toOneRelationshipKeyCount = [toOneRelationshipKeys count]; toManyRelationshipKeyCount = [toManyRelationshipKeys count]; - NSDebugMLLog(@"gsdb", @"attributeKeyCount=%d toOneRelationshipKeyCount=%d toManyRelationshipKeyCount=%d", + NSDebugMLLog(@"gsdb", @"attributeKeyCount=%d toOneRelationshipKeyCount=%d " + @"toManyRelationshipKeyCount=%d", attributeKeyCount, toOneRelationshipKeyCount, toManyRelationshipKeyCount); @@ -1289,7 +1302,7 @@ fromInsertionInEditingContext: (EOEditingContext *)anEditingContext @implementation NSObject (EOKeyRelationshipManipulation) -- (void)addObject: object +- (void)addObject: (id)object toPropertyWithKey: (NSString *)key { const char *str = NULL; @@ -1389,7 +1402,7 @@ toPropertyWithKey: (NSString *)key EOFLOGObjectFnStop(); } -- (void)removeObject: object +- (void)removeObject: (id)object fromPropertyWithKey: (NSString *)key { //self valueForKey: @@ -1479,7 +1492,7 @@ toPropertyWithKey: (NSString *)key EOFLOGObjectFnStop(); } --(void)_setObject: (id)object +- (void)_setObject: (id)object forBothSidesOfRelationshipWithKey: (NSString*)key { //Near OK @@ -1819,7 +1832,7 @@ fromBothSidesOfRelationshipWithKey: (NSString *)key @implementation NSObject (_EOEditingContext) --(EOEditingContext*)editingContext +- (EOEditingContext*)editingContext { return [EOObserverCenter observerForObject: self ofClass: [EOEditingContext class]]; diff --git a/EOControl/EOKeyValueCoding.m b/EOControl/EOKeyValueCoding.m index 165d5b9..ec7fd58 100644 --- a/EOControl/EOKeyValueCoding.m +++ b/EOControl/EOKeyValueCoding.m @@ -80,9 +80,9 @@ initialize(void) { if (null == nil) { - null = [EONull null]; oaiSel = @selector(objectAtIndex:); strictWO = GSUseStrictWO451Compatibility(nil); + null = [EONull null]; } } @@ -90,64 +90,24 @@ initialize(void) of efficiency, we don't use the do {} while (0) pattern. */ #define INITIALIZE if (null == nil) initialize(); -/* - * This dummy class exists to provide a replacement implementation for - * NSObject -unableToSetNilForKey:, which calls -unableToSetNullForKey: - * as defined in WO4.5. We need this mechanism as a category cannot - * reliably override the category in gnustep-base or Foundation. - */ -@interface NilToNull : NSObject -@end -@interface NilToNull (SurrpressWarning) -- (void) unableToSetNullForKey: (NSString *)key; -@end -@implementation NilToNull + +@implementation NSObject (_EOKeyValueCodingCompatibility) + +- (void)GDL2KVCNSObjectICategoryID +{ +} + + (void)load { - Class cls; - SEL sel; - IMP imp; - GSMethod method; - - imp = NULL; - sel = @selector(unableToSetNilForKey:); - cls = GSClassFromName("NSObject"); - - method = GSGetInstanceMethodNotInherited(self, sel); - if (method != METHOD_NULL) - { - imp = method->method_imp; - } - else - { - fprintf(stderr, - "%s: Could not find method unableToSetNilForKey: in NilToNil!\n", - __FILE__); - abort(); - } - - method = GSGetInstanceMethodNotInherited(cls, sel); - if (method != METHOD_NULL) - { - method->method_imp = imp; - } - else - { - fprintf(stderr, - "%s: Could not find method unableToSetNilForKey: in NSObject!\n", - __FILE__); - abort(); - } - GSFlushMethodCacheForClass(cls); + GDL2_ActivateCategory("NSObject", + @selector(GDL2KVCNSObjectICategoryID), YES); } - (void) unableToSetNilForKey: (NSString *)key { [self unableToSetNullForKey: key]; } -@end -@implementation NSObject (_EOKeyValueCodingCompatibility) /* See EODeprecated.h. */ + (void) flushClassKeyBindings { @@ -184,6 +144,16 @@ initialize(void) @implementation NSArray (EOKeyValueCoding) +- (void)GDL2KVCNSArrayICategoryID +{ +} + ++ (void)load +{ + GDL2_ActivateCategory("NSArray", + @selector(GDL2KVCNSArrayICategoryID), YES); +} + /** * EOKeyValueCoding protocol
* This overrides NSObjects implementation of this method. @@ -497,6 +467,16 @@ initialize(void) @implementation NSDictionary (EOKeyValueCoding) +- (void)GDL2KVCNSDictionaryICategoryID +{ +} + ++ (void)load +{ + GDL2_ActivateCategory("NSDictionary", + @selector(GDL2KVCNSDictionaryICategoryID), YES); +} + /** * Returns the object stored in the dictionary for this key. * Unlike Foundation, this method may return objects for keys other than @@ -795,6 +775,16 @@ initialize(void) @implementation NSMutableDictionary (EOKVCGNUstepExtensions) +- (void)GDL2KVCNSMutableDictionaryICategoryID +{ +} + ++ (void)load +{ + GDL2_ActivateCategory("NSMutableDictionary", + @selector(GDL2KVCNSMutableDictionaryICategoryID), YES); +} + /** * Method to augment the NSKeyValueCoding implementation * to account for added functionality such as quoted key paths. diff --git a/EOControl/EONSAddOns.h b/EOControl/EONSAddOns.h index 30b739a..f5fbc89 100644 --- a/EOControl/EONSAddOns.h +++ b/EOControl/EONSAddOns.h @@ -46,9 +46,17 @@ : ( TYPE *)GSAutoreleasedBuffer((ID##_size) * sizeof( TYPE )); \ TYPE *ID = ID##_base; + GDL2CONTROL_EXPORT BOOL GSUseStrictWO451Compatibility(NSString *key); +GDL2CONTROL_EXPORT void +GDL2_ActivateCategory(const char *className, SEL sel, BOOL isInstance); + +GDL2CONTROL_EXPORT void +GDL2_ActivateAllGDL2Categories(void); + + @interface NSObject (NSObjectPerformingSelector) - (NSArray *)resultsOfPerformingSelector: (SEL)sel withEachObjectInArray: (NSArray *)array; diff --git a/EOControl/EONSAddOns.m b/EOControl/EONSAddOns.m index 40573c2..1b12211 100644 --- a/EOControl/EONSAddOns.m +++ b/EOControl/EONSAddOns.m @@ -90,6 +90,62 @@ GSUseStrictWO451Compatibility (NSString *key) return GSStrictWO451Flag; } +void +GDL2_DumpMethodList(Class cls, SEL sel, BOOL isInstance) +{ + void *iterator = 0; + GSMethodList mList; + + fprintf(stderr,"List for :%s %s (inst:%d)\n", + GSNameFromClass(cls), GSNameFromSelector(sel), isInstance); + while ((mList = GSMethodListForSelector(cls, sel, + &iterator, isInstance))) + { + GSMethod meth = GSMethodFromList(mList, sel, NO); + IMP imp = meth->method_imp; + + fprintf(stderr,"List: %p Meth: %p Imp: %p\n", + mList, meth, imp); + } + fprintf(stderr,"List finished\n"); fflush(stderr); +} + +void +GDL2_ActivateCategory(const char *className, SEL sel, BOOL isInstance) +{ + Class cls; + GSMethodList mList; + + cls = GSClassFromName(className); + mList = GSMethodListForSelector(cls, sel, 0, isInstance); + + GSRemoveMethodList(cls, mList, isInstance); + GSAddMethodList(cls, mList, isInstance); + + GSFlushMethodCacheForClass(cls); +} + +void +GDL2_ActivateAllGDL2Categories(void) +{ + /* EOKeyValueCoding */ + GDL2_ActivateCategory("NSObject", + @selector(GDL2KVCNSObjectICategoryID), YES); + GDL2_ActivateCategory("NSArray", + @selector(GDL2KVCNSArrayICategoryID), YES); + GDL2_ActivateCategory("NSDictionary", + @selector(GDL2KVCNSDictionaryICategoryID), YES); + GDL2_ActivateCategory("NSMutableDictionary", + @selector(GDL2KVCNSMutableDictionaryICategoryID), YES); + + /* EOClassDescription */ + GDL2_ActivateCategory("NSObject", + @selector(GDL2CDNSObjectICategoryID), YES); + +} + + + @implementation NSObject (NSObjectPerformingSelector) - (NSArray*)resultsOfPerformingSelector: (SEL)sel