Skip to content

Commit 0d487c5

Browse files
rfmqmfrederik
authored andcommitted
Workaround for apparent clang bug calculating ivar offset into NSThread object.
1 parent e9ab3d8 commit 0d487c5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Source/NSGraphicsContext.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
Boston, MA 02110-1301, USA.
3434
*/
3535

36+
#if !defined(_NONFRAGILE_ABI)
3637
#define EXPOSE_NSThread_IVARS
38+
#endif
3739

3840
#import <Foundation/NSGeometry.h>
3941
#import <Foundation/NSString.h>
@@ -102,7 +104,12 @@
102104
*/
103105
NSThread *th = GSCurrentThread();
104106

107+
# if defined(_NONFRAGILE_ABI)
108+
return (NSGraphicsContext*)object_getIvar(th,
109+
class_getInstanceVariable(object_getClass(th), "_gcontext"));
110+
# else
105111
return (NSGraphicsContext*) th->_gcontext;
112+
# endif
106113
#else
107114
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
108115

@@ -171,7 +178,12 @@ + (void) setCurrentContext: (NSGraphicsContext *)context
171178
*/
172179
NSThread *th = GSCurrentThread();
173180

181+
# if defined(_NONFRAGILE_ABI)
182+
object_setIvar(th,
183+
class_getInstanceVariable(object_getClass(th), "_gcontext"), context);
184+
# else
174185
ASSIGN(th->_gcontext, context);
186+
# endif
175187
#else
176188
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
177189

0 commit comments

Comments
 (0)