Skip to content

Commit b5ec5d8

Browse files
authored
Merge pull request #342 from compnerd/blocks
BlocksRuntime: adjust implementation for Windows x64
2 parents 9c792ac + 4b32356 commit b5ec5d8

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

src/BlocksRuntime/runtime.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,22 @@
2828
#define os_assert(_x) assert(_x)
2929
#endif
3030

31-
#if TARGET_OS_WIN32
32-
#define _CRT_SECURE_NO_WARNINGS 1
33-
#include <windows.h>
34-
static __inline bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst)
35-
{
36-
// fixme barrier is overkill -- see objc-os.h
37-
long original = InterlockedCompareExchange(dst, newl, oldl);
38-
return (original == oldl);
39-
}
31+
#if !defined(__has_builtin)
32+
#define __has_builtin(builtin) 0
33+
#endif
4034

41-
static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi, int volatile *dst)
42-
{
43-
// fixme barrier is overkill -- see objc-os.h
44-
int original = InterlockedCompareExchange(dst, newi, oldi);
45-
return (original == oldi);
46-
}
35+
#if __has_builtin(__sync_bool_compare_and_swap)
36+
#define OSAtomicCompareAndSwapInt(_Old, _New, _Ptr) \
37+
__sync_bool_compare_and_swap(_Ptr, _Old, _New)
4738
#else
48-
#define OSAtomicCompareAndSwapLong(_Old, _New, _Ptr) __sync_bool_compare_and_swap(_Ptr, _Old, _New)
49-
#define OSAtomicCompareAndSwapInt(_Old, _New, _Ptr) __sync_bool_compare_and_swap(_Ptr, _Old, _New)
39+
#define _CRT_SECURE_NO_WARNINGS 1
40+
#include <Windows.h>
41+
static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi,
42+
int volatile *dst) {
43+
// fixme barrier is overkill -- see objc-os.h
44+
int original = InterlockedCompareExchange((LONG volatile *)dst, newi, oldi);
45+
return (original == oldi);
46+
}
5047
#endif
5148

5249
/***********************
@@ -141,13 +138,13 @@ static bool latching_decr_int_now_zero(volatile int32_t *where) {
141138
/***********************
142139
GC support stub routines
143140
************************/
144-
#if !TARGET_OS_WIN32
141+
#if !defined(_MSC_VER) || defined(__clang__)
145142
#pragma mark GC Support Routines
146143
#endif
147144

148145

149146

150-
static void *_Block_alloc_default(const unsigned long size, const bool initialCountIsOne, const bool isObject) {
147+
static void *_Block_alloc_default(size_t size, const bool initialCountIsOne, const bool isObject) {
151148
(void)initialCountIsOne;
152149
(void)isObject;
153150
return malloc(size);
@@ -207,7 +204,7 @@ static void _Block_destructInstance_default(const void *aBlock) {
207204
GC support callout functions - initially set to stub routines
208205
***************************************************************************/
209206

210-
static void *(*_Block_allocator)(const unsigned long, const bool isOne, const bool isObject) = _Block_alloc_default;
207+
static void *(*_Block_allocator)(size_t, const bool isOne, const bool isObject) = _Block_alloc_default;
211208
static void (*_Block_deallocator)(const void *) = (void (*)(const void *))free;
212209
static void (*_Block_assign)(void *value, void **destptr) = _Block_assign_default;
213210
static void (*_Block_setHasRefcount)(const void *ptr, const bool hasRefcount) = _Block_setHasRefcount_default;
@@ -226,7 +223,7 @@ GC support SPI functions - called from ObjC runtime and CoreFoundation
226223
// Public SPI
227224
// Called from objc-auto to turn on GC.
228225
// version 3, 4 arg, but changed 1st arg
229-
void _Block_use_GC( void *(*alloc)(const unsigned long, const bool isOne, const bool isObject),
226+
void _Block_use_GC( void *(*alloc)(size_t, const bool isOne, const bool isObject),
230227
void (*setHasRefcount)(const void *, const bool),
231228
void (*gc_assign)(void *, void **),
232229
void (*gc_assign_weak)(const void *, void *),
@@ -249,7 +246,7 @@ void _Block_use_GC( void *(*alloc)(const unsigned long, const bool isOne, const
249246
}
250247

251248
// transitional
252-
void _Block_use_GC5( void *(*alloc)(const unsigned long, const bool isOne, const bool isObject),
249+
void _Block_use_GC5( void *(*alloc)(size_t, const bool isOne, const bool isObject),
253250
void (*setHasRefcount)(const void *, const bool),
254251
void (*gc_assign)(void *, void **),
255252
void (*gc_assign_weak)(const void *, void *)) {
@@ -339,7 +336,7 @@ static void _Block_call_dispose_helper(struct Block_layout *aBlock)
339336
Internal Support routines for copying
340337
********************************************************************************/
341338

342-
#if !TARGET_OS_WIN32
339+
#if !defined(_MSC_VER) || defined(__clang__)
343340
#pragma mark Copy/Release support
344341
#endif
345342

@@ -500,7 +497,7 @@ static void _Block_byref_release(const void *arg) {
500497
*
501498
***********************************************************/
502499

503-
#if !TARGET_OS_WIN32
500+
#if !defined(_MSC_VER) || defined(__clang__)
504501
#pragma mark SPI/API
505502
#endif
506503

@@ -632,7 +629,7 @@ const char * _Block_extended_layout(void *aBlock)
632629
else return desc3->layout;
633630
}
634631

635-
#if !TARGET_OS_WIN32
632+
#if !defined(_MSC_VER) || defined(__clang__)
636633
#pragma mark Compiler SPI entry points
637634
#endif
638635

0 commit comments

Comments
 (0)