Update dtoa to version from Ruby 4.0#528
Conversation
| } | ||
| memcpy(buf, p, len10); | ||
| xfree(p); | ||
| free(p); |
There was a problem hiding this comment.
Shouldn't we fix dtoa to use xmalloc instead?
There was a problem hiding this comment.
I'm not sure there's value in doing so. These allocations are short-lived and running the GC doesn't help us remove them (they aren't associated with a Ruby heap object) so I'm not sure it helps for them to contribute to GC pressure.
This was changed upstream in ruby/ruby@bc8cc68
There was a problem hiding this comment.
Sorry, I should have explained my train of thoughts. I agree there's no GC benefits, especially since when you use xfree (instead of the new xfree_sized) this likely cause a malloc_usable_size call which make the whole thing slower.
However, I recently ran into a bunch of bugs related to using xfree with malloc and vice-versa, so I tend to think it's simpler to just always use the Ruby allocator.
But really up to you.
Anyway, as you said bgidecimal should probably move away from vendoring dtoa.
There was a problem hiding this comment.
I'd like to use malloc and free instead of xmalloc and xfree in bigdecimal's dtoa.
dtoa and strtod may call MALLOC several times, and if the second call fails to allocate, dtoa frees the first allocated one.
b1 = Balloc(b->k+1);
if (!b1) {
Bfree(b);
return NULL;
}bd = Balloc(bd0->k);
if (!bd) goto retfree;If we use ruby_xmalloc, and the second allocation raises NoMemoryError, this mechanism will fail, and will cause memory leak.
So I think current dtoa.c in ruby/ruby can be considered designed to be use with malloc and free
move away from vendoring
dtoa.
Agree
Fixes #527
Upstream commits: