diff options
| -rw-r--r-- | include/Paradox/Core.h | 2 | ||||
| -rw-r--r-- | include/Paradox/Object.h | 8 | ||||
| -rw-r--r-- | meson.build | 6 | ||||
| -rw-r--r-- | src/Object.m | 15 | ||||
| -rw-r--r-- | tests/Object.m | 26 |
5 files changed, 55 insertions, 2 deletions
diff --git a/include/Paradox/Core.h b/include/Paradox/Core.h index 2506399..44ed514 100644 --- a/include/Paradox/Core.h +++ b/include/Paradox/Core.h @@ -2,5 +2,7 @@ #define PARADOX_CORE_H #include <Paradox/Object.h> +#include <objc/objc.h> +#include <objc/runtime.h> #endif diff --git a/include/Paradox/Object.h b/include/Paradox/Object.h index e51c733..a4ef7f8 100644 --- a/include/Paradox/Object.h +++ b/include/Paradox/Object.h @@ -1,8 +1,14 @@ #ifndef PARADOX_OBJECT_H #define PARADOX_OBJECT_H -@interface PXObject +#include <objc/objc.h> +#include <objc/runtime.h> + +@interface PXObject { + Class isa; +} + (instancetype)alloc; ++ (instancetype)allocDebug; - (instancetype)init; - (void)dealloc; @end diff --git a/meson.build b/meson.build index aa9cc96..a97cc69 100644 --- a/meson.build +++ b/meson.build @@ -19,5 +19,11 @@ install_headers( subdir: 'paradox' ) +test_deps = [] +test_deps += dependency('libobjc') +test_deps += declare_dependency(link_with: paradox, include_directories: inc, dependencies: deps) + +executable('Object', 'tests/Object.m', dependencies: test_deps) + pkg = import('pkgconfig') pkg.generate(paradox, subdirs: 'paradox', version: '0.0.1', name: 'paradox', filebase: 'paradox', description: 'Application framework for Objective-C built from first principles.', requires: ['libobjc']) diff --git a/src/Object.m b/src/Object.m index d6fd2cb..71a2a7d 100644 --- a/src/Object.m +++ b/src/Object.m @@ -1,11 +1,24 @@ #include <Paradox/Object.h> #include <objc/objc.h> #include <objc/runtime.h> +#include <stdio.h> @implementation PXObject + (instancetype)alloc { - return (id)class_createInstance(self, 0); + return class_createInstance(self, 0); +} + ++ (instancetype)allocDebug { + printf("alloc: self = %p\n", (void*)self); + printf("alloc: instance size = %zu\n", class_getInstanceSize(self)); + printf("alloc: sizeof(Class) = %zu\n", sizeof(Class)); + + id object = [self alloc]; + + printf("alloc: object = %p\n", (void*)object); + + return object; } - (instancetype)init { diff --git a/tests/Object.m b/tests/Object.m new file mode 100644 index 0000000..be81b1d --- /dev/null +++ b/tests/Object.m @@ -0,0 +1,26 @@ +#include <Paradox/Core.h> +#include <stdio.h> + +int main(void) { + printf("PXObject test\n"); + + PXObject *object = [PXObject allocDebug]; + + if (object == nil) { + fprintf(stderr, "PXObject failed to alloc :c\n"); + return 1; + } + + object = [object init]; + + if (object == nil) { + fprintf(stderr, "PXObject failed to init :c\n"); + return 1; + } + + [object dealloc]; + + printf("If you got this far without segfaulting or crashing it means it allocated and initialized a PXObject, then deallocated it. Yayayayayay\n"); + + return 0; +} |
