From 38e98cbdb7c429d0042fd24efd9fec6516fb45f5 Mon Sep 17 00:00:00 2001 From: Kenta Murata Date: Wed, 24 Nov 2021 00:20:42 +0900 Subject: [ruby/bigdecimal] Keep obj-to-Real link when VpReallocReal returns different pointer https://github.com/ruby/bigdecimal/commit/252748de17 --- ext/bigdecimal/bigdecimal.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 1cbdbd8832..668d9d1d4d 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -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) -- cgit v1.2.3