diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-09 12:20:51 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-09 12:20:51 +0000 |
| commit | b7a20fdf6100ff6e857b81ec9e076c6102893cc3 (patch) | |
| tree | f21133ac0906db5405c2f5c7dfb626fbaa4a5401 /ext/bigdecimal | |
| parent | 823099be741697872beb2cb0eadee21127b84656 (diff) | |
| download | ruby-b7a20fdf6100ff6e857b81ec9e076c6102893cc3.tar.gz ruby-b7a20fdf6100ff6e857b81ec9e076c6102893cc3.tar.xz ruby-b7a20fdf6100ff6e857b81ec9e076c6102893cc3.zip | |
* ext/bigdecimal/bigdecimal.c (BigDecimal_data_type): typed.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
| -rw-r--r-- | ext/bigdecimal/bigdecimal.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index c917e8409..de18b8378 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -203,11 +203,23 @@ static int VpLimitRound(Real *c,U_LONG ixDigit); */ static void -BigDecimal_delete(Real *pv) +BigDecimal_delete(void *pv) { VpFree(pv); } +static size_t +BigDecimal_memsize(const void *ptr) +{ + const Real *pv = ptr; + return pv ? (sizeof(*pv) + pv->MaxPrec * sizeof(U_LONG)) : 0; +} + +static const rb_data_type_t BigDecimal_data_type = { + "BigDecimal", + 0, BigDecimal_delete, BigDecimal_memsize, +}; + static VALUE ToValue(Real *p) { @@ -231,8 +243,8 @@ GetVpValue(VALUE v, int must) switch(TYPE(v)) { case T_DATA: - if(RDATA(v)->dfree ==(void *) BigDecimal_delete) { - Data_Get_Struct(v, Real, pv); + if(rb_typeddata_is_kind_of(v, &BigDecimal_data_type)) { + pv = DATA_PTR(v); return pv; } else { goto SomeOneMayDoIt; @@ -503,7 +515,7 @@ VP_EXPORT Real * VpNewRbClass(U_LONG mx, char *str, VALUE klass) { Real *pv = VpAlloc(mx,str); - pv->obj = (VALUE)Data_Wrap_Struct(klass, 0, BigDecimal_delete, pv); + pv->obj = TypedData_Wrap_Struct(klass, &BigDecimal_data_type, pv); return pv; } @@ -511,7 +523,7 @@ VP_EXPORT Real * VpCreateRbObject(U_LONG mx, const char *str) { Real *pv = VpAlloc(mx,str); - pv->obj = (VALUE)Data_Wrap_Struct(rb_cBigDecimal, 0, BigDecimal_delete, pv); + pv->obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, pv); return pv; } |
