[ruby/bigdecimal] Keep obj-to-Real link when VpReallocReal returns different pointer

https://github.com/ruby/bigdecimal/commit/252748de17
This commit is contained in:
Kenta Murata 2021-11-24 00:20:42 +09:00
parent 75f552e973
commit 38e98cbdb7
No known key found for this signature in database
GPG Key ID: CEFE8AFB6081B062

View File

@ -869,7 +869,18 @@ VpCreateRbObject(size_t mx, const char *str, bool raise_exception)
}
#define VpAllocReal(prec) (Real *)VpMemAlloc(offsetof(Real, frac) + (prec) * sizeof(DECDIG))
#define VpReallocReal(ptr, prec) (Real *)VpMemRealloc((ptr), offsetof(Real, frac) + (prec) * sizeof(DECDIG))
static Real *
VpReallocReal(Real *pv, size_t prec)
{
VALUE obj = pv ? pv->obj : 0;
Real *new_pv = (Real *)VpMemRealloc(pv, offsetof(Real, frac) + prec * sizeof(DECDIG));
if (obj) {
new_pv->obj = 0;
BigDecimal_wrap_struct(obj, new_pv);
}
return new_pv;
}
static Real *
VpCopy(Real *pv, Real const* const x)