ruby-changes:32038
From: nobu <ko1@a...>
Date: Tue, 10 Dec 2013 16:16:12 +0900 (JST)
Subject: [ruby-changes:32038] nobu:r44117 (trunk): gc.c: ruby_sized_xrealloc2
nobu 2013-12-10 16:16:06 +0900 (Tue, 10 Dec 2013) New Revision: 44117 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44117 Log: gc.c: ruby_sized_xrealloc2 * gc.c (ruby_sized_xrealloc2): reallocate from old size. Modified files: trunk/gc.c trunk/internal.h Index: gc.c =================================================================== --- gc.c (revision 44116) +++ gc.c (revision 44117) @@ -6122,14 +6122,23 @@ ruby_xrealloc(void *ptr, size_t new_size https://github.com/ruby/ruby/blob/trunk/gc.c#L6122 return ruby_sized_xrealloc(ptr, new_size, 0); } +#ifdef ruby_sized_xrealloc2 +#undef ruby_sized_xrealloc2 +#endif void * -ruby_xrealloc2(void *ptr, size_t n, size_t size) +ruby_sized_xrealloc2(void *ptr, size_t n, size_t size, size_t old_n) { size_t len = size * n; if (n != 0 && size != len / n) { rb_raise(rb_eArgError, "realloc: possible integer overflow"); } - return ruby_xrealloc(ptr, len); + return objspace_xrealloc(&rb_objspace, ptr, len, old_n * size); +} + +void * +ruby_xrealloc2(void *ptr, size_t n, size_t size) +{ + return ruby_sized_xrealloc2(ptr, n, size, 0); } #ifdef ruby_sized_xfree Index: internal.h =================================================================== --- internal.h (revision 44116) +++ internal.h (revision 44117) @@ -461,10 +461,12 @@ void ruby_gc_set_params(int safe_level); https://github.com/ruby/ruby/blob/trunk/internal.h#L461 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32) #define ruby_sized_xrealloc(ptr, new_size, old_size) ruby_xrealloc(ptr, new_size) +#define ruby_sized_xrealloc2(ptr, new_count, element_size, old_count) ruby_xrealloc(ptr, new_count, element_size) #define ruby_sized_xfree(ptr, size) ruby_xfree(ptr) #define SIZED_REALLOC_N(var,type,n,old_n) REALLOC_N(var, type, n) #else void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_ALLOC_SIZE((2)); +void *ruby_sized_xrealloc(void *ptr, size_t new_count, size_t element_size, size_t old_count) RUBY_ATTR_ALLOC_SIZE((2, 3)); void ruby_sized_xfree(void *x, size_t size); #define SIZED_REALLOC_N(var,type,n,old_n) ((var)=(type*)ruby_sized_xrealloc((char*)(var), (n) * sizeof(type), (old_n) * sizeof(type))) #endif -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/