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.
This commit is contained in:
David Chisnall 2018-12-30 17:24:14 +00:00 committed by David Chisnall
parent dcbf7d7746
commit c554b72b74
5 changed files with 48 additions and 15 deletions

View file

@ -102,7 +102,13 @@
@implementation NSDocument (GormPrivate) @implementation NSDocument (GormPrivate)
- (NSWindow *) _docWindow - (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 @end

View file

@ -31,20 +31,31 @@
- (BOOL) containsDocumentTypeName: (NSString *)tname; - (BOOL) containsDocumentTypeName: (NSString *)tname;
@end @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) @implementation NSDocumentController (GormPrivate)
- (NSArray *) types - (NSArray *) types
{ {
return _types; return object_getIvar(self, types_ivar());
} }
- (void) setTypes: (NSArray *)types - (void) setTypes: (NSArray *)types
{ {
ASSIGN(_types, types); object_setIvar(self, types_ivar(), types);
} }
- (BOOL) containsDocumentTypeName: (NSString *)tname - (BOOL) containsDocumentTypeName: (NSString *)tname
{ {
NSEnumerator *en = [_types objectEnumerator]; NSEnumerator *en = [object_getIvar(self, types_ivar()) objectEnumerator];
id obj = nil; id obj = nil;
while ((obj = [en nextObject]) != nil) while ((obj = [en nextObject]) != nil)

View file

@ -163,7 +163,7 @@
_view = view; _view = view;
[[self contentView] addSubview: _view]; [[self contentView] addSubview: _view];
DESTROY(_delegate); RELEASE([self delegate]);
[self setDelegate: [[GormViewWindowDelegate alloc] initWithView: _view]]; [self setDelegate: [[GormViewWindowDelegate alloc] initWithView: _view]];
} }
@ -204,7 +204,8 @@
- (void) dealloc - (void) dealloc
{ {
DESTROY(_delegate); RELEASE([self delegate]);
[self setDelegate: nil];
[super dealloc]; [super dealloc];
} }

View file

@ -25,10 +25,23 @@
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSEnumerator.h> #include <Foundation/NSEnumerator.h>
#include <Foundation/NSDebug.h> #include <Foundation/NSDebug.h>
#include <Foundation/NSException.h>
#include "NSView+GormExtensions.h" #include "NSView+GormExtensions.h"
#include <InterfaceBuilder/IBViewResourceDragging.h> #include <InterfaceBuilder/IBViewResourceDragging.h>
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) @implementation NSView (GormExtensions)
/** /**
* All superviews of this view * All superviews of this view
@ -72,11 +85,12 @@
- (void) moveViewToFront: (NSView *)sv - (void) moveViewToFront: (NSView *)sv
{ {
NSDebugLog(@"move to front %@", 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. RETAIN(sv); // make sure it doesn't deallocate the view.
[_sub_views removeObject: sv]; [sub_views removeObject: sv];
[_sub_views addObject: sv]; // add it to the end. [sub_views addObject: sv]; // add it to the end.
RELEASE(sv); RELEASE(sv);
} }
} }
@ -88,18 +102,19 @@
- (void) moveViewToBack: (NSView *)sv - (void) moveViewToBack: (NSView *)sv
{ {
NSDebugLog(@"move to back %@", 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. RETAIN(sv); // make sure it doesn't deallocate the view.
[_sub_views removeObject: sv]; [sub_views removeObject: sv];
if([_sub_views count] > 0) if([sub_views count] > 0)
{ {
[_sub_views insertObject: sv [sub_views insertObject: sv
atIndex: 0]; // add it to the end. atIndex: 0]; // add it to the end.
} }
else else
{ {
[_sub_views addObject: sv]; [sub_views addObject: sv];
} }
RELEASE(sv); RELEASE(sv);
} }

View file

@ -37,7 +37,7 @@
@implementation NSMenu (GormMenuEditorAdditions) @implementation NSMenu (GormMenuEditorAdditions)
- (BOOL) isVisible - (BOOL) isVisible
{ {
return [_aWindow isVisible]; return [[self window] isVisible];
} }
@end @end