Skip to content

Commit

Permalink
win32: add an unpleasant workaround for _NSConcreteGlobalBlock's linkage
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett committed Jan 22, 2018
1 parent 6cd94b7 commit 652be81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions arc.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static inline DWORD arc_tls_key_create(void WINAPI(*cleanupFunction)(void*))

extern void _NSConcreteMallocBlock;
extern void _NSConcreteStackBlock;
extern void _NSConcreteGlobalBlock;
extern struct objc_class _NSConcreteGlobalBlock;

@interface NSAutoreleasePool
+ (Class)class;
Expand Down Expand Up @@ -190,6 +190,12 @@ static inline id retain(id obj)
{
if (isSmallObject(obj)) { return obj; }
Class cls = obj->isa;

if ((Class)&_NSConcreteGlobalBlock == cls->isa)
{
cls = cls->isa;
}

if ((Class)&_NSConcreteMallocBlock == cls ||
(Class)&_NSConcreteStackBlock == cls)
{
Expand All @@ -214,13 +220,14 @@ static inline void release(id obj)
{
if (isSmallObject(obj)) { return; }
Class cls = obj->isa;

if (cls == &_NSConcreteMallocBlock)
{
_Block_release(obj);
return;
}
if ((cls == &_NSConcreteStackBlock) ||
(cls == &_NSConcreteGlobalBlock))
(cls->isa == &_NSConcreteGlobalBlock))
{
return;
}
Expand Down
4 changes: 4 additions & 0 deletions class.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ static inline Class classForObject(id obj)
return SmallObjectClasses[(addr & OBJC_SMALL_OBJECT_MASK)];
}
}
extern struct objc_class _NSConcreteGlobalBlock;
if (obj->isa->isa == (Class)&_NSConcreteGlobalBlock) {
return (Class)&_NSConcreteGlobalBlock;
}
return obj->isa;
}

Expand Down

0 comments on commit 652be81

Please sign in to comment.