summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2021-11-24 00:20:42 +0900
committerKenta Murata <mrkn@mrkn.jp>2021-12-24 02:28:56 +0900
commit38e98cbdb7c429d0042fd24efd9fec6516fb45f5 (patch)
treee5e0b0f6521c8c3fb6ca387fbdb84dc90fea71fd /ext
parent75f552e973ba565ef8615a0c5fd375d3a052b82e (diff)
[ruby/bigdecimal] Keep obj-to-Real link when VpReallocReal returns different pointer
https://github.com/ruby/bigdecimal/commit/252748de17
Diffstat (limited to 'ext')
-rw-r--r--ext/bigdecimal/bigdecimal.c13
1 files changed, 12 insertions, 1 deletions
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)