Skip to content

Commit

Permalink
Exceptions are now autoreleased.
Browse files Browse the repository at this point in the history
This is safe as an "exception loop" can't happen, since if allocating
an exception fails, it throws an OFAllocFailedException which is
preallocated and can always be thrown.

So, the worst case would be that an autorelease of an exception fails,
triggering an OFOutOfMemoryException for which there is no memory,
resulting in an OFAllocFailedException to be thrown.
  • Loading branch information
Midar committed Sep 22, 2011
1 parent 868289a commit 9b5e368
Show file tree
Hide file tree
Showing 148 changed files with 1,601 additions and 1,524 deletions.
4 changes: 2 additions & 2 deletions src/OFApplication.m
Expand Up @@ -267,8 +267,8 @@ - (void)dealloc
@implementation OFObject (OFApplicationDelegate)
- (void)applicationDidFinishLaunching
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- (void)applicationWillTerminate
Expand Down
48 changes: 25 additions & 23 deletions src/OFArray.m
Expand Up @@ -105,8 +105,8 @@ - (void)release

- (void)dealloc
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
[super dealloc]; /* Get rid of a stupid warning */
}
@end
Expand Down Expand Up @@ -171,8 +171,8 @@ + (void)initialize
if (isa == [OFArray class]) {
Class c = isa;
[self release];
@throw [OFNotImplementedException newWithClass: c
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: c
selector: _cmd];
}

return [super init];
Expand Down Expand Up @@ -201,47 +201,47 @@ + (void)initialize
{
Class c = isa;
[self release];
@throw [OFNotImplementedException newWithClass: c
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: c
selector: _cmd];
}

- initWithArray: (OFArray*)array
{
Class c = isa;
[self release];
@throw [OFNotImplementedException newWithClass: c
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: c
selector: _cmd];
}

- initWithCArray: (id*)objects
{
Class c = isa;
[self release];
@throw [OFNotImplementedException newWithClass: c
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: c
selector: _cmd];
}

- initWithCArray: (id*)objects
length: (size_t)length
{
Class c = isa;
[self release];
@throw [OFNotImplementedException newWithClass: c
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: c
selector: _cmd];
}

- initWithSerialization: (OFXMLElement*)element
{
Class c = isa;
[self release];
@throw [OFNotImplementedException newWithClass: c
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: c
selector: _cmd];
}

- (size_t)count
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- (void)getObjects: (id*)buffer
Expand Down Expand Up @@ -282,8 +282,8 @@ - (id*)cArray

- (id)objectAtIndex: (size_t)index
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- (size_t)indexOfObject: (id)object
Expand Down Expand Up @@ -531,7 +531,7 @@ - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
size_t count = [self count];

if (count > INT_MAX)
@throw [OFOutOfRangeException newWithClass: isa];
@throw [OFOutOfRangeException exceptionWithClass: isa];

if (state->state >= count)
return 0;
Expand Down Expand Up @@ -668,8 +668,9 @@ - (void)dealloc
- (id)nextObject
{
if (mutationsPtr != NULL && *mutationsPtr != mutations)
@throw [OFEnumerationMutationException newWithClass: isa
object: array];
@throw [OFEnumerationMutationException
exceptionWithClass: isa
object: array];

if (position < count)
return [array objectAtIndex: position++];
Expand All @@ -680,8 +681,9 @@ - (id)nextObject
- (void)reset
{
if (mutationsPtr != NULL && *mutationsPtr != mutations)
@throw [OFEnumerationMutationException newWithClass: isa
object: array];
@throw [OFEnumerationMutationException
exceptionWithClass: isa
object: array];

position = 0;
}
Expand Down
9 changes: 5 additions & 4 deletions src/OFArray_adjacent.m
Expand Up @@ -189,8 +189,9 @@ @implementation OFArray_adjacent
if ((![[element name] isEqual: @"OFArray"] &&
![[element name] isEqual: @"OFMutableArray"]) ||
![[element namespace] isEqual: OF_SERIALIZATION_NS])
@throw [OFInvalidArgumentException newWithClass: isa
selector: _cmd];
@throw [OFInvalidArgumentException
exceptionWithClass: isa
selector: _cmd];

enumerator = [[element children] objectEnumerator];
pool2 = [[OFAutoreleasePool alloc] init];
Expand Down Expand Up @@ -239,7 +240,7 @@ - (void)getObjects: (id*)buffer
size_t i, count = [array count];

if (range.start + range.length > count)
@throw [OFOutOfRangeException newWithClass: isa];
@throw [OFOutOfRangeException exceptionWithClass: isa];

for (i = 0; i < range.length; i++)
buffer[i] = cArray[range.start + i];
Expand Down Expand Up @@ -281,7 +282,7 @@ - (OFArray*)objectsInRange: (of_range_t)range
count = [array count];

if (range.start + range.length > count)
@throw [OFOutOfRangeException newWithClass: isa];
@throw [OFOutOfRangeException exceptionWithClass: isa];

return [OFArray arrayWithCArray: (id*)[array cArray] + range.start
length: range.length];
Expand Down
6 changes: 3 additions & 3 deletions src/OFArray_subarray.m
Expand Up @@ -60,7 +60,7 @@ - (size_t)count
- (id)objectAtIndex: (size_t)index
{
if (index >= range.length)
@throw [OFOutOfRangeException newWithClass: isa];
@throw [OFOutOfRangeException exceptionWithClass: isa];

return [array objectAtIndex: index + range.start];
}
Expand All @@ -69,7 +69,7 @@ - (void)getObjects: (id*)buffer
inRange: (of_range_t)range_
{
if (range_.start + range_.length > range.length)
@throw [OFOutOfRangeException newWithClass: isa];
@throw [OFOutOfRangeException exceptionWithClass: isa];

range_.start += range.start;

Expand Down Expand Up @@ -110,7 +110,7 @@ - (size_t)indexOfObjectIdenticalTo: (id)object
- (OFArray*)objectsInRange: (of_range_t)range_
{
if (range_.start + range_.length > range.length)
@throw [OFOutOfRangeException newWithClass: isa];
@throw [OFOutOfRangeException exceptionWithClass: isa];

range_.start += range.start;

Expand Down
18 changes: 10 additions & 8 deletions src/OFAutoreleasePool.m
Expand Up @@ -41,7 +41,8 @@ + (void)initialize
return;

if (!of_tlskey_new(&firstKey) || !of_tlskey_new(&lastKey))
@throw [OFInitializationFailedException newWithClass: self];
@throw [OFInitializationFailedException
exceptionWithClass: self];
}
#endif

Expand All @@ -66,7 +67,8 @@ + (void)addObject: (id)object

if (lastPool == nil) {
[object release];
@throw [OFInitializationFailedException newWithClass: self];
@throw [OFInitializationFailedException
exceptionWithClass: self];
}

@try {
Expand Down Expand Up @@ -97,7 +99,7 @@ + (void)_releaseAll

if (!of_tlskey_set(lastKey, self))
@throw [OFInitializationFailedException
newWithClass: isa];
exceptionWithClass: isa];
#else
previousPool = lastPool;
lastPool = self;
Expand All @@ -108,7 +110,7 @@ + (void)_releaseAll
if (!of_tlskey_set(firstKey, self)) {
of_tlskey_set(lastKey, previousPool);
@throw [OFInitializationFailedException
newWithClass: isa];
exceptionWithClass: isa];
}
#else
firstPool = self;
Expand Down Expand Up @@ -209,13 +211,13 @@ - (void)dealloc

- retain
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- autorelease
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}
@end
47 changes: 25 additions & 22 deletions src/OFBlock.m
Expand Up @@ -352,19 +352,22 @@ + (void)load
* this workaround should be fine.
*/
if ((tmp = objc_allocateClassPair(self, "OFStackBlock", 0)) == NULL)
@throw [OFInitializationFailedException newWithClass: self];
@throw [OFInitializationFailedException
exceptionWithClass: self];
memcpy(&_NSConcreteStackBlock, tmp, sizeof(_NSConcreteStackBlock));
free(tmp);
objc_registerClassPair((Class)&_NSConcreteStackBlock);

if ((tmp = objc_allocateClassPair(self, "OFGlobalBlock", 0)) == NULL)
@throw [OFInitializationFailedException newWithClass: self];
@throw [OFInitializationFailedException
exceptionWithClass: self];
memcpy(&_NSConcreteGlobalBlock, tmp, sizeof(_NSConcreteGlobalBlock));
free(tmp);
objc_registerClassPair((Class)&_NSConcreteGlobalBlock);

if ((tmp = objc_allocateClassPair(self, "OFMallocBlock", 0)) == NULL)
@throw [OFInitializationFailedException newWithClass: self];
@throw [OFInitializationFailedException
exceptionWithClass: self];
memcpy(&_NSConcreteMallocBlock, tmp, sizeof(_NSConcreteMallocBlock));
free(tmp);
objc_registerClassPair((Class)&_NSConcreteMallocBlock);
Expand All @@ -379,60 +382,60 @@ + (void)initialize
for (i = 0; i < NUM_SPINLOCKS; i++)
if (!of_spinlock_new(&spinlocks[i]))
@throw [OFInitializationFailedException
newWithClass: self];
exceptionWithClass: self];
}
#endif

+ alloc
{
@throw [OFNotImplementedException newWithClass: self
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: self
selector: _cmd];
}

- init
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- (void)addMemoryToPool: (void*)ptr
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- (void*)allocMemoryWithSize: (size_t)size
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- (void*)allocMemoryForNItems: (size_t)nitems
withSize: (size_t)size
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- (void*)resizeMemory: (void*)ptr
toSize: (size_t)size
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- (void*)resizeMemory: (void*)ptr
toNItems: (size_t)nitems
withSize: (size_t)size
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- (void)freeMemory: (void*)ptr
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
}

- retain
Expand Down Expand Up @@ -473,8 +476,8 @@ - (void)release

- (void)dealloc
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: isa
selector: _cmd];
[super dealloc]; /* Get rid of a stupid warning */
}
@end
Expand Down

0 comments on commit 9b5e368

Please sign in to comment.