Skip to content

Commit

Permalink
Workaround for apparent clang bug calculating ivar offset into NSThre…
Browse files Browse the repository at this point in the history
…ad object.
  • Loading branch information
rfm authored and qmfrederik committed Nov 1, 2024
1 parent e9ab3d8 commit 0d487c5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Source/NSGraphicsContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
Boston, MA 02110-1301, USA.
*/

#if !defined(_NONFRAGILE_ABI)
#define EXPOSE_NSThread_IVARS
#endif

#import <Foundation/NSGeometry.h>
#import <Foundation/NSString.h>
Expand Down Expand Up @@ -102,7 +104,12 @@
*/
NSThread *th = GSCurrentThread();

# if defined(_NONFRAGILE_ABI)
return (NSGraphicsContext*)object_getIvar(th,
class_getInstanceVariable(object_getClass(th), "_gcontext"));
# else
return (NSGraphicsContext*) th->_gcontext;
# endif
#else
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];

Expand Down Expand Up @@ -171,7 +178,12 @@ + (void) setCurrentContext: (NSGraphicsContext *)context
*/
NSThread *th = GSCurrentThread();

# if defined(_NONFRAGILE_ABI)
object_setIvar(th,
class_getInstanceVariable(object_getClass(th), "_gcontext"), context);
# else
ASSIGN(th->_gcontext, context);
# endif
#else
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];

Expand Down

0 comments on commit 0d487c5

Please sign in to comment.