From ce421c6d05c7855ce50d0377362096f258335d4c Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Fri, 2 Oct 2026 19:08:12 +1300 Subject: Debugging stuff and basic PXObject test --- include/Paradox/Core.h | 2 ++ include/Paradox/Object.h | 8 +++++++- meson.build | 6 ++++++ src/Object.m | 15 ++++++++++++++- tests/Object.m | 26 ++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/Object.m 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 +#include +#include #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 +#include + +@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 #include #include +#include @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 +#include + +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; +} -- cgit v1.2.3