From 4305eb8e6c0e8ad0db9db29b38510d5815ccaabf Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 21 Nov 2013 09:49:05 +0000 Subject: [PATCH] gc.c: malloc_usable_size * gc.c (vm_xrealloc, vm_xfree): use malloc_usable_size() to obtain old size if available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ configure.in | 1 + gc.c | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index bc4f94f0e1..908fdf9dac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Nov 21 18:49:02 2013 Nobuyoshi Nakada + + * 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 * 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) diff --git a/gc.c b/gc.c index 3c1c63d1d8..c15b19c44f 100644 --- a/gc.c +++ b/gc.c @@ -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); }