diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | gc.c | 10 |
3 files changed, 16 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Thu Nov 21 18:49:02 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * gc.c (vm_xrealloc, vm_xfree): use malloc_usable_size() to obtain old + size if available. + Thu Nov 21 18:47:29 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/delegate.rb (SimpleDelegator#__getobj__): target object must be set. diff --git a/configure.in b/configure.in index a4080e1a00..ab0cea9905 100644 --- a/configure.in +++ b/configure.in @@ -1851,6 +1851,7 @@ AC_CHECK_FUNCS(llabs) AC_CHECK_FUNCS(lockf) AC_CHECK_FUNCS(log2) AC_CHECK_FUNCS(lstat) +AC_CHECK_FUNCS(malloc_usable_size) AC_CHECK_FUNCS(mblen) AC_CHECK_FUNCS(memalign) AC_CHECK_FUNCS(memrchr) @@ -5553,6 +5553,10 @@ vm_xrealloc(rb_objspace_t *objspace, void *ptr, size_t new_size, size_t old_size return 0; } +#ifdef HAVE_MALLOC_USABLE_SIZE + old_size = malloc_usable_size(ptr); +#endif + vm_malloc_increase(objspace, new_size, old_size, FALSE); #if CALC_EXACT_MALLOC_SIZE @@ -5587,7 +5591,13 @@ vm_xfree(rb_objspace_t *objspace, void *ptr, size_t old_size) ATOMIC_SIZE_SUB(objspace->malloc_params.allocated_size, cem_oldsize); ATOMIC_SIZE_DEC(objspace->malloc_params.allocations); } +#endif +#ifdef HAVE_MALLOC_USABLE_SIZE + old_size = malloc_usable_size(ptr); +#endif + +#if CALC_EXACT_MALLOC_SIZE if (CALC_EXACT_MALLOC_SIZE_CHECK_OLD_SIZE && old_size > 0 && cem_oldsize - sizeof(size_t) != old_size) { fprintf(stderr, "vm_xfree: old_size mismatch: expected %d, but %d\n", (int)(cem_oldsize-sizeof(size_t)), (int)old_size); } |