@@ -50,10 +50,15 @@ arguments: arguments] autorelease]; va_end(arguments); return ret; } + ++ arrayWithArray: (OFArray*)array +{ + return [[[self alloc] initWithArray: array] autorelease]; +} + arrayWithCArray: (id*)objects { return [[[self alloc] initWithCArray: objects] autorelease]; } @@ -121,10 +126,46 @@ while ((object = va_arg(arguments, id)) != nil) { [array addItem: &object]; [object retain]; } } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithArray: (OFArray*)array_ +{ + id *cArray; + size_t i, count; + + self = [self init]; + + @try { + cArray = [array_ cArray]; + count = [array_ count]; + } @catch (id e) { + [self release]; + @throw e; + } + + @try { + for (i = 0; i < count; i++) + [cArray[i] retain]; + + [array addNItems: count + fromCArray: cArray]; + } @catch (id e) { + for (i = 0; i < count; i++) + [cArray[i] release]; + + /* Prevent double-release of objects */ + [array release]; + array = nil; + [self release]; @throw e; } return self; @@ -199,24 +240,11 @@ return [self retain]; } - mutableCopy { - OFArray *mutableCopy = [[OFMutableArray alloc] init]; - id *cArray; - size_t count, i; - - cArray = [array cArray]; - count = [array count]; - - [mutableCopy->array addNItems: count - fromCArray: cArray]; - - for (i = 0; i < count; i++) - [cArray[i] retain]; - - return mutableCopy; + return [[OFMutableArray alloc] initWithArray: self]; } - (id)objectAtIndex: (size_t)index { return *((id*)[array itemAtIndex: index]);