ruby-changes:23034
From: yugui <ko1@a...>
Date: Sun, 18 Mar 2012 20:16:00 +0900 (JST)
Subject: [ruby-changes:23034] yugui:r35083 (trunk): * gc.c (aligned_malloc, aligned_free): added fallback implementations
yugui 2012-03-18 20:15:50 +0900 (Sun, 18 Mar 2012) New Revision: 35083 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35083 Log: * gc.c (aligned_malloc, aligned_free): added fallback implementations for platforms like OSX Leopard. Modified files: trunk/ChangeLog trunk/gc.c Index: ChangeLog =================================================================== --- ChangeLog (revision 35082) +++ ChangeLog (revision 35083) @@ -1,3 +1,8 @@ +Sun Mar 18 18:31:45 2012 Yuki Sonoda (Yugui) <yugui@y...> + + * gc.c (aligned_malloc, aligned_free): added fallback implementations + for platforms like OSX Leopard. + Sun Mar 18 17:17:48 2012 Nobuyoshi Nakada <nobu@r...> * bignum.c (rb_big_pow): estimate result bit size more precisely. Index: gc.c =================================================================== --- gc.c (revision 35082) +++ gc.c (revision 35083) @@ -1106,8 +1106,19 @@ #elif defined(HAVE_MEMALIGN) res = memalign(alignment, size); #else -#error no memalign function + char* aligned; + res = malloc(alignment + size + sizeof(void*)); + aligned = (char*)res + alignment + sizeof(void*); + aligned -= ((VALUE)aligned & (alignment - 1)); + ((void**)aligned)[-1] = res; + res = (void*)aligned; #endif + +#if defined(_DEBUG) || defined(GC_DEBUG) + /* alignment must be a power of 2 */ + assert((alignment - 1) & alignment == 0); + assert(alignment % sizeof(void*) == 0); +#endif return res; } @@ -1118,8 +1129,10 @@ __mingw_aligned_free(ptr); #elif defined _WIN32 && !defined __CYGWIN__ _aligned_free(ptr); +#elif defined(HAVE_MEMALIGN) && defined(HAVE_POSIX_MEMALIGN) + free(ptr); #else - free(ptr); + free(((void**)ptr)[-1]); #endif } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/