2525#define os_assert (_x ) assert(_x)
2626#endif
2727
28- #if TARGET_OS_WIN32
29- #define _CRT_SECURE_NO_WARNINGS 1
30- #include <windows.h>
31- static __inline bool OSAtomicCompareAndSwapLong (long oldl , long newl , long volatile * dst )
32- {
33- // fixme barrier is overkill -- see objc-os.h
34- long original = InterlockedCompareExchange (dst , newl , oldl );
35- return (original == oldl );
36- }
28+ #if !defined(__has_builtin )
29+ #define __has_builtin (builtin ) 0
30+ #endif
3731
38- static __inline bool OSAtomicCompareAndSwapInt (int oldi , int newi , int volatile * dst )
39- {
40- // fixme barrier is overkill -- see objc-os.h
41- int original = InterlockedCompareExchange (dst , newi , oldi );
42- return (original == oldi );
32+ #if __has_builtin (__sync_bool_compare_and_swap )
33+ #define OSAtomicCompareAndSwapInt (Old , New , Ptr ) \
34+ __sync_bool_compare_and_swap(Ptr, Old, New)
35+ #elif TARGET_OS_WIN32
36+ #define _CRT_SECURE_NO_WARNINGS 1
37+ #include <Windows.h>
38+ static __inline bool OSAtomicCompareAndSwapInt (int oldi , int newi ,
39+ int volatile * dst ) {
40+ // fixme barrier is overkill -- see objc-os.h
41+ int original = InterlockedCompareExchange ((LONG volatile * )dst , newi , oldi );
42+ return (original == oldi );
4343}
44- #else
45- #define OSAtomicCompareAndSwapLong (_Old , _New , _Ptr ) __sync_bool_compare_and_swap(_Ptr, _Old, _New)
46- #define OSAtomicCompareAndSwapInt (_Old , _New , _Ptr ) __sync_bool_compare_and_swap(_Ptr, _Old, _New)
4744#endif
4845
4946/***********************
@@ -142,7 +139,7 @@ GC support stub routines
142139
143140
144141
145- static void * _Block_alloc_default (const unsigned long size , const bool initialCountIsOne , const bool isObject ) {
142+ static void * _Block_alloc_default (size_t size , const bool initialCountIsOne , const bool isObject ) {
146143 return malloc (size );
147144}
148145
@@ -190,7 +187,7 @@ static void _Block_destructInstance_default(const void *aBlock) {}
190187GC support callout functions - initially set to stub routines
191188***************************************************************************/
192189
193- static void * (* _Block_allocator )(const unsigned long , const bool isOne , const bool isObject ) = _Block_alloc_default ;
190+ static void * (* _Block_allocator )(size_t , const bool isOne , const bool isObject ) = _Block_alloc_default ;
194191static void (* _Block_deallocator )(const void * ) = (void (* )(const void * ))free ;
195192static void (* _Block_assign )(void * value , void * * destptr ) = _Block_assign_default ;
196193static void (* _Block_setHasRefcount )(const void * ptr , const bool hasRefcount ) = _Block_setHasRefcount_default ;
@@ -208,7 +205,7 @@ GC support SPI functions - called from ObjC runtime and CoreFoundation
208205// Public SPI
209206// Called from objc-auto to turn on GC.
210207// version 3, 4 arg, but changed 1st arg
211- void _Block_use_GC ( void * (* alloc )(const unsigned long , const bool isOne , const bool isObject ),
208+ void _Block_use_GC ( void * (* alloc )(size_t , const bool isOne , const bool isObject ),
212209 void (* setHasRefcount )(const void * , const bool ),
213210 void (* gc_assign )(void * , void * * ),
214211 void (* gc_assign_weak )(const void * , void * ),
@@ -231,7 +228,7 @@ void _Block_use_GC( void *(*alloc)(const unsigned long, const bool isOne, const
231228}
232229
233230// transitional
234- void _Block_use_GC5 ( void * (* alloc )(const unsigned long , const bool isOne , const bool isObject ),
231+ void _Block_use_GC5 ( void * (* alloc )(size_t , const bool isOne , const bool isObject ),
235232 void (* setHasRefcount )(const void * , const bool ),
236233 void (* gc_assign )(void * , void * * ),
237234 void (* gc_assign_weak )(const void * , void * )) {
0 commit comments