From c554b72b74f0ea774e7b6bbe1c2e1ec1d10e3f6f Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Sun, 30 Dec 2018 17:24:14 +0000 Subject: [PATCH] Fix Gorm with the new ABI. Now that @private is enforced by the linker, we can't just bypass it with categories. Instead, either access public interfaces or use reflection to look up instance variables. --- GormCore/GormDocument.m | 8 +++++++- GormCore/GormPlugin.m | 17 ++++++++++++++--- GormCore/GormViewWindow.m | 5 +++-- GormCore/NSView+GormExtensions.m | 31 +++++++++++++++++++++++-------- Palettes/0Menus/GormMenuEditor.m | 2 +- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/GormCore/GormDocument.m b/GormCore/GormDocument.m index 66be33d8..d39c2283 100644 --- a/GormCore/GormDocument.m +++ b/GormCore/GormDocument.m @@ -102,7 +102,13 @@ @implementation NSDocument (GormPrivate) - (NSWindow *) _docWindow { - return _window; + static Ivar iv; + if (!iv) + { + Ivar iv = class_getInstanceVariable([NSDocument class], @"_window"); + NSAssert(iv, @"Unable to find _window ivar in NSDocument class"); + } + return object_getIvar(self, iv); } @end diff --git a/GormCore/GormPlugin.m b/GormCore/GormPlugin.m index 71dfd3ea..a6669c21 100644 --- a/GormCore/GormPlugin.m +++ b/GormCore/GormPlugin.m @@ -31,20 +31,31 @@ - (BOOL) containsDocumentTypeName: (NSString *)tname; @end +static Ivar types_ivar(void) +{ + static Ivar iv; + if (iv == NULL) + { + iv = class_getInstanceVariable([NSDocumentController class], "_types"); + NSCAssert(iv, "Unable to find _types instance variable of NSDocumentController"); + } + return iv; +} + @implementation NSDocumentController (GormPrivate) - (NSArray *) types { - return _types; + return object_getIvar(self, types_ivar()); } - (void) setTypes: (NSArray *)types { - ASSIGN(_types, types); + object_setIvar(self, types_ivar(), types); } - (BOOL) containsDocumentTypeName: (NSString *)tname { - NSEnumerator *en = [_types objectEnumerator]; + NSEnumerator *en = [object_getIvar(self, types_ivar()) objectEnumerator]; id obj = nil; while ((obj = [en nextObject]) != nil) diff --git a/GormCore/GormViewWindow.m b/GormCore/GormViewWindow.m index 683f9665..78a0897b 100644 --- a/GormCore/GormViewWindow.m +++ b/GormCore/GormViewWindow.m @@ -163,7 +163,7 @@ _view = view; [[self contentView] addSubview: _view]; - DESTROY(_delegate); + RELEASE([self delegate]); [self setDelegate: [[GormViewWindowDelegate alloc] initWithView: _view]]; } @@ -204,7 +204,8 @@ - (void) dealloc { - DESTROY(_delegate); + RELEASE([self delegate]); + [self setDelegate: nil]; [super dealloc]; } diff --git a/GormCore/NSView+GormExtensions.m b/GormCore/NSView+GormExtensions.m index c3f32a08..2331cfd8 100644 --- a/GormCore/NSView+GormExtensions.m +++ b/GormCore/NSView+GormExtensions.m @@ -25,10 +25,23 @@ #include #include #include +#include #include "NSView+GormExtensions.h" #include +static Ivar subviews_ivar(void) +{ + static Ivar iv; + if (iv == NULL) + { + iv = class_getInstanceVariable([NSView class], "_sub_views"); + NSCAssert(iv, @"Unable to get NSView's _sub_views instance variable"); + } + return iv; +} + + @implementation NSView (GormExtensions) /** * All superviews of this view @@ -72,11 +85,12 @@ - (void) moveViewToFront: (NSView *)sv { NSDebugLog(@"move to front %@", sv); - if([_sub_views containsObject: sv]) + NSMutableArray *sub_views = object_getIvar(self, subviews_ivar()); + if([sub_views containsObject: sv]) { RETAIN(sv); // make sure it doesn't deallocate the view. - [_sub_views removeObject: sv]; - [_sub_views addObject: sv]; // add it to the end. + [sub_views removeObject: sv]; + [sub_views addObject: sv]; // add it to the end. RELEASE(sv); } } @@ -88,18 +102,19 @@ - (void) moveViewToBack: (NSView *)sv { NSDebugLog(@"move to back %@", sv); - if([_sub_views containsObject: sv]) + NSMutableArray *sub_views = object_getIvar(self, subviews_ivar()); + if([sub_views containsObject: sv]) { RETAIN(sv); // make sure it doesn't deallocate the view. - [_sub_views removeObject: sv]; - if([_sub_views count] > 0) + [sub_views removeObject: sv]; + if([sub_views count] > 0) { - [_sub_views insertObject: sv + [sub_views insertObject: sv atIndex: 0]; // add it to the end. } else { - [_sub_views addObject: sv]; + [sub_views addObject: sv]; } RELEASE(sv); } diff --git a/Palettes/0Menus/GormMenuEditor.m b/Palettes/0Menus/GormMenuEditor.m index 9444db54..10fc1546 100644 --- a/Palettes/0Menus/GormMenuEditor.m +++ b/Palettes/0Menus/GormMenuEditor.m @@ -37,7 +37,7 @@ @implementation NSMenu (GormMenuEditorAdditions) - (BOOL) isVisible { - return [_aWindow isVisible]; + return [[self window] isVisible]; } @end