Skip to content

Commit

Permalink
Keep obj-to-Real link when VpReallocReal returns different pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkn committed Nov 23, 2021
1 parent 8dc8cd3 commit 252748d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ext/bigdecimal/bigdecimal.c
Expand Up @@ -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)
Expand Down

0 comments on commit 252748d

Please sign in to comment.