aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/Paradox/Object.h3
-rw-r--r--src/Object.m13
-rw-r--r--tests/Object.m28
3 files changed, 41 insertions, 3 deletions
diff --git a/include/Paradox/Object.h b/include/Paradox/Object.h
index 2ca6392..87b93f5 100644
--- a/include/Paradox/Object.h
+++ b/include/Paradox/Object.h
@@ -9,8 +9,11 @@
}
+ (instancetype)alloc;
+ (instancetype)allocDebug;
++ (instancetype)new;
+- (instancetype)retain;
- (instancetype)init;
- (void)dealloc;
+- (void)release;
@end
#endif
diff --git a/src/Object.m b/src/Object.m
index 71a2a7d..7b26bf8 100644
--- a/src/Object.m
+++ b/src/Object.m
@@ -1,6 +1,7 @@
#include <Paradox/Object.h>
#include <objc/objc.h>
#include <objc/runtime.h>
+#include <objc/objc-arc.h>
#include <stdio.h>
@implementation PXObject
@@ -21,6 +22,18 @@
return object;
}
++ (instancetype) new {
+ return [[self alloc] init];
+}
+
+- (instancetype) retain {
+ return objc_retain_fast_np(self);
+}
+
+- (void) release {
+ objc_release_fast_np(self);
+}
+
- (instancetype)init {
return self;
}
diff --git a/tests/Object.m b/tests/Object.m
index be81b1d..2814489 100644
--- a/tests/Object.m
+++ b/tests/Object.m
@@ -2,7 +2,7 @@
#include <stdio.h>
int main(void) {
- printf("PXObject test\n");
+ printf("PXObject test (allocDebug)\n");
PXObject *object = [PXObject allocDebug];
@@ -18,9 +18,31 @@ int main(void) {
return 1;
}
- [object dealloc];
+ [object release];
- printf("If you got this far without segfaulting or crashing it means it allocated and initialized a PXObject, then deallocated it. Yayayayayay\n");
+ printf("If you got this far without segfaulting or crashing it means it allocated and initialized a PXObject, then released it. Yay!\n");
+
+ printf("\nPXObject two-owner test (new)\n");
+
+ PXObject *object1 = [PXObject new];
+ PXObject *object2 = [object1 retain];
+
+ printf("object1 reference: %p\n", (void*)object1);
+ [object1 release];
+ printf("object1 released\n");
+
+ printf("attempting retain on object2\n");
+ PXObject *object3 = [object2 retain];
+
+ printf("object2 reference: %p\n", (void*)object2);
+ [object2 release];
+ printf("object2 released\n");
+
+ printf("object3 reference: %p\n", (void*)object3);
+ [object3 release];
+ printf("object3 released\n");
+
+ printf("test complete\n");
return 0;
}