From 5f01917a498951e883a91c86d02d7d201b05a0bd Mon Sep 17 00:00:00 2001 From: Zenny Chen Date: Sun, 19 Nov 2017 04:27:25 +0800 Subject: [PATCH] Update blocks_runtime.h (#45) Update blocks_runtime.h to be compatible with Apple / LLVM version. --- blocks_runtime.m | 12 ++++++------ objc/blocks_runtime.h | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/blocks_runtime.m b/blocks_runtime.m index 0ba7961..844d487 100644 --- a/blocks_runtime.m +++ b/blocks_runtime.m @@ -42,9 +42,9 @@ static void *_HeapBlockByRef = (void*)1; /** * Returns the Objective-C type encoding for the block. */ -const char *block_getType_np(void *b) +const char *block_getType_np(const void *b) { - struct Block_layout *block = b; + const struct Block_layout *block = b; if ((NULL == block) || !(block->flags & BLOCK_HAS_SIGNATURE)) { return NULL; @@ -231,10 +231,10 @@ void _Block_object_dispose(const void *object, const int flags) // Copy a block to the heap if it's still on the stack or increments its retain count. -void *_Block_copy(void *src) +void *_Block_copy(const void *src) { if (NULL == src) { return NULL; } - struct Block_layout *self = src; + struct Block_layout *self = (struct Block_layout*)src; struct Block_layout *ret = self; extern void _NSConcreteStackBlock; @@ -265,10 +265,10 @@ void *_Block_copy(void *src) } // Release a block and frees the memory when the retain count hits zero. -void _Block_release(void *src) +void _Block_release(const void *src) { if (NULL == src) { return; } - struct Block_layout *self = src; + struct Block_layout *self = (struct Block_layout*)src; extern void _NSConcreteStackBlock; extern void _NSConcreteMallocBlock; diff --git a/objc/blocks_runtime.h b/objc/blocks_runtime.h index e5dbdea..3834f54 100644 --- a/objc/blocks_runtime.h +++ b/objc/blocks_runtime.h @@ -13,9 +13,9 @@ #define BLOCKS_EXPORT extern #endif -BLOCKS_EXPORT void *_Block_copy(void *); -BLOCKS_EXPORT void _Block_release(void *); -BLOCKS_EXPORT const char *block_getType_np(void *b) OBJC_NONPORTABLE; +BLOCKS_EXPORT void *_Block_copy(const void *); +BLOCKS_EXPORT void _Block_release(const void *); +BLOCKS_EXPORT const char *block_getType_np(const void *b) OBJC_NONPORTABLE; -#define Block_copy(x) ((__typeof(x))_Block_copy((void *)(x))) -#define Block_release(x) _Block_release((void *)(x)) +#define Block_copy(x) ((__typeof(x))_Block_copy((const void *)(x))) +#define Block_release(x) _Block_release((const void *)(x))