ruby-changes:70486
From: Kenta <ko1@a...>
Date: Fri, 24 Dec 2021 02:30:26 +0900 (JST)
Subject: [ruby-changes:70486] 38e98cbdb7 (master): [ruby/bigdecimal] Keep obj-to-Real link when VpReallocReal returns different pointer
https://git.ruby-lang.org/ruby.git/commit/?id=38e98cbdb7 From 38e98cbdb7c429d0042fd24efd9fec6516fb45f5 Mon Sep 17 00:00:00 2001 From: Kenta Murata <mrkn@m...> 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(-) diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 1cbdbd88326..668d9d1d4d3 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) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L869 } #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.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/