fix erroneous casts

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37251 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-10-18 07:25:32 +00:00
parent b6fd2dd2ff
commit d4ac64d355
2 changed files with 60 additions and 23 deletions

View file

@ -1,3 +1,7 @@
2013-10-18 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPredicate.m: Fix faulty casts of immutable array to mutable.
2013-10-17 Eric Wasylishen <ewasylishen@gmail.com> 2013-10-17 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSException.m: * Source/NSException.m:

View file

@ -405,21 +405,23 @@ extern void GSPropertyListMake(id,NSDictionary*,BOOL,BOOL,unsigned,id*);
+ (NSPredicate *) andPredicateWithSubpredicates: (NSArray *)list + (NSPredicate *) andPredicateWithSubpredicates: (NSArray *)list
{ {
return AUTORELEASE([[GSAndCompoundPredicate alloc] initWithType: NSAndPredicateType return AUTORELEASE([[GSAndCompoundPredicate alloc]
subpredicates: list]); initWithType: NSAndPredicateType subpredicates: list]);
} }
+ (NSPredicate *) notPredicateWithSubpredicate: (NSPredicate *)predicate + (NSPredicate *) notPredicateWithSubpredicate: (NSPredicate *)predicate
{ {
NSArray *list;
list = [NSArray arrayWithObject: predicate];
return AUTORELEASE([[GSNotCompoundPredicate alloc] return AUTORELEASE([[GSNotCompoundPredicate alloc]
initWithType: NSNotPredicateType initWithType: NSNotPredicateType subpredicates: list]);
subpredicates: [NSArray arrayWithObject: predicate]]);
} }
+ (NSPredicate *) orPredicateWithSubpredicates: (NSArray *)list + (NSPredicate *) orPredicateWithSubpredicates: (NSArray *)list
{ {
return AUTORELEASE([[GSOrCompoundPredicate alloc] initWithType: NSOrPredicateType return AUTORELEASE([[GSOrCompoundPredicate alloc]
subpredicates: list]); initWithType: NSOrPredicateType subpredicates: list]);
} }
- (NSCompoundPredicateType) compoundPredicateType - (NSCompoundPredicateType) compoundPredicateType
@ -433,7 +435,7 @@ extern void GSPropertyListMake(id,NSDictionary*,BOOL,BOOL,unsigned,id*);
if ((self = [super init]) != nil) if ((self = [super init]) != nil)
{ {
_type = type; _type = type;
ASSIGN(_subs, list); ASSIGNCOPY(_subs, list);
} }
return self; return self;
} }
@ -458,7 +460,7 @@ extern void GSPropertyListMake(id,NSDictionary*,BOOL,BOOL,unsigned,id*);
{ {
unsigned int count = [_subs count]; unsigned int count = [_subs count];
NSMutableArray *esubs = [NSMutableArray arrayWithCapacity: count]; NSMutableArray *esubs = [NSMutableArray arrayWithCapacity: count];
unsigned int i; unsigned int i;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
@ -1827,28 +1829,44 @@ GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOption
&& [(NSCompoundPredicate *)r compoundPredicateType] && [(NSCompoundPredicate *)r compoundPredicateType]
== NSAndPredicateType) == NSAndPredicateType)
{ {
NSCompoundPredicate *right = (NSCompoundPredicate*)r;
// merge // merge
if ([l isKindOfClass:[NSCompoundPredicate class]] if ([l isKindOfClass:[NSCompoundPredicate class]]
&& [(NSCompoundPredicate *)l compoundPredicateType] && [(NSCompoundPredicate *)l compoundPredicateType]
== NSAndPredicateType) == NSAndPredicateType)
{ {
[(NSMutableArray *)[(NSCompoundPredicate *)l subpredicates] NSCompoundPredicate *left;
addObjectsFromArray: [(NSCompoundPredicate *)r subpredicates]]; NSMutableArray *subs;
left = (NSCompoundPredicate*)l;
subs = [[left subpredicates] mutableCopy];
[subs addObjectsFromArray: [right subpredicates]];
l = [NSCompoundPredicate andPredicateWithSubpredicates: subs];
[subs release];
} }
else else
{ {
[(NSMutableArray *)[(NSCompoundPredicate *)r subpredicates] NSMutableArray *subs;
insertObject: l atIndex: 0];
l = r; subs = [[right subpredicates] mutableCopy];
[subs insertObject: l atIndex: 0];
l = [NSCompoundPredicate andPredicateWithSubpredicates: subs];
[subs release];
} }
} }
else if ([l isKindOfClass: [NSCompoundPredicate class]] else if ([l isKindOfClass: [NSCompoundPredicate class]]
&& [(NSCompoundPredicate *)l compoundPredicateType] && [(NSCompoundPredicate *)l compoundPredicateType]
== NSAndPredicateType) == NSAndPredicateType)
{ {
// add to l NSCompoundPredicate *left;
[(NSMutableArray *)[(NSCompoundPredicate *)l subpredicates] NSMutableArray *subs;
addObject: r];
left = (NSCompoundPredicate*)l;
subs = [[left subpredicates] mutableCopy];
[subs addObject: r];
l = [NSCompoundPredicate andPredicateWithSubpredicates: subs];
[subs release];
} }
else else
{ {
@ -1905,27 +1923,42 @@ GSICUStringMatchesRegex(NSString *string, NSString *regex, NSStringCompareOption
&& [(NSCompoundPredicate *)r compoundPredicateType] && [(NSCompoundPredicate *)r compoundPredicateType]
== NSOrPredicateType) == NSOrPredicateType)
{ {
NSCompoundPredicate *right = (NSCompoundPredicate*)r;
// merge // merge
if ([l isKindOfClass: [NSCompoundPredicate class]] if ([l isKindOfClass: [NSCompoundPredicate class]]
&& [(NSCompoundPredicate *)l compoundPredicateType] && [(NSCompoundPredicate *)l compoundPredicateType]
== NSOrPredicateType) == NSOrPredicateType)
{ {
[(NSMutableArray *)[(NSCompoundPredicate *)l subpredicates] NSCompoundPredicate *left = (NSCompoundPredicate*)l;
addObjectsFromArray: [(NSCompoundPredicate *)r subpredicates]]; NSMutableArray *subs;
subs = [[left subpredicates] mutableCopy];
[subs addObjectsFromArray: [right subpredicates]];
l = [NSCompoundPredicate orPredicateWithSubpredicates: subs];
[subs release];
} }
else else
{ {
[(NSMutableArray *)[(NSCompoundPredicate *)r subpredicates] NSMutableArray *subs;
insertObject: l atIndex: 0];
l = r; subs = [[right subpredicates] mutableCopy];
[subs insertObject: l atIndex: 0];
l = [NSCompoundPredicate orPredicateWithSubpredicates: subs];
[subs release];
} }
} }
else if ([l isKindOfClass: [NSCompoundPredicate class]] else if ([l isKindOfClass: [NSCompoundPredicate class]]
&& [(NSCompoundPredicate *)l compoundPredicateType] && [(NSCompoundPredicate *)l compoundPredicateType]
== NSOrPredicateType) == NSOrPredicateType)
{ {
[(NSMutableArray *) [(NSCompoundPredicate *) l subpredicates] NSCompoundPredicate *left = (NSCompoundPredicate*)l;
addObject:r]; NSMutableArray *subs;
subs = [[left subpredicates] mutableCopy];
[subs addObject:r];
l = [NSCompoundPredicate orPredicateWithSubpredicates: subs];
[subs release];
} }
else else
{ {