In the sqlite3MemInit() function, sqlite uses OS X's OSAtomicCompareAndSwapPtrBarrier() function once. This function was introduced in Mac OS X 10.5, but 10.4 has 32-bit and 64-bit specific versions; the PtrBarrier version is simply designed to work with the size of pointers on both 32-bit and 64-bit systems.
The attached patch for this issue is based on a similar solution adopted by fontconfig: http://cgit.freedesktop.org/fontconfig/commit/?id=0f9aa8759df563332db60055ae33dd9424ebf802It defines a macro for the function, which calls OSAtomicCompareAndSwapPtrBarrier() if available and otherwise calls OSAtomicCompareAndSwap32Barrier() or OSAtomicCompareAndSwap64Barrier() as appropriate. The patch contains an explanatory comment, but still uses fontconfig's macro name, which I can change if you rather. Thanks, Misty De Meo --- sqlite3.c.orig 2013-08-27 18:37:13.000000000 -0700 +++ sqlite3.c 2013-08-27 21:25:45.000000000 -0700 @@ -15685,6 +15685,7 @@ #include <sys/sysctl.h> #include <malloc/malloc.h> #include <libkern/OSAtomic.h> + static malloc_zone_t* _sqliteZone_; #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x)) #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x)); @@ -15692,6 +15693,29 @@ #define SQLITE_MALLOCSIZE(x) \ (_sqliteZone_ ? _sqliteZone_->size(_sqliteZone_,x) : malloc_size(x)) +/* +** If compiling for Mac OS X 10.4, the OSAtomicCompareAndSwapPtrBarrier +** function will not be available, but individual 32-bit and 64-bit +** versions will. +*/ + +#ifdef __MAC_OS_X_MIN_REQUIRED +# include <AvailabilityMacros.h> +#elif defined(__IPHONE_OS_MIN_REQUIRED) +# include <Availability.h> +#endif + +typedef int fc_atomic_int_t; +#if (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 || __IPHONE_VERSION_MIN_REQUIRED >= 20100) +# define fc_atomic_ptr_cmpexch(O,N,P) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P)) +#else +# if __ppc64__ || __x86_64__ +# define fc_atomic_ptr_cmpexch(O,N,P) OSAtomicCompareAndSwap64Barrier ((int64_t) (O), (int64_t) (N), (int64_t*) (P)) +# else +# define fc_atomic_ptr_cmpexch(O,N,P) OSAtomicCompareAndSwap32Barrier ((int32_t) (O), (int32_t) (N), (int32_t*) (P)) +# endif +#endif + #else /* if not __APPLE__ */ /* @@ -15852,7 +15876,7 @@ malloc_zone_t* newzone = malloc_create_zone(4096, 0); malloc_set_zone_name(newzone, "Sqlite_Heap"); do{ - success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, + success = fc_atomic_ptr_cmpexch(NULL, newzone, (void * volatile *)&_sqliteZone_); }while(!_sqliteZone_); if( !success ){ _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users