[libdispatch-dev] [PATCH 05/17] more precise detection of blocks

Paolo Bonzini bonzini at gnu.org
Sun Oct 18 08:04:05 PDT 2009


I now make the test a bit more precise; for some reason my first LLVM
installation had blocks but no Blocks.h and Blocks_private.h.  After
adding this check, using __BLOCKS__ is not sufficient anymore hence
I changed it all over the place to an autoconfy HAVE_BLOCKS symbol.
---
 m4/blocks.m4        |   10 +++++++-
 src/apply.c         |    4 +-
 src/benchmark.c     |    2 +-
 src/internal.h      |    8 +++---
 src/legacy.c        |   24 ++++++++++----------
 src/legacy.h        |   60 +++++++++++++++++++++++++-------------------------
 src/once.c          |    2 +-
 src/queue.c         |   22 +++++++++---------
 src/queue_private.h |    4 +-
 src/semaphore.c     |    4 +-
 src/source.c        |   26 +++++++++++-----------
 11 files changed, 87 insertions(+), 79 deletions(-)

diff --git a/m4/blocks.m4 b/m4/blocks.m4
index ad74479..988313a 100644
--- a/m4/blocks.m4
+++ b/m4/blocks.m4
@@ -6,7 +6,10 @@ AC_DEFUN([DISPATCH_C_BLOCKS], [
 AC_CACHE_CHECK([for C Blocks support], [dispatch_cv_cblocks], [
   saveCFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS -fblocks"
-  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[(void)^{int i; i = 0; }();])], [
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+     [#include <Block.h>
+      #include <Block_private.h>],
+     [(void)^{int i; i = 0; }();])], [
     CFLAGS="$saveCFLAGS"
     dispatch_cv_cblocks="-fblocks"
   ], [
@@ -15,6 +18,11 @@ AC_CACHE_CHECK([for C Blocks support], [dispatch_cv_cblocks], [
   ])
 ])
 
+if test "x$dispatch_cv_cblocks" != xno; then
+  AC_DEFINE([HAVE_BLOCKS],,
+            [Define if your compiler and runtime support blocks.])
+fi
+
 #
 # Allow configure to be passed a path to the directory where it should look
 # for the Blocks runtime library, if any.
diff --git a/src/apply.c b/src/apply.c
index 2c51eb2..90a8ce7 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -71,7 +71,7 @@ _dispatch_apply_serial(void *context)
 	} while (++idx < da->da_iterations);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 void
 dispatch_apply(size_t iterations, dispatch_queue_t dq, void (^work)(size_t))
 {
@@ -143,7 +143,7 @@ dispatch_apply_f(size_t iterations, dispatch_queue_t dq, void *ctxt, void (*func
 }
 
 #if 0
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 void
 dispatch_stride(size_t offset, size_t stride, size_t iterations, dispatch_queue_t dq, void (^work)(size_t))
 {
diff --git a/src/benchmark.c b/src/benchmark.c
index d52191d..5bc52b6 100644
--- a/src/benchmark.c
+++ b/src/benchmark.c
@@ -71,7 +71,7 @@ _dispatch_benchmark_init(void *context)
 	bdata->loop_cost = lcost;
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 uint64_t
 dispatch_benchmark(size_t count, void (^block)(void))
 {
diff --git a/src/internal.h b/src/internal.h
index 6e2f6e5..3a3a4ee 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -102,10 +102,10 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 #include <Block_private.h>
 #include <Block.h>
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 #include <assert.h>
 #include <errno.h>
@@ -221,11 +221,11 @@ void _dispatch_logv(const char *msg, va_list) __attribute__((__noinline__,__form
 
 
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_block_t _dispatch_Block_copy(dispatch_block_t block);
 void _dispatch_call_block_and_release(void *block);
 void _dispatch_call_block_and_release2(void *block, void *ctxt);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 void dummy_function(void);
 long dummy_function_r0(void);
diff --git a/src/legacy.c b/src/legacy.c
index f598dee..ed37141 100644
--- a/src/legacy.c
+++ b/src/legacy.c
@@ -26,7 +26,7 @@
  * earlier revision of the API. These interfaces WILL be removed in the future.
  */
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 DISPATCH_PUBLIC_API DISPATCH_NONNULL1 DISPATCH_NONNULL2
 dispatch_item_t
 LEGACY_dispatch_call(dispatch_queue_t, dispatch_legacy_block_t work, dispatch_legacy_block_t completion)
@@ -46,7 +46,7 @@ LEGACY_dispatch_queue_get_current(void)
 	return _dispatch_queue_get_current();
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_item_t
 LEGACY_dispatch_call(dispatch_queue_t dq,
 	dispatch_legacy_block_t dispatch_block,
@@ -81,7 +81,7 @@ LEGACY_dispatch_call(dispatch_queue_t dq,
 
 	return di;
 }
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 #ifndef DISPATCH_NO_LEGACY
 
@@ -165,7 +165,7 @@ dispatch_source_custom_create_f(
 
 
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_source_t
 dispatch_source_timer_create(uint64_t flags,
 	uint64_t nanoseconds,
@@ -225,7 +225,7 @@ dispatch_source_timer_create_f(uint64_t timer_flags,
 	return ds;
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_source_t
 dispatch_source_read_create(int descriptor,
 	dispatch_source_attr_t attr,
@@ -249,7 +249,7 @@ dispatch_source_read_create_f(int fd,
 	return _dispatch_source_create2(ds, attr, context, callback);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_source_t
 dispatch_source_write_create(int descriptor,
 	dispatch_source_attr_t attr,
@@ -273,7 +273,7 @@ dispatch_source_write_create_f(int fd,
 	return _dispatch_source_create2(ds, attr, context, callback);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_source_t
 dispatch_source_vnode_create(int descriptor,
 	uint64_t flags,
@@ -299,7 +299,7 @@ dispatch_source_vnode_create_f(int fd,
 	return _dispatch_source_create2(ds, attr, context, callback);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_source_t
 dispatch_source_signal_create(unsigned long sig,
 	dispatch_source_attr_t attr,
@@ -323,7 +323,7 @@ dispatch_source_signal_create_f(unsigned long signo,
 	return _dispatch_source_create2(ds, attr, context, callback);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_source_t
 dispatch_source_proc_create(pid_t pid,
 	uint64_t flags,
@@ -349,7 +349,7 @@ dispatch_source_proc_create_f(pid_t pid,
 	return _dispatch_source_create2(ds, attr, context, callback);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_source_t
 dispatch_source_vfs_create(uint64_t flags,
 	dispatch_source_attr_t attr,
@@ -373,7 +373,7 @@ dispatch_source_vfs_create_f(uint64_t event_mask,
 	return _dispatch_source_create2(ds, attr, context, callback);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_source_t
 dispatch_source_data_create(unsigned long behavior,
 	dispatch_source_attr_t attr,
@@ -385,7 +385,7 @@ dispatch_source_data_create(unsigned long behavior,
 }
 #endif
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_source_t
 dispatch_source_machport_create(mach_port_t mport,
 	uint64_t flags,
diff --git a/src/legacy.h b/src/legacy.h
index 85349ad..e2f825c 100644
--- a/src/legacy.h
+++ b/src/legacy.h
@@ -65,7 +65,7 @@ struct dispatch_item_s {
 typedef struct dispatch_source_s *dispatch_event_t;
 
 // Obsolete
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 typedef void (^dispatch_legacy_block_t)(dispatch_item_t);
 typedef void (^dispatch_queue_deletion_block_t)(dispatch_queue_t queue);
 typedef void (^dispatch_source_deletion_t)(dispatch_source_t source);
@@ -73,7 +73,7 @@ typedef void (^dispatch_event_callback_t)(dispatch_event_t event);
 typedef void (^dispatch_source_handler_t)(dispatch_source_t source);
 typedef dispatch_source_handler_t dispatch_event_handler_t;
 typedef void (^dispatch_source_finalizer_t)(dispatch_source_t source);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Obsolete
 typedef void (*dispatch_source_handler_function_t)(void *, dispatch_source_t);
@@ -84,7 +84,7 @@ DISPATCH_DECL(dispatch_source_attr);
 
 #define DISPATCH_SOURCE_CREATE_SUSPENDED	((dispatch_source_attr_t)~0ul)
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 typedef void (^dispatch_queue_finalizer_t)(dispatch_queue_t queue);
 #endif
 
@@ -134,7 +134,7 @@ DISPATCH_NONNULL1 DISPATCH_NOTHROW
 void
 dispatch_queue_attr_set_priority(dispatch_queue_attr_t attr, int priority);
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_NONNULL1 DISPATCH_NOTHROW
 long
@@ -187,12 +187,12 @@ DISPATCH_PUBLIC_API //DISPATCH_DEPRECATED
 void
 dispatch_queue_attr_set_flags(dispatch_queue_attr_t attr, uint64_t flags);
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 DISPATCH_PUBLIC_API DISPATCH_NONNULL1 DISPATCH_NONNULL2 DISPATCH_DEPRECATED
 dispatch_item_t
 dispatch_call(dispatch_queue_t, dispatch_legacy_block_t work, dispatch_legacy_block_t completion)
 __asm__("_dispatch_call2");
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 DISPATCH_PUBLIC_API DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_DEPRECATED
 dispatch_queue_t
@@ -380,12 +380,12 @@ dispatch_source_attr_t
 dispatch_source_attr_create(void);
 
 // Obsolete
-#if defined(__BLOCKS__)
+#if defined(HAVE_BLOCKS)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_NOTHROW
 dispatch_source_finalizer_t
 dispatch_source_attr_get_finalizer(dispatch_source_attr_t attr);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Obsolete
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -394,14 +394,14 @@ dispatch_source_attr_t
 dispatch_source_attr_copy(dispatch_source_attr_t proto);
 
 // Obsolete
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_NONNULL1 DISPATCH_NOTHROW
 long
 dispatch_source_attr_set_finalizer(
 	dispatch_source_attr_t attr,
 	dispatch_source_finalizer_t finalizer);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Obsolete
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -444,7 +444,7 @@ enum {
 };
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, ...)
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_MALLOC DISPATCH_NONNULL5 DISPATCH_NONNULL6 DISPATCH_NOTHROW
 dispatch_source_t
@@ -455,7 +455,7 @@ dispatch_source_timer_create(
 	dispatch_source_attr_t attr,
 	dispatch_queue_t queue,
 	dispatch_source_handler_t handler);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, ...)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -471,7 +471,7 @@ dispatch_source_timer_create_f(
 	dispatch_source_handler_function_t handler);
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, ...)
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_MALLOC DISPATCH_NOTHROW
 dispatch_source_t
@@ -480,7 +480,7 @@ dispatch_source_signal_create(
 	dispatch_source_attr_t attr,
 	dispatch_queue_t queue,
 	dispatch_source_handler_t handler);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, ...)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -494,7 +494,7 @@ dispatch_source_signal_create_f(
 	dispatch_source_handler_function_t handler);
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, ...)
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_MALLOC DISPATCH_NONNULL3 DISPATCH_NONNULL4 DISPATCH_NOTHROW
 dispatch_source_t
@@ -503,7 +503,7 @@ dispatch_source_read_create(
 	dispatch_source_attr_t attr,
 	dispatch_queue_t queue,
 	dispatch_source_handler_t handler);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, ...)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -517,7 +517,7 @@ dispatch_source_read_create_f(
 	dispatch_source_handler_function_t handler);
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_WRITE, ...)
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_MALLOC DISPATCH_NONNULL3 DISPATCH_NONNULL4 DISPATCH_NOTHROW
 dispatch_source_t
@@ -526,7 +526,7 @@ dispatch_source_write_create(
 	dispatch_source_attr_t attr,
 	dispatch_queue_t queue,
 	dispatch_source_handler_t handler);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_WRITE, ...)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -540,7 +540,7 @@ dispatch_source_write_create_f(
 	dispatch_source_handler_function_t handler);
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, ...)
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_MALLOC DISPATCH_NONNULL4 DISPATCH_NONNULL5 DISPATCH_NOTHROW
 dispatch_source_t
@@ -550,7 +550,7 @@ dispatch_source_vnode_create(
 	dispatch_source_attr_t attr,
 	dispatch_queue_t queue,
 	dispatch_source_handler_t handler);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, ...)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -565,7 +565,7 @@ dispatch_source_vnode_create_f(
 	dispatch_source_handler_function_t handler);
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, ...)
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_MALLOC DISPATCH_NONNULL4 DISPATCH_NONNULL5 DISPATCH_NOTHROW
 dispatch_source_t
@@ -575,7 +575,7 @@ dispatch_source_proc_create(
 	dispatch_source_attr_t attr,
 	dispatch_queue_t queue,
 	dispatch_source_handler_t handler);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, ...)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -597,7 +597,7 @@ enum {
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, ...)
 #ifdef HAVE_MACH
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_MALLOC DISPATCH_NOTHROW
 dispatch_source_t
@@ -607,7 +607,7 @@ dispatch_source_machport_create(
 	dispatch_source_attr_t attr,
 	dispatch_queue_t queue,
 	dispatch_source_handler_t handler);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, ...)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -628,7 +628,7 @@ enum {
 };
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_DATA..., ...)
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_MALLOC DISPATCH_NONNULL3 DISPATCH_NONNULL4 DISPATCH_NOTHROW
 dispatch_source_t
@@ -637,7 +637,7 @@ dispatch_source_data_create(
 	dispatch_source_attr_t attr,
 	dispatch_queue_t queue,
 	dispatch_source_handler_t handler);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_DATA..., ...)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -656,7 +656,7 @@ enum {
 };
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_DATA..., ...)
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_MALLOC DISPATCH_NONNULL2 DISPATCH_NONNULL3 DISPATCH_NOTHROW
 dispatch_source_t
@@ -665,7 +665,7 @@ dispatch_source_custom_create(
 							  dispatch_source_attr_t attr,
 							  dispatch_queue_t queue,
 							  dispatch_event_handler_t handler);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_DATA..., ...)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
@@ -679,7 +679,7 @@ dispatch_source_custom_create_f(
 								dispatch_event_handler_function_t handler);
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_VFS, ...)
-#if defined(__BLOCKS__)
+#if defined(HAVE_BLOCKS)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_MALLOC DISPATCH_NONNULL3 DISPATCH_NONNULL4
 dispatch_source_t
@@ -688,7 +688,7 @@ dispatch_source_vfs_create(
 						   dispatch_source_attr_t attr,
 						   dispatch_queue_t queue,
 						   dispatch_source_handler_t handler);
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 // Use: dispatch_source_create(DISPATCH_SOURCE_TYPE_VFS, ...)
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
diff --git a/src/once.c b/src/once.c
index 9046c06..bf90660 100644
--- a/src/once.c
+++ b/src/once.c
@@ -23,7 +23,7 @@
 #undef dispatch_once
 #undef dispatch_once_f
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 void
 dispatch_once(dispatch_once_t *val, void (^block)(void))
 {
diff --git a/src/queue.c b/src/queue.c
index 5918ed2..97ec7f8 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -99,7 +99,7 @@ _dispatch_get_root_queue(long priority, bool overcommit)
 	}
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 dispatch_block_t
 _dispatch_Block_copy(dispatch_block_t db)
 {
@@ -129,7 +129,7 @@ _dispatch_call_block_and_release2(void *block, void *ctxt)
 	Block_release(b);
 }
 
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 struct dispatch_queue_attr_vtable_s {
 	DISPATCH_VTABLE_HEADER(dispatch_queue_attr_s);
@@ -573,7 +573,7 @@ dispatch_queue_create(const char *label, dispatch_queue_attr_t attr)
 		dq->do_targetq = _dispatch_get_root_queue(attr->qa_priority, attr->qa_flags & DISPATCH_QUEUE_OVERCOMMIT);
 		dq->dq_finalizer_ctxt = attr->finalizer_ctxt;
 		dq->dq_finalizer_func = attr->finalizer_func;
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 		if (attr->finalizer_func == (void*)_dispatch_call_block_and_release2) {
 			// if finalizer_ctxt is a Block, retain it.
  			dq->dq_finalizer_ctxt = Block_copy(dq->dq_finalizer_ctxt);
@@ -589,7 +589,7 @@ dispatch_queue_create(const char *label, dispatch_queue_attr_t attr)
 
 	return dq;
 
-#if !defined(DISPATCH_NO_LEGACY) && defined(__BLOCKS__)
+#if !defined(DISPATCH_NO_LEGACY) && defined(HAVE_BLOCKS)
 out_bad:
 #endif
 	free(dq);
@@ -632,7 +632,7 @@ _dispatch_barrier_async_f_slow(dispatch_queue_t dq, void *context, dispatch_func
 	_dispatch_queue_push(dq, dc);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 void
 dispatch_barrier_async(dispatch_queue_t dq, void (^work)(void))
 {
@@ -670,7 +670,7 @@ _dispatch_async_f_slow(dispatch_queue_t dq, void *context, dispatch_function_t f
 	_dispatch_queue_push(dq, dc);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 void
 dispatch_async(dispatch_queue_t dq, void (^work)(void))
 {
@@ -744,7 +744,7 @@ _dispatch_barrier_sync_f_slow(dispatch_queue_t dq, void *ctxt, dispatch_function
 	_dispatch_put_thread_semaphore(dbss2.dbss2_sema);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 void
 dispatch_barrier_sync(dispatch_queue_t dq, void (^work)(void))
 {
@@ -809,7 +809,7 @@ _dispatch_sync_f_slow(dispatch_queue_t dq)
 	_dispatch_put_thread_semaphore(dss.dc_ctxt);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 void
 dispatch_sync(dispatch_queue_t dq, void (^work)(void))
 {
@@ -1615,7 +1615,7 @@ void
 dispatch_queue_attr_set_finalizer_f(dispatch_queue_attr_t attr,
         void *context, dispatch_queue_finalizer_function_t finalizer)
 {
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 	if (attr->finalizer_func == (void*)_dispatch_call_block_and_release2) {
 		Block_release(attr->finalizer_ctxt);
 	}
@@ -1624,7 +1624,7 @@ dispatch_queue_attr_set_finalizer_f(dispatch_queue_attr_t attr,
 	attr->finalizer_func = finalizer;
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 long
 dispatch_queue_attr_set_finalizer(dispatch_queue_attr_t attr,
         dispatch_queue_finalizer_t finalizer)
@@ -2115,7 +2115,7 @@ const struct dispatch_queue_offsets_s dispatch_queue_offsets = {
 	.dqo_running_size = sizeof(_dispatch_main_q.dq_running),
 };
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 void
 dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t work)
 {
diff --git a/src/queue_private.h b/src/queue_private.h
index 85f87c0..b3ceee6 100644
--- a/src/queue_private.h
+++ b/src/queue_private.h
@@ -48,7 +48,7 @@ enum {
 
 #define DISPATCH_QUEUE_FLAGS_MASK	(DISPATCH_QUEUE_OVERCOMMIT)
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
 void
@@ -60,7 +60,7 @@ DISPATCH_NONNULL1 DISPATCH_NONNULL3 DISPATCH_NOTHROW
 void
 dispatch_barrier_sync_f(dispatch_queue_t dq, void *context, dispatch_function_t work);
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_NA)
 DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
 void
diff --git a/src/semaphore.c b/src/semaphore.c
index 3b03868..aa066be 100644
--- a/src/semaphore.c
+++ b/src/semaphore.c
@@ -554,7 +554,7 @@ dispatch_group_wait(dispatch_group_t dg, dispatch_time_t timeout)
 	return _dispatch_group_wait_slow(dsema, timeout);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 void
 dispatch_group_notify(dispatch_group_t dg, dispatch_queue_t dq, dispatch_block_t db)
 {
@@ -636,7 +636,7 @@ _dispatch_semaphore_debug(dispatch_semaphore_t dsema, char *buf, size_t bufsiz)
 	return offset;
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 void
 dispatch_group_async(dispatch_group_t dg, dispatch_queue_t dq, dispatch_block_t db)
 {
diff --git a/src/source.c b/src/source.c
index 87f4526..d56bb99 100644
--- a/src/source.c
+++ b/src/source.c
@@ -746,7 +746,7 @@ _dispatch_source_cancel_callout(dispatch_source_t ds)
 	ds->ds_pending_data = 0;
 	ds->ds_data = 0;
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 	if (ds->ds_handler_is_block) {
 		Block_release(ds->ds_handler_ctxt);
 		ds->ds_handler_is_block = false;
@@ -759,7 +759,7 @@ _dispatch_source_cancel_callout(dispatch_source_t ds)
 		return;
 	}
 	if (ds->ds_cancel_is_block) {
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 		dispatch_block_t b = ds->ds_cancel_handler;
 		if (ds->ds_atomic_flags & DSF_CANCELED) {
 			b();
@@ -854,7 +854,7 @@ void
 dispatch_source_attr_set_finalizer_f(dispatch_source_attr_t attr,
 	void *context, dispatch_source_finalizer_function_t finalizer)
 {
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 	if (attr->finalizer_func == (void*)_dispatch_call_block_and_release2) {
 		Block_release(attr->finalizer_ctxt);
 	}
@@ -864,7 +864,7 @@ dispatch_source_attr_set_finalizer_f(dispatch_source_attr_t attr,
 	attr->finalizer_func = finalizer;
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 long
 dispatch_source_attr_set_finalizer(dispatch_source_attr_t attr,
 	dispatch_source_finalizer_t finalizer)
@@ -913,7 +913,7 @@ dispatch_source_attr_copy(dispatch_source_attr_t proto)
 
 	if (proto && (rval = malloc(sizeof(struct dispatch_source_attr_s)))) {
 		memcpy(rval, proto, sizeof(struct dispatch_source_attr_s));
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 		if (rval->finalizer_func == (void*)_dispatch_call_block_and_release2) {
 			rval->finalizer_ctxt = Block_copy(rval->finalizer_ctxt);
 		}
@@ -1141,7 +1141,7 @@ out_bad:
 	return NULL;
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 // 6618342 Contact the team that owns the Instrument DTrace probe before renaming this symbol
 static void
 _dispatch_source_set_event_handler2(void *context)
@@ -1167,7 +1167,7 @@ dispatch_source_set_event_handler(dispatch_source_t ds, dispatch_block_t handler
 	dispatch_barrier_async_f((dispatch_queue_t)ds,
 		handler, _dispatch_source_set_event_handler2);
 }
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 static void
 _dispatch_source_set_event_handler_f(void *context)
@@ -1175,7 +1175,7 @@ _dispatch_source_set_event_handler_f(void *context)
 	dispatch_source_t ds = (dispatch_source_t)_dispatch_queue_get_current();
 	dispatch_assert(ds->do_vtable == &_dispatch_source_kevent_vtable);
 	
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 	if (ds->ds_handler_is_block && ds->ds_handler_ctxt) {
 		Block_release(ds->ds_handler_ctxt);
 	}
@@ -1194,7 +1194,7 @@ dispatch_source_set_event_handler_f(dispatch_source_t ds,
 		handler, _dispatch_source_set_event_handler_f);
 }
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 // 6618342 Contact the team that owns the Instrument DTrace probe before renaming this symbol
 static void
 _dispatch_source_set_cancel_handler2(void *context)
@@ -1218,7 +1218,7 @@ dispatch_source_set_cancel_handler(dispatch_source_t ds,
 	dispatch_barrier_async_f((dispatch_queue_t)ds,
 							 handler, _dispatch_source_set_cancel_handler2);
 }
-#endif /* __BLOCKS__ */
+#endif /* HAVE_BLOCKS */
 
 static void
 _dispatch_source_set_cancel_handler_f(void *context)
@@ -1226,7 +1226,7 @@ _dispatch_source_set_cancel_handler_f(void *context)
 	dispatch_source_t ds = (dispatch_source_t)_dispatch_queue_get_current();
 	dispatch_assert(ds->do_vtable == &_dispatch_source_kevent_vtable);
 	
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 	if (ds->ds_cancel_is_block && ds->ds_cancel_handler) {
 		Block_release(ds->ds_cancel_handler);
 	}
@@ -1266,7 +1266,7 @@ _dispatch_source_create2(dispatch_source_t ds,
 		ds->dq_finalizer_func = (typeof(ds->dq_finalizer_func))attr->finalizer_func;
 		ds->do_ctxt = attr->context;
 	}
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 	if (ds->dq_finalizer_func == (void*)_dispatch_call_block_and_release2) {
 		ds->dq_finalizer_ctxt = Block_copy(ds->dq_finalizer_ctxt);
 		if (!ds->dq_finalizer_ctxt) {
@@ -1308,7 +1308,7 @@ _dispatch_source_create2(dispatch_source_t ds,
 
 	return ds;
 
-#ifdef __BLOCKS__
+#ifdef HAVE_BLOCKS
 out_bad:
 	free(ds);
 	return NULL;
-- 
1.6.2.5





More information about the libdispatch-dev mailing list