1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/bigdecimal/bigdecimal.c (BigDecimal_data_type): typed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-09-09 12:20:51 +00:00
parent c754c0b237
commit 7bac09fc26
2 changed files with 20 additions and 6 deletions

View file

@ -1,4 +1,6 @@
Wed Sep 9 21:19:27 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Wed Sep 9 21:20:49 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/bigdecimal/bigdecimal.c (BigDecimal_data_type): typed.
* ext/dl/cfunc.c (dlcfunc_data_type): typed. * ext/dl/cfunc.c (dlcfunc_data_type): typed.

View file

@ -203,11 +203,23 @@ static int VpLimitRound(Real *c,U_LONG ixDigit);
*/ */
static void static void
BigDecimal_delete(Real *pv) BigDecimal_delete(void *pv)
{ {
VpFree(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 static VALUE
ToValue(Real *p) ToValue(Real *p)
{ {
@ -231,8 +243,8 @@ GetVpValue(VALUE v, int must)
switch(TYPE(v)) switch(TYPE(v))
{ {
case T_DATA: case T_DATA:
if(RDATA(v)->dfree ==(void *) BigDecimal_delete) { if(rb_typeddata_is_kind_of(v, &BigDecimal_data_type)) {
Data_Get_Struct(v, Real, pv); pv = DATA_PTR(v);
return pv; return pv;
} else { } else {
goto SomeOneMayDoIt; goto SomeOneMayDoIt;
@ -503,7 +515,7 @@ VP_EXPORT Real *
VpNewRbClass(U_LONG mx, char *str, VALUE klass) VpNewRbClass(U_LONG mx, char *str, VALUE klass)
{ {
Real *pv = VpAlloc(mx,str); 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; return pv;
} }
@ -511,7 +523,7 @@ VP_EXPORT Real *
VpCreateRbObject(U_LONG mx, const char *str) VpCreateRbObject(U_LONG mx, const char *str)
{ {
Real *pv = VpAlloc(mx,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; return pv;
} }