Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ARC compile errors in a way that is compatible with non-ARC builds #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions DCIntrospect/ARCMacros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// ARCMacros.h
//
// Created by John Blanco on 1/28/2011.
// Rapture In Venice releases all rights to this code. Feel free use and/or copy it openly and freely!
//

#if !defined(__clang__) || __clang_major__ < 3
#ifndef __bridge
#define __bridge
#endif

#ifndef __bridge_retain
#define __bridge_retain
#endif

#ifndef __bridge_retained
#define __bridge_retained
#endif

#ifndef __autoreleasing
#define __autoreleasing
#endif

#ifndef __strong
#define __strong
#endif

#ifndef __unsafe_unretained
#define __unsafe_unretained
#endif

#ifndef __weak
#define __weak
#endif
#endif

#if __has_feature(objc_arc)
#define SAFE_ARC_PROP_RETAIN strong
#define SAFE_ARC_RETAIN(x) (x)
#define SAFE_ARC_RELEASE(x)
#define SAFE_ARC_AUTORELEASE(x) (x)
#define SAFE_ARC_BLOCK_COPY(x) (x)
#define SAFE_ARC_BLOCK_RELEASE(x)
#define SAFE_ARC_SUPER_DEALLOC()
#define SAFE_ARC_AUTORELEASE_POOL_START() @autoreleasepool {
#define SAFE_ARC_AUTORELEASE_POOL_END() }
#define SAFE_ARC_AUTORELEASE_POOL_DRAIN_AND_END() }
#else
#define SAFE_ARC_PROP_RETAIN retain
#define SAFE_ARC_RETAIN(x) ([(x) retain])
#define SAFE_ARC_RELEASE(x) ([(x) release])
#define SAFE_ARC_AUTORELEASE(x) ([(x) autorelease])
#define SAFE_ARC_BLOCK_COPY(x) (Block_copy(x))
#define SAFE_ARC_BLOCK_RELEASE(x) (Block_release(x))
#define SAFE_ARC_SUPER_DEALLOC() ([super dealloc])
#define SAFE_ARC_AUTORELEASE_POOL_START() NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#define SAFE_ARC_AUTORELEASE_POOL_END() [pool release];
#define SAFE_ARC_AUTORELEASE_POOL_DRAIN_AND_END() [pool drain];
#endif
2 changes: 2 additions & 0 deletions DCIntrospect/DCCrossHairView.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
@implementation DCCrossHairView
@synthesize color;

#if !__has_feature(objc_arc)
- (void)dealloc
{
[color release];
[super dealloc];
}
#endif

- (id)initWithFrame:(CGRect)frame color:(UIColor *)aColor
{
Expand Down
7 changes: 5 additions & 2 deletions DCIntrospect/DCFrameView.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

#import "DCFrameView.h"
#import "ARCMacros.h"

@implementation DCFrameView
@synthesize delegate;
Expand All @@ -13,6 +14,7 @@ @implementation DCFrameView
@synthesize rectsToOutline;
@synthesize touchPointView;

#if !__has_feature(objc_arc)
- (void)dealloc
{
self.delegate = nil;
Expand All @@ -21,6 +23,7 @@ - (void)dealloc

[super dealloc];
}
#endif

#pragma mark - Setup

Expand All @@ -33,7 +36,7 @@ - (id)initWithFrame:(CGRect)frame delegate:(id)aDelegate
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;

self.touchPointLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
self.touchPointLabel = SAFE_ARC_AUTORELEASE([[UILabel alloc] initWithFrame:CGRectZero]);
self.touchPointLabel.text = @"X 320 Y 480";
self.touchPointLabel.font = [UIFont boldSystemFontOfSize:12.0f];
self.touchPointLabel.textAlignment = UITextAlignmentCenter;
Expand All @@ -46,7 +49,7 @@ - (id)initWithFrame:(CGRect)frame delegate:(id)aDelegate

self.rectsToOutline = [NSMutableArray array];

self.touchPointView = [[[DCCrossHairView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 17.0f, 17.0f) color:[UIColor blueColor]] autorelease];
self.touchPointView = SAFE_ARC_AUTORELEASE([[DCCrossHairView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 17.0f, 17.0f) color:[UIColor blueColor]]);
self.touchPointView.alpha = 0.0f;
[self addSubview:self.touchPointView];
}
Expand Down
30 changes: 16 additions & 14 deletions DCIntrospect/DCIntrospect.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

#import "DCIntrospect.h"
#import "ARCMacros.h"
#import <dlfcn.h>

#include <assert.h>
Expand Down Expand Up @@ -82,7 +83,7 @@ @implementation DCIntrospect

+ (void)load
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SAFE_ARC_AUTORELEASE_POOL_START();

NSString *simulatorRoot = [[[NSProcessInfo processInfo] environment] objectForKey:@"IPHONE_SIMULATOR_ROOT"];
if (simulatorRoot)
Expand All @@ -101,12 +102,12 @@ + (void)load
}
}

[pool drain];
SAFE_ARC_AUTORELEASE_POOL_DRAIN_AND_END();
}

static void *originalValueForKeyIMPKey = &originalValueForKeyIMPKey;

id UITextInputTraits_valueForKey(id self, SEL _cmd, NSString *key);
//id UITextInputTraits_valueForKey(id self, SEL _cmd, NSString *key);
id UITextInputTraits_valueForKey(id self, SEL _cmd, NSString *key)
{
static NSMutableSet *textInputTraitsProperties = nil;
Expand Down Expand Up @@ -186,16 +187,16 @@ - (void)start

if (!self.statusBarOverlay)
{
self.statusBarOverlay = [[[DCStatusBarOverlay alloc] init] autorelease];
self.statusBarOverlay = SAFE_ARC_AUTORELEASE([[DCStatusBarOverlay alloc] init]);
}

if (!self.inputTextView)
{
self.inputTextView = [[[UITextView alloc] initWithFrame:CGRectZero] autorelease];
self.inputTextView = SAFE_ARC_AUTORELEASE([[UITextView alloc] initWithFrame:CGRectZero]);
self.inputTextView.delegate = self;
self.inputTextView.autocorrectionType = UITextAutocorrectionTypeNo;
self.inputTextView.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.inputTextView.inputView = [[[UIView alloc] init] autorelease];
self.inputTextView.inputView = SAFE_ARC_AUTORELEASE([[UIView alloc] init]);
self.inputTextView.scrollsToTop = NO;
[mainWindow addSubview:self.inputTextView];
}
Expand Down Expand Up @@ -236,7 +237,7 @@ - (void)start
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateViews) name:UIDeviceOrientationDidChangeNotification object:nil];

if (!self.currentViewHistory)
self.currentViewHistory = [[[NSMutableArray alloc] init] autorelease];
self.currentViewHistory = SAFE_ARC_AUTORELEASE([[NSMutableArray alloc] init]);

NSLog(@"DCIntrospect is setup. %@ to start.", [kDCIntrospectKeysInvoke isEqualToString:@" "] ? @"Push the space bar" : [NSString stringWithFormat:@"Type '%@'", kDCIntrospectKeysInvoke]);
}
Expand All @@ -261,9 +262,9 @@ - (void)setInvokeGestureRecognizer:(UIGestureRecognizer *)newGestureRecognizer
UIWindow *mainWindow = [self mainWindow];
[mainWindow removeGestureRecognizer:invokeGestureRecognizer];

[invokeGestureRecognizer release];
SAFE_ARC_RELEASE(invokeGestureRecognizer);
invokeGestureRecognizer = nil;
invokeGestureRecognizer = [newGestureRecognizer retain];
invokeGestureRecognizer = SAFE_ARC_RETAIN(newGestureRecognizer);
[invokeGestureRecognizer addTarget:self action:@selector(invokeIntrospector)];
[mainWindow addGestureRecognizer:invokeGestureRecognizer];
}
Expand Down Expand Up @@ -730,7 +731,8 @@ - (void)updateFrameView
UIWindow *mainWindow = [self mainWindow];
if (!self.frameView)
{
self.frameView = [[[DCFrameView alloc] initWithFrame:(CGRect){ CGPointZero, mainWindow.frame.size } delegate:self] autorelease];
CGRect frame = (CGRect){ CGPointZero, mainWindow.frame.size };
self.frameView = SAFE_ARC_AUTORELEASE([[DCFrameView alloc] initWithFrame:frame delegate:self]);
[mainWindow addSubview:self.frameView];
self.frameView.alpha = 0.0f;
[self updateViews];
Expand Down Expand Up @@ -1294,13 +1296,13 @@ - (void)toggleHelp
{
self.statusBarOverlay.leftLabel.text = @"Help";
self.statusBarOverlay.rightLabel.text = @"Any key to close";
UIView *backingView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, mainWindow.frame.size.width, mainWindow.frame.size.height)] autorelease];
UIView *backingView = SAFE_ARC_AUTORELEASE([[UIView alloc] initWithFrame:CGRectMake(0, 0, mainWindow.frame.size.width, mainWindow.frame.size.height)]);
backingView.tag = 1548;
backingView.alpha = 0;
backingView.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.85f];
[mainWindow addSubview:backingView];

UIWebView *webView = [[[UIWebView alloc] initWithFrame:backingView.frame] autorelease];
UIWebView *webView = SAFE_ARC_AUTORELEASE([[UIWebView alloc] initWithFrame:backingView.frame]);
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
webView.delegate = self;
Expand Down Expand Up @@ -1560,7 +1562,7 @@ - (NSArray *)subclassesOfClass:(Class)parentClass
int numClasses = objc_getClassList(NULL, 0);
Class *classes = NULL;

classes = malloc(sizeof(Class) * numClasses);
classes = (Class *)malloc(sizeof(Class) * numClasses);
numClasses = objc_getClassList(classes, numClasses);

NSMutableArray *result = [NSMutableArray array];
Expand Down Expand Up @@ -1616,7 +1618,7 @@ - (NSMutableArray *)viewsAtPoint:(CGPoint)touchPoint inView:(UIView *)view
}
}

return [views autorelease];
return SAFE_ARC_AUTORELEASE(views);
}

- (void)fadeView:(UIView *)view toAlpha:(CGFloat)alpha
Expand Down
11 changes: 7 additions & 4 deletions DCIntrospect/DCStatusBarOverlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
//

#import "DCStatusBarOverlay.h"
#import "ARCMacros.h"

@implementation DCStatusBarOverlay
@synthesize leftLabel, rightLabel;

#if !__has_feature(objc_arc)
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
Expand All @@ -18,6 +20,7 @@ - (void)dealloc

[super dealloc];
}
#endif

#pragma mark Setup

Expand All @@ -39,25 +42,25 @@ - (id)init
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.frame];
backgroundImageView.image = [[UIImage imageNamed:@"statusBarBackground.png"] stretchableImageWithLeftCapWidth:2.0f topCapHeight:0.0f];
[self addSubview:backgroundImageView];
[backgroundImageView release];
SAFE_ARC_RELEASE(backgroundImageView);

self.leftLabel = [[[UILabel alloc] initWithFrame:CGRectOffset(self.frame, 2.0f, 0.0f)] autorelease];
self.leftLabel = SAFE_ARC_AUTORELEASE([[UILabel alloc] initWithFrame:CGRectOffset(self.frame, 2.0f, 0.0f)]);
self.leftLabel.backgroundColor = [UIColor clearColor];
self.leftLabel.textAlignment = UITextAlignmentLeft;
self.leftLabel.font = [UIFont boldSystemFontOfSize:12.0f];
self.leftLabel.textColor = [UIColor colorWithWhite:0.97f alpha:1.0f];
self.leftLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self addSubview:self.leftLabel];

self.rightLabel = [[[UILabel alloc] initWithFrame:CGRectOffset(self.frame, -2.0f, 0.0f)] autorelease];
self.rightLabel = SAFE_ARC_AUTORELEASE([[UILabel alloc] initWithFrame:CGRectOffset(self.frame, -2.0f, 0.0f)]);
self.rightLabel.backgroundColor = [UIColor clearColor];
self.rightLabel.font = [UIFont boldSystemFontOfSize:12.0f];
self.rightLabel.textAlignment = UITextAlignmentRight;
self.rightLabel.textColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
self.rightLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self addSubview:self.rightLabel];

UITapGestureRecognizer *gestureRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)] autorelease];
UITapGestureRecognizer *gestureRecognizer = SAFE_ARC_AUTORELEASE([[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)]);
[self addGestureRecognizer:gestureRecognizer];

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Expand Down