Permalink
Browse files

Use ARC

  • Loading branch information...
phoboslab committed Feb 10, 2013
1 parent 5be306a commit 933b29352a1852470d93ae8612f806ad1a1de3c8
Showing with 325 additions and 510 deletions.
  1. +2 −0 Ejecta.xcodeproj/project.pbxproj
  2. +1 −1 Source/AppDelegate.h
  3. +2 −10 Source/AppDelegate.m
  4. +0 −3 Source/Ejecta/EJAppViewController.m
  5. +2 −2 Source/Ejecta/EJAudio/EJAudioSourceAVAudio.h
  6. +1 −7 Source/Ejecta/EJAudio/EJAudioSourceAVAudio.m
  7. +2 −2 Source/Ejecta/EJAudio/EJAudioSourceOpenAL.h
  8. +2 −5 Source/Ejecta/EJAudio/EJAudioSourceOpenAL.m
  9. +1 −1 Source/Ejecta/EJAudio/EJBindingAudio.h
  10. +2 −11 Source/Ejecta/EJAudio/EJBindingAudio.m
  11. +3 −5 Source/Ejecta/EJAudio/EJOpenALBuffer.m
  12. +1 −3 Source/Ejecta/EJAudio/EJOpenALManager.m
  13. +12 −11 Source/Ejecta/EJBindingBase.h
  14. +6 −9 Source/Ejecta/EJBindingBase.m
  15. +1 −7 Source/Ejecta/EJBindingEjectaCore.m
  16. +5 −5 Source/Ejecta/EJBindingEventedBase.h
  17. +0 −3 Source/Ejecta/EJBindingEventedBase.m
  18. +35 −38 Source/Ejecta/EJCanvas/2D/EJBindingCanvasContext2D.m
  19. +2 −6 Source/Ejecta/EJCanvas/2D/EJBindingCanvasGradient.m
  20. +2 −6 Source/Ejecta/EJCanvas/2D/EJBindingCanvasPattern.m
  21. +1 −1 Source/Ejecta/EJCanvas/2D/EJBindingImageData.h
  22. +1 −3 Source/Ejecta/EJCanvas/2D/EJBindingImageData.m
  23. +26 −28 Source/Ejecta/EJCanvas/2D/EJCanvasContext2D.h
  24. +99 −121 Source/Ejecta/EJCanvas/2D/EJCanvasContext2D.m
  25. +4 −8 Source/Ejecta/EJCanvas/2D/EJCanvasContext2DScreen.m
  26. +1 −1 Source/Ejecta/EJCanvas/2D/EJCanvasContext2DTexture.h
  27. +5 −10 Source/Ejecta/EJCanvas/2D/EJCanvasContext2DTexture.m
  28. +1 −1 Source/Ejecta/EJCanvas/2D/EJCanvasGradient.h
  29. +0 −6 Source/Ejecta/EJCanvas/2D/EJCanvasGradient.m
  30. +2 −2 Source/Ejecta/EJCanvas/2D/EJCanvasPattern.h
  31. +0 −4 Source/Ejecta/EJCanvas/2D/EJCanvasPattern.m
  32. +18 −33 Source/Ejecta/EJCanvas/2D/EJFont.mm
  33. +0 −1 Source/Ejecta/EJCanvas/2D/EJGLProgram2D.m
  34. +1 −1 Source/Ejecta/EJCanvas/2D/EJImageData.h
  35. +2 −6 Source/Ejecta/EJCanvas/2D/EJImageData.m
  36. +1 −1 Source/Ejecta/EJCanvas/2D/EJPath.h
  37. +20 −21 Source/Ejecta/EJCanvas/2D/EJPath.mm
  38. +1 −1 Source/Ejecta/EJCanvas/EJBindingCanvas.h
  39. +0 −2 Source/Ejecta/EJCanvas/EJBindingCanvas.m
  40. +3 −10 Source/Ejecta/EJCanvas/EJBindingImage.m
  41. +1 −1 Source/Ejecta/EJCanvas/EJCanvasContext.h
  42. +1 −1 Source/Ejecta/EJCanvas/EJTexture.h
  43. +6 −17 Source/Ejecta/EJCanvas/EJTexture.m
  44. +2 −2 Source/Ejecta/EJCanvas/WebGL/EJBindingCanvasContextWebGL.h
  45. +3 −11 Source/Ejecta/EJCanvas/WebGL/EJBindingCanvasContextWebGL.m
  46. +5 −20 Source/Ejecta/EJCanvas/WebGL/EJBindingWebGLObjects.m
  47. +1 −1 Source/Ejecta/EJCanvas/WebGL/EJCanvasContextWebGL.h
  48. +2 −4 Source/Ejecta/EJCanvas/WebGL/EJCanvasContextWebGL.m
  49. +4 −0 Source/Ejecta/EJConvert.h
  50. +2 −3 Source/Ejecta/EJConvert.m
  51. +3 −3 Source/Ejecta/EJJavaScriptView.h
  52. +1 −1 Source/Ejecta/EJJavaScriptView.m
  53. +1 −7 Source/Ejecta/EJTimer.m
  54. +0 −3 Source/Ejecta/EJUtils.h
  55. +2 −6 Source/Ejecta/EJUtils.m
  56. +0 −2 Source/Ejecta/EJUtils/EJBindingAdBanner.m
  57. +4 −8 Source/Ejecta/EJUtils/EJBindingGameCenter.m
  58. +19 −23 Source/Ejecta/EJUtils/EJBindingHttpRequest.m
  59. +0 −1 Source/Ejecta/EJUtils/EJBindingTouchInput.m
@@ -670,6 +670,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COMPRESS_PNG_FILES = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
@@ -695,6 +696,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COMPRESS_PNG_FILES = NO;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
View
@@ -3,7 +3,7 @@
@interface AppDelegate : NSObject <UIApplicationDelegate>
-@property (nonatomic, retain) IBOutlet UIWindow *window;
+@property (nonatomic, strong) IBOutlet UIWindow *window;
@property (nonatomic, strong) EJAppViewController *ejApp;
@end
View
@@ -9,20 +9,12 @@ @implementation AppDelegate
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- //Optionally set the idle timer disabled, this prevents the device from sleep when not being interacted with by touch. ie. games with motion control.
+ //Optionally set the idle timer disabled, this prevents the device from sleep when not
+ // being interacted with by touch. ie. games with motion control.
[application setIdleTimerDisabled:YES];
self.ejApp = [EJAppViewController instance];
window.rootViewController = self.ejApp;
return YES;
}
-#pragma mark -
-#pragma mark Memory management
-
-- (void)dealloc {
- [self.ejApp release];
- [super dealloc];
-}
-
-
@end
@@ -36,9 +36,6 @@ +(id)alloc {
return nil;
}
-- (void)dealloc {
- [super dealloc];
-}
- (void)didReceiveMemoryWarning {
[[EJJavaScriptView sharedView] clearCaches];
@@ -6,11 +6,11 @@
@interface EJAudioSourceAVAudio : NSObject <EJAudioSource, AVAudioPlayerDelegate> {
NSString *path;
AVAudioPlayer *player;
- NSObject<EJAudioSourceDelegate> *delegate;
+ NSObject<EJAudioSourceDelegate> *__weak delegate;
}
@property (nonatomic) float currentTime;
@property (nonatomic) float duration;
-@property (nonatomic, assign) NSObject<EJAudioSourceDelegate> *delegate;
+@property (nonatomic, weak) NSObject<EJAudioSourceDelegate> *delegate;
@end
@@ -7,19 +7,13 @@ @implementation EJAudioSourceAVAudio
- (id)initWithPath:(NSString *)pathp {
if( self = [super init] ) {
- path = [pathp retain];
+ path = pathp;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
player.delegate = self;
}
return self;
}
-- (void)dealloc {
- [path release];
- [player release];
-
- [super dealloc];
-}
- (void)play {
[player play];
@@ -14,11 +14,11 @@
BOOL looping;
NSTimer *endTimer;
- NSObject<EJAudioSourceDelegate> *delegate;
+ NSObject<EJAudioSourceDelegate> *__weak delegate;
}
@property (nonatomic) float currentTime;
@property (nonatomic) float duration;
-@property (nonatomic, assign) NSObject<EJAudioSourceDelegate> *delegate;
+@property (nonatomic, weak) NSObject<EJAudioSourceDelegate> *delegate;
@end
@@ -7,9 +7,9 @@ @implementation EJAudioSourceOpenAL
- (id)initWithPath:(NSString *)pathp {
if( self = [super init] ) {
- path = [pathp retain];
+ path = pathp;
- buffer = [[EJOpenALBuffer cachedBufferWithPath:pathp] retain];
+ buffer = [EJOpenALBuffer cachedBufferWithPath:pathp];
alGenSources(1, &sourceId);
alSourcei(sourceId, AL_BUFFER, buffer.bufferId);
@@ -24,11 +24,8 @@ - (void)dealloc {
alDeleteSources(1, &sourceId);
}
- [buffer release];
- [path release];
[endTimer invalidate];
- [super dealloc];
}
- (void)play {
@@ -30,7 +30,7 @@ typedef enum {
@property (nonatomic) BOOL loop;
@property (nonatomic) BOOL ended;
@property (nonatomic) float volume;
-@property (nonatomic, retain) NSString *path;
+@property (nonatomic, strong) NSString *path;
@property (nonatomic) EJAudioPreload preload;
@end
@@ -20,19 +20,12 @@ - (id)initWithContext:(JSContextRef)ctx argc:(size_t)argc argv:(const JSValueRef
return self;
}
-- (void)dealloc {
- [source release];
- [path release];
- [super dealloc];
-}
- (void)setSourcePath:(NSString *)pathp {
if( !path || ![path isEqualToString:pathp] ) {
- [path release];
- [source release];
source = NULL;
- path = [pathp retain];
+ path = pathp;
if( preload != kEJAudioPreloadNone ) {
[self load];
}
@@ -54,7 +47,6 @@ - (void)load {
selector:@selector(loadOperation:) object:fullPath];
loadOp.threadPriority = 0.2;
[[EJJavaScriptView sharedView].opQueue addOperation:loadOp];
- [loadOp release];
}
- (void)loadOperation:(NSString *)fullPath {
@@ -72,14 +64,13 @@ - (void)loadOperation:(NSString *)fullPath {
src = [[EJAudioSourceAVAudio alloc] initWithPath:fullPath];
}
src.delegate = self;
- [src autorelease];
[self performSelectorOnMainThread:@selector(endLoad:) withObject:src waitUntilDone:NO];
}
}
- (void)endLoad:(NSObject<EJAudioSource> *)src {
- source = [src retain];
+ source = src;
[source setLooping:loop];
[source setVolume:volume];
@@ -10,7 +10,7 @@ @implementation EJOpenALBuffer
@synthesize duration;
+ (id)cachedBufferWithPath:(NSString *)path {
- EJOpenALBuffer *buffer = [[EJJavaScriptView sharedView].openALManager.buffers[path] retain];
+ EJOpenALBuffer *buffer = [EJJavaScriptView sharedView].openALManager.buffers[path];
if( !buffer ) {
buffer = [[EJOpenALBuffer alloc] initWithPath:path];
[EJJavaScriptView sharedView].openALManager.buffers[path] = buffer;
@@ -20,7 +20,7 @@ + (id)cachedBufferWithPath:(NSString *)path {
- (id)initWithPath:(NSString *)pathp {
if( self = [super init] ) {
- path = [pathp retain];
+ path = pathp;
NSURL *url = [NSURL fileURLWithPath:pathp];
void *data = [self getAudioDataWithURL:url];
@@ -35,12 +35,10 @@ - (id)initWithPath:(NSString *)pathp {
- (void)dealloc {
[[EJJavaScriptView sharedView].openALManager.buffers removeObjectForKey:path];
- [path release];
if( bufferId ) {
alDeleteBuffers(1, &bufferId);
}
- [super dealloc];
}
- (void*)getAudioDataWithURL:(NSURL *)url {
@@ -49,7 +47,7 @@ - (void*)getAudioDataWithURL:(NSURL *)url {
// Open the file
ExtAudioFileRef file = NULL;
- OSStatus error = ExtAudioFileOpenURL((CFURLRef)url, &file);
+ OSStatus error = ExtAudioFileOpenURL((__bridge CFURLRef)url, &file);
if( error ) {
NSLog(@"OpenALSource: ExtAudioFileOpenURL FAILED, Error = %ld", error);
goto Exit;
@@ -6,7 +6,7 @@ @implementation EJOpenALManager
-(id)init {
if( self = [super init] ) {
// Create a non-retaining Dictionary to hold the cached buffers
- buffers = (NSMutableDictionary*)CFDictionaryCreateMutable(NULL, 8, &kCFCopyStringDictionaryKeyCallBacks, NULL);
+ buffers = (NSMutableDictionary*)CFBridgingRelease(CFDictionaryCreateMutable(NULL, 8, &kCFCopyStringDictionaryKeyCallBacks, NULL));
device = alcOpenDevice(NULL);
if( device ) {
@@ -18,11 +18,9 @@ -(id)init {
}
- (void)dealloc {
- [buffers release];
alcDestroyContext( context );
alcCloseDevice( device );
- [super dealloc];
}
@end
@@ -39,10 +39,11 @@ extern JSValueRef ej_global_undefined;
JSObjectRef object, \
size_t argc, \
const JSValueRef argv[], \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
- id instance = (id)JSObjectGetPrivate(object); \
- JSValueRef ret = (JSValueRef)objc_msgSend(instance, @selector(_func_##NAME:argc:argv:), ctx, argc, argv); \
+ __unsafe_unretained id instance = (__bridge id)JSObjectGetPrivate(object); \
+ JSValueRef ret = (__bridge JSValueRef)objc_msgSend( \
+ instance, @selector(_func_##NAME:argc:argv:), ctx, argc, argv); \
return ret ? ret : ej_global_undefined; \
} \
__EJ_GET_POINTER_TO(_func_##NAME)\
@@ -61,10 +62,10 @@ extern JSValueRef ej_global_undefined;
JSContextRef ctx, \
JSObjectRef object, \
JSStringRef propertyName, \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
- id instance = (id)JSObjectGetPrivate(object); \
- return (JSValueRef)objc_msgSend(instance, @selector(_get_##NAME:), ctx); \
+ __unsafe_unretained id instance = (__bridge id)JSObjectGetPrivate(object); \
+ return (__bridge JSValueRef)objc_msgSend(instance, @selector(_get_##NAME:), ctx); \
} \
__EJ_GET_POINTER_TO(_get_##NAME)\
\
@@ -83,9 +84,9 @@ extern JSValueRef ej_global_undefined;
JSObjectRef object, \
JSStringRef propertyName, \
JSValueRef value, \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
- id instance = (id)JSObjectGetPrivate(object); \
+ __unsafe_unretained id instance = (__bridge id)JSObjectGetPrivate(object); \
objc_msgSend(instance, @selector(_set_##NAME:value:), ctx, value); \
return true; \
} \
@@ -106,7 +107,7 @@ extern JSValueRef ej_global_undefined;
JSObjectRef object, \
size_t argc, \
const JSValueRef argv[], \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
static bool didShowWarning; \
if( !didShowWarning ) { \
@@ -136,7 +137,7 @@ extern JSValueRef ej_global_undefined;
JSStringRef _str = JSValueToStringCopy(ctx, value, NULL); \
const JSChar *_strptr = JSStringGetCharactersPtr( _str ); \
int _length = JSStringGetLength(_str)-1; \
- const char ** _names = _##NAME##EnumNames; \
+ const char **_names = _##NAME##EnumNames; \
int _target; \
EJ_MAP_EXT(0, _EJ_LITERAL(else), _EJ_BIND_ENUM_COMPARE, __VA_ARGS__) \
else { JSStringRelease( _str ); return; } \
@@ -164,7 +165,7 @@ static inline bool JSStrIsEqualToStr( const JSChar *s1, const char *s2, int leng
JSContextRef ctx, \
JSObjectRef object, \
JSStringRef propertyName, \
- JSValueRef* exception \
+ JSValueRef *exception \
) { \
return JSValueMakeNumber(ctx, VALUE); \
} \
@@ -3,8 +3,8 @@
void _ej_class_finalize(JSObjectRef object) {
- id instance = (id)JSObjectGetPrivate(object);
- [instance release];
+ id instance;
+ instance = (__bridge_transfer id)JSObjectGetPrivate(object);
}
NSData *NSDataFromString( NSString *str ) {
@@ -45,7 +45,6 @@ + (JSClassRef)getJSClass {
}
+ (void)clearJSClassCache {
- [CachedJSClasses release];
CachedJSClasses = NULL;
}
@@ -88,12 +87,12 @@ + (JSClassRef)createJSClass {
values[i].attributes = kJSPropertyAttributeDontDelete;
SEL get = NSSelectorFromString([NSString stringWithFormat:@"_ptr_to_get_%@", name]);
- values[i].getProperty = (JSObjectGetPropertyCallback)[self performSelector:get];
+ values[i].getProperty = (__bridge void *)objc_msgSend(self, get);
// Property has a setter? Otherwise mark as read only
SEL set = NSSelectorFromString([NSString stringWithFormat:@"_ptr_to_set_%@", name]);
if( [self respondsToSelector:set] ) {
- values[i].setProperty = (JSObjectSetPropertyCallback)[self performSelector:set];
+ values[i].setProperty = (__bridge void *)objc_msgSend(self, set);
}
else {
values[i].attributes |= kJSPropertyAttributeReadOnly;
@@ -110,7 +109,7 @@ + (JSClassRef)createJSClass {
functions[i].attributes = kJSPropertyAttributeDontDelete;
SEL call = NSSelectorFromString([NSString stringWithFormat:@"_ptr_to_func_%@", name]);
- functions[i].callAsFunction = (JSObjectCallAsFunctionCallback)[self performSelector:call];
+ functions[i].callAsFunction = (__bridge void *)objc_msgSend(self, call);
}
JSClassDefinition classDef = kJSClassDefinitionEmpty;
@@ -123,8 +122,6 @@ + (JSClassRef)createJSClass {
free( values );
free( functions );
- [properties release];
- [methods release];
return class;
}
@@ -133,7 +130,7 @@ + (JSObjectRef)createJSObjectWithContext:(JSContextRef)ctx instance:(EJBindingBa
JSClassRef jsClass = [self getJSClass];
JSObjectRef obj = JSObjectMake( ctx, jsClass, NULL );
- JSObjectSetPrivate( obj, (void *)instance );
+ JSObjectSetPrivate( obj, (__bridge_retained void *)instance );
instance->jsObject = obj;
return obj;
Oops, something went wrong.

0 comments on commit 933b293

Please sign in to comment.