diff options
author | Shantonu Sen <ssen@apple.com> | 2009-09-22 00:49:12 +0000 |
---|---|---|
committer | Shantonu Sen <ssen@apple.com> | 2009-09-22 00:49:12 +0000 |
commit | b4c3b6f8a2d3481bac6b0e9b4240fa0c99412d10 (patch) | |
tree | ecfc1c923f3e6991c75264d5a8e9edd2d394e492 /BlocksRuntime | |
parent | 92a6cf5b64bb661c8b67825a4a5583eb01807633 (diff) | |
download | compiler-rt-b4c3b6f8a2d3481bac6b0e9b4240fa0c99412d10.tar.gz compiler-rt-b4c3b6f8a2d3481bac6b0e9b4240fa0c99412d10.tar.bz2 compiler-rt-b4c3b6f8a2d3481bac6b0e9b4240fa0c99412d10.tar.xz |
1) Remove cmake-specific #define usage from the exported
Block.h/Block_private.h headers, since clients won't know what to
set. These are moved into runtime.c as appropriate
2) Use cmake checks for CAS builtins, instead of guessing based on GCC
#defines (which aren't set by clang and llvm-gcc anyway)
3) "#pragma mark" isn't supported by FSF gcc, so "#if 0" it out. It
should still show up in IDEs that support it
4) Fix some compiler warnings. GCC 4.3.3 seems super strict about
%p. function pointers can't be cast to void * either.
5) Avoid a warning for apple_versioning.c that "ISO C does not allow
empty files"
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@82504 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'BlocksRuntime')
-rw-r--r-- | BlocksRuntime/Block.h | 15 | ||||
-rw-r--r-- | BlocksRuntime/Block_private.h | 13 | ||||
-rw-r--r-- | BlocksRuntime/CMakeLists.txt | 5 | ||||
-rw-r--r-- | BlocksRuntime/runtime.c | 58 |
4 files changed, 46 insertions, 45 deletions
diff --git a/BlocksRuntime/Block.h b/BlocksRuntime/Block.h index 477040c7..2f2920a5 100644 --- a/BlocksRuntime/Block.h +++ b/BlocksRuntime/Block.h @@ -22,8 +22,8 @@ * */ -#ifndef _Block_H_ -#define _Block_H_ +#ifndef _BLOCK_H_ +#define _BLOCK_H_ #if !defined(BLOCK_EXPORT) # if defined(__cplusplus) @@ -33,14 +33,7 @@ # endif #endif -#include <config.h> - -#if defined( HAVE_AVAILABILITY_MACROS_H ) && defined( HAVE_TARGET_CONDITIONALS_H ) -#include <AvailabilityMacros.h> -#include <TargetConditionals.h> -#endif /* HAVE_AVAILABILITY_MACROS_H and HAVE_TARGET_CONDITIONALS_H. */ - -#if __cplusplus +#if defined(__cplusplus) extern "C" { #endif @@ -53,7 +46,7 @@ BLOCK_EXPORT void *_Block_copy(const void *aBlock); /* Lose the reference, and if heap based and last reference, recover the memory. */ BLOCK_EXPORT void _Block_release(const void *aBlock); -#if __cplusplus +#if defined(__cplusplus) } #endif diff --git a/BlocksRuntime/Block_private.h b/BlocksRuntime/Block_private.h index e5ea8c00..f7cad030 100644 --- a/BlocksRuntime/Block_private.h +++ b/BlocksRuntime/Block_private.h @@ -33,16 +33,9 @@ # endif #endif -#include <config.h> - -#if defined( HAVE_AVAILABILITY_MACROS_H ) && defined( HAVE_TARGET_CONDITIONALS_H ) -#include <AvailabilityMacros.h> -#include <TargetConditionals.h> -#endif /* HAVE_AVAILABILITY_MACROS_H and HAVE_TARGET_CONDITIONALS_H. */ - #include <stdbool.h> -#if __cplusplus +#if defined(__cplusplus) extern "C" { #endif @@ -171,9 +164,9 @@ struct Block_basic { }; -#if __cplusplus +#if defined(__cplusplus) } #endif -#endif +#endif /* _BLOCK_PRIVATE_H_ */ diff --git a/BlocksRuntime/CMakeLists.txt b/BlocksRuntime/CMakeLists.txt index 33ab7e55..46b8993f 100644 --- a/BlocksRuntime/CMakeLists.txt +++ b/BlocksRuntime/CMakeLists.txt @@ -6,3 +6,8 @@ SET( SRCS ) ADD_LIBRARY( ${PROJECT_NAME} SHARED ${SRCS}) +SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES + INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib ) + +INSTALL( TARGETS ${PROJECT_NAME} DESTINATION lib ) +INSTALL( FILES Block.h Block_private.h DESTINATION include ) diff --git a/BlocksRuntime/runtime.c b/BlocksRuntime/runtime.c index bd079bef..dedb6eb0 100644 --- a/BlocksRuntime/runtime.c +++ b/BlocksRuntime/runtime.c @@ -27,10 +27,23 @@ #include <stdlib.h> #include <string.h> #include <stdint.h> +#include <stdbool.h> -#if TARGET_OS_MAC +#include "config.h" + +#ifdef HAVE_AVAILABILITY_MACROS_H +#include <AvailabilityMacros.h> +#endif + +#ifdef HAVE_TARGET_CONDITIONALS_H +#include <TargetConditionals.h> +#endif + +#if defined(HAVE_OSATOMIC_COMPARE_AND_SWAP_INT) && defined(HAVE_OSATOMIC_COMPARE_AND_SWAP_LONG) +#ifdef HAVE_LIBKERN_OSATOMIC_H #include <libkern/OSAtomic.h> -#elif TARGET_OS_WIN32 +#endif +#elif defined(__WIN32__) #define _CRT_SECURE_NO_WARNINGS 1 #include <windows.h> static __inline bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst) @@ -50,8 +63,7 @@ static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi, int volatile * a 64-bit system, make sure we have an 8-byte atomic function * available. */ -#elif __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 && \ - ((__SIZEOF_LONG__ != 8) || __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) +#elif defined(HAVE_SYNC_BOOL_COMPARE_AND_SWAP_INT) && defined(HAVE_SYNC_BOOL_COMPARE_AND_SWAP_LONG) static __inline bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst) { return __sync_bool_compare_and_swap(dst, oldl, newl); @@ -61,6 +73,8 @@ static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi, int volatile { return __sync_bool_compare_and_swap(dst, oldi, newi); } +#else +#error unknown atomic compare-and-swap primitive #endif @@ -143,7 +157,7 @@ static int latching_decr_int(int *where) { /*********************** GC support stub routines ************************/ -#if !TARGET_OS_WIN32 +#if 0 #pragma mark GC Support Routines #endif @@ -171,11 +185,7 @@ static void _Block_release_object_default(const void *ptr) { } static void _Block_assign_weak_default(const void *ptr, void *dest) { -#if !TARGET_OS_WIN32 - *(long *)dest = (long)ptr; -#else *(void **)dest = (void *)ptr; -#endif } static void _Block_memmove_default(void *dst, void *src, unsigned long size) { @@ -260,7 +270,7 @@ void _Block_use_RR( void (*retain)(const void *), Internal Support routines for copying ********************************************************************************/ -#if !TARGET_OS_WIN32 +#if 0 #pragma mark Copy/Release support #endif @@ -429,7 +439,7 @@ static void _Block_byref_release(const void *arg) { * ***********************************************************/ -#if !TARGET_OS_WIN32 +#if 0 #pragma mark SPI/API #endif @@ -460,7 +470,7 @@ void _Block_release(void *arg) { ; } else { - printf("Block_release called upon a stack Block: %p, ignored\n", aBlock); + printf("Block_release called upon a stack Block: %p, ignored\n", (void *)aBlock); } } @@ -498,7 +508,7 @@ unsigned long int Block_size(void *arg) { } -#if !TARGET_OS_WIN32 +#if 0 #pragma mark Compiler SPI entry points #endif @@ -595,7 +605,7 @@ void _Block_object_dispose(const void *object, const int flags) { /******************* Debugging support ********************/ -#if !TARGET_OS_WIN32 +#if 0 #pragma mark Debugging #endif @@ -612,7 +622,7 @@ const char *_Block_dump(const void *block) { printf("Block compiled by obsolete compiler, please recompile source for this Block\n"); exit(1); } - cp += sprintf(cp, "^%p (new layout) =\n", closure); + cp += sprintf(cp, "^%p (new layout) =\n", (void *)closure); if (closure->isa == NULL) { cp += sprintf(cp, "isa: NULL\n"); } @@ -632,7 +642,7 @@ const char *_Block_dump(const void *block) { cp += sprintf(cp, "isa: finalizing Block\n"); } else { - cp += sprintf(cp, "isa?: %p\n", closure->isa); + cp += sprintf(cp, "isa?: %p\n", (void *)closure->isa); } cp += sprintf(cp, "flags:"); if (closure->flags & BLOCK_HAS_DESCRIPTOR) { @@ -651,16 +661,16 @@ const char *_Block_dump(const void *block) { cp += sprintf(cp, " HASCTOR"); } cp += sprintf(cp, "\nrefcount: %u\n", closure->flags & BLOCK_REFCOUNT_MASK); - cp += sprintf(cp, "invoke: %p\n", closure->invoke); + cp += sprintf(cp, "invoke: %#lx\n", (uintptr_t)closure->invoke); { struct Block_descriptor *dp = closure->descriptor; - cp += sprintf(cp, "descriptor: %p\n", dp); + cp += sprintf(cp, "descriptor: %p\n", (void *)dp); cp += sprintf(cp, "descriptor->reserved: %lu\n", dp->reserved); cp += sprintf(cp, "descriptor->size: %lu\n", dp->size); if (closure->flags & BLOCK_HAS_COPY_DISPOSE) { - cp += sprintf(cp, "descriptor->copy helper: %p\n", dp->copy); - cp += sprintf(cp, "descriptor->dispose helper: %p\n", dp->dispose); + cp += sprintf(cp, "descriptor->copy helper: %#lx\n", (uintptr_t)dp->copy); + cp += sprintf(cp, "descriptor->dispose helper: %#lx\n", (uintptr_t)dp->dispose); } } return buffer; @@ -670,13 +680,13 @@ const char *_Block_dump(const void *block) { const char *_Block_byref_dump(struct Block_byref *src) { static char buffer[256]; char *cp = buffer; - cp += sprintf(cp, "byref data block %p contents:\n", src); - cp += sprintf(cp, " forwarding: %p\n", src->forwarding); + cp += sprintf(cp, "byref data block %p contents:\n", (void *)src); + cp += sprintf(cp, " forwarding: %p\n", (void *)src->forwarding); cp += sprintf(cp, " flags: 0x%x\n", src->flags); cp += sprintf(cp, " size: %d\n", src->size); if (src->flags & BLOCK_HAS_COPY_DISPOSE) { - cp += sprintf(cp, " copy helper: %p\n", src->byref_keep); - cp += sprintf(cp, " dispose helper: %p\n", src->byref_destroy); + cp += sprintf(cp, " copy helper: %#lx\n", (uintptr_t)src->byref_keep); + cp += sprintf(cp, " dispose helper: %#lx\n", (uintptr_t)src->byref_destroy); } return buffer; } |