Skip to content

Commit

Permalink
stub out the necessary weak functions
Browse files Browse the repository at this point in the history
git-svn-id: https://src.office.plausiblelabs.com/repo/PLWeakCompatibility/trunk@3 0b19fab4-3b79-e111-ab8d-001cc008e099
  • Loading branch information
mikeash committed Mar 29, 2012
1 parent 8a3a904 commit 0371d9e
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.xcworkspace
xcuserdata
build
26 changes: 21 additions & 5 deletions PLWeakCompatibility.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
C2CB834A1523D8F300E8ABFC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2CB83311523D8F300E8ABFC /* Foundation.framework */; };
C2CB83521523D8F400E8ABFC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C2CB83501523D8F400E8ABFC /* InfoPlist.strings */; };
C2CB83551523D8F400E8ABFC /* PLWeakCompatibilityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C2CB83541523D8F400E8ABFC /* PLWeakCompatibilityTests.m */; };
C2CB83601523D91500E8ABFC /* PLWeakCompatibilityStubs.m in Sources */ = {isa = PBXBuildFile; fileRef = C2CB835F1523D91500E8ABFC /* PLWeakCompatibilityStubs.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -35,18 +36,20 @@
C2CB832F1523D8F300E8ABFC /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
C2CB83311523D8F300E8ABFC /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
C2CB83331523D8F300E8ABFC /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
C2CB83371523D8F300E8ABFC /* PLWeakCompatibility-Info.plist */ = {isa = PBXFileReference; path = "PLWeakCompatibility-Info.plist"; sourceTree = "<group>"; };
C2CB83371523D8F300E8ABFC /* PLWeakCompatibility-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PLWeakCompatibility-Info.plist"; sourceTree = "<group>"; };
C2CB83391523D8F300E8ABFC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
C2CB833B1523D8F300E8ABFC /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
C2CB833D1523D8F300E8ABFC /* PLWeakCompatibility-Prefix.pch */ = {isa = PBXFileReference; path = "PLWeakCompatibility-Prefix.pch"; sourceTree = "<group>"; };
C2CB833E1523D8F300E8ABFC /* PLAppDelegate.h */ = {isa = PBXFileReference; path = PLAppDelegate.h; sourceTree = "<group>"; };
C2CB833D1523D8F300E8ABFC /* PLWeakCompatibility-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PLWeakCompatibility-Prefix.pch"; sourceTree = "<group>"; };
C2CB833E1523D8F300E8ABFC /* PLAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PLAppDelegate.h; sourceTree = "<group>"; };
C2CB833F1523D8F300E8ABFC /* PLAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PLAppDelegate.m; sourceTree = "<group>"; };
C2CB83461523D8F300E8ABFC /* PLWeakCompatibilityTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PLWeakCompatibilityTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
C2CB83471523D8F300E8ABFC /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
C2CB834F1523D8F400E8ABFC /* PLWeakCompatibilityTests-Info.plist */ = {isa = PBXFileReference; path = "PLWeakCompatibilityTests-Info.plist"; sourceTree = "<group>"; };
C2CB834F1523D8F400E8ABFC /* PLWeakCompatibilityTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PLWeakCompatibilityTests-Info.plist"; sourceTree = "<group>"; };
C2CB83511523D8F400E8ABFC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
C2CB83531523D8F400E8ABFC /* PLWeakCompatibilityTests.h */ = {isa = PBXFileReference; path = PLWeakCompatibilityTests.h; sourceTree = "<group>"; };
C2CB83531523D8F400E8ABFC /* PLWeakCompatibilityTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PLWeakCompatibilityTests.h; sourceTree = "<group>"; };
C2CB83541523D8F400E8ABFC /* PLWeakCompatibilityTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PLWeakCompatibilityTests.m; sourceTree = "<group>"; };
C2CB835E1523D91500E8ABFC /* PLWeakCompatibilityStubs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLWeakCompatibilityStubs.h; sourceTree = "<group>"; };
C2CB835F1523D91500E8ABFC /* PLWeakCompatibilityStubs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLWeakCompatibilityStubs.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -108,6 +111,8 @@
children = (
C2CB833E1523D8F300E8ABFC /* PLAppDelegate.h */,
C2CB833F1523D8F300E8ABFC /* PLAppDelegate.m */,
C2CB835E1523D91500E8ABFC /* PLWeakCompatibilityStubs.h */,
C2CB835F1523D91500E8ABFC /* PLWeakCompatibilityStubs.m */,
C2CB83361523D8F300E8ABFC /* Supporting Files */,
);
path = PLWeakCompatibility;
Expand Down Expand Up @@ -251,6 +256,7 @@
files = (
C2CB833C1523D8F300E8ABFC /* main.m in Sources */,
C2CB83401523D8F300E8ABFC /* PLAppDelegate.m in Sources */,
C2CB83601523D91500E8ABFC /* PLWeakCompatibilityStubs.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -345,6 +351,11 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "PLWeakCompatibility/PLWeakCompatibility-Prefix.pch";
INFOPLIST_FILE = "PLWeakCompatibility/PLWeakCompatibility-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
"OTHER_CFLAGS[arch=*]" = (
"-Xclang",
"-fobjc-runtime-has-weak",
);
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -356,6 +367,11 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "PLWeakCompatibility/PLWeakCompatibility-Prefix.pch";
INFOPLIST_FILE = "PLWeakCompatibility/PLWeakCompatibility-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
"OTHER_CFLAGS[arch=*]" = (
"-Xclang",
"-fobjc-runtime-has-weak",
);
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand Down
38 changes: 7 additions & 31 deletions PLWeakCompatibility/PLAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,14 @@ @implementation PLAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// do some lame tests
id obj = [[NSObject alloc] init];
__weak id weakObj = obj;
dispatch_block_t block = [^{ NSLog(@"%@", weakObj); } copy];
NSLog(@"%@", weakObj);
block();

return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
20 changes: 20 additions & 0 deletions PLWeakCompatibility/PLWeakCompatibilityStubs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// PLWeakCompatibilityStubs.h
// PLWeakCompatibility
//
// Created by Michael Ash on 3/28/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//


// Convince ARC to leave these kids alone
typedef void *VoidPtr;
#define id VoidPtr

id objc_loadWeakRetained(id *location);
id objc_initWeak(id *addr, id val);
void objc_destroyWeak(id *addr);
void objc_copyWeak(id *to, id *from);
void objc_moveWeak(id *to, id *from);
id objc_loadWeak(id *location);
id objc_storeWeak(id *location, id obj);
50 changes: 50 additions & 0 deletions PLWeakCompatibility/PLWeakCompatibilityStubs.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// PLWeakCompatibilityStubs.m
// PLWeakCompatibility
//
// Created by Michael Ash on 3/28/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "PLWeakCompatibilityStubs.h"

id objc_autorelease(id obj);

id objc_loadWeakRetained(id *location)
{
// TODO: this is a primitive method
return NULL;
}

id objc_initWeak(id *addr, id val)
{
*addr = NULL;
return objc_storeWeak(addr, val);
}

void objc_destroyWeak(id *addr)
{
objc_storeWeak(addr, NULL);
}

void objc_copyWeak(id *to, id *from)
{
objc_initWeak(to, objc_loadWeak(from));
}

void objc_moveWeak(id *to, id *from)
{
objc_copyWeak(to, from);
objc_destroyWeak(from);
}

id objc_loadWeak(id *location)
{
return objc_autorelease(objc_loadWeakRetained(location));
}

id objc_storeWeak(id *location, id obj)
{
// TODO: this is a primitive method
return NULL;
}

0 comments on commit 0371d9e

Please sign in to comment.