Skip to content

Commit

Permalink
Merge pull request #4 from ngrewe/nil_exception
Browse files Browse the repository at this point in the history
Fix throwing nil exceptions.
  • Loading branch information
davidchisnall committed Sep 7, 2015
2 parents 3443925 + 1ac1520 commit 27933a9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(TESTS
WeakReferences_arc.m
objc_msgSend.m
msgInterpose.m
NilException.m
MethodArguments.m
)

Expand Down
49 changes: 49 additions & 0 deletions Test/NilException.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "Test.h"


#ifdef __has_attribute
#if __has_attribute(objc_root_class)
__attribute__((objc_root_class))
#endif
#endif
@interface NSObject
{
Class isa;
}
@end

@implementation NSObject
+ (id)new
{
return class_createInstance(self, 0);
}
@end
int main(void)
{
BOOL caught_exception = NO;
@try
{
@throw(nil);
}
@catch (NSObject* o)
{
assert(0);
}
@catch (id x)
{
assert(nil == x);
caught_exception = YES;
}
assert(caught_exception == YES);
caught_exception = NO;
@try
{
@throw(nil);
}
@catch (...)
{
caught_exception = YES;
}
assert(caught_exception == YES);
return 0;
}
5 changes: 4 additions & 1 deletion eh_personality.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ static inline _Unwind_Reason_Code internal_objc_personality(int version,
else if (!foreignException)
{
ex = objc_exception_from_header(exceptionObject);
thrown_class = classForObject(ex->object);
if (ex->object != nil)
{
thrown_class = classForObject(ex->object);
}
}
else if (_objc_class_for_boxing_foreign_exception)
{
Expand Down

0 comments on commit 27933a9

Please sign in to comment.