From f9c9ea7318f8163eae45b61f37171837a7251244 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Tue, 4 Aug 2009 13:52:01 +0200 Subject: [PATCH] clean up PMC (see TT #895) --- src/pmc/luaboolean.pmc | 3 ++- src/pmc/luafunction.pmc | 22 ++++++++++++---------- src/pmc/luanumber.pmc | 3 ++- src/pmc/luastring.pmc | 4 +++- src/pmc/luatable.pmc | 2 +- src/pmc/luathread.pmc | 7 ++----- src/pmc/luauserdata.pmc | 7 ++----- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/pmc/luaboolean.pmc b/src/pmc/luaboolean.pmc index f224563..4e77c80 100644 --- a/src/pmc/luaboolean.pmc +++ b/src/pmc/luaboolean.pmc @@ -46,8 +46,8 @@ Initializes the Boolean with a default value of C. VTABLE void init() { Parrot_LuaBoolean_attributes* attrs = mem_allocate_typed(Parrot_LuaBoolean_attributes); - attrs->iv = 0; PMC_data(SELF) = attrs; + SET_ATTR_iv(INTERP, SELF, 0); PObj_active_destroy_SET(SELF); } @@ -62,6 +62,7 @@ Destroy this PMC. */ VTABLE void destroy() { mem_sys_free(PMC_data(SELF)); + PMC_data(SELF) = NULL; } /* diff --git a/src/pmc/luafunction.pmc b/src/pmc/luafunction.pmc index 2789915..33786f3 100644 --- a/src/pmc/luafunction.pmc +++ b/src/pmc/luafunction.pmc @@ -52,11 +52,12 @@ Initializes the function. VTABLE void init() { Parrot_LuaFunction_attributes *attrs = mem_allocate_typed(Parrot_LuaFunction_attributes); - - attrs->sub = mem_allocate_zeroed_typed(Parrot_sub); - attrs->sub->seg = INTERP->code; - attrs->env = NULL; + struct Parrot_sub * _sub = + mem_allocate_zeroed_typed(Parrot_sub); + _sub->seg = INTERP->code; PMC_data(SELF) = attrs; + f_sub(SELF) = _sub; + f_env(SELF) = NULL; PObj_custom_mark_destroy_SETALL(SELF); } @@ -71,17 +72,18 @@ Initializes the function. if (VTABLE_isa(INTERP, sub, Parrot_str_new_constant(INTERP, "Sub"))) { Parrot_LuaFunction_attributes *attrs = mem_allocate_zeroed_typed(Parrot_LuaFunction_attributes); - - attrs->sub = mem_allocate_zeroed_typed(Parrot_sub); - attrs->env = NULL; + struct Parrot_sub * _sub = + mem_allocate_typed(Parrot_sub); + /* copy the sub struct */ + memcpy(_sub, f_sub(sub), sizeof (Parrot_sub)); PMC_data(SELF) = attrs; + f_sub(SELF) = _sub; + f_env(SELF) = NULL; PObj_custom_mark_destroy_SETALL(SELF); - /* copy the sub struct */ - memcpy(attrs->sub, f_sub(sub), sizeof (Parrot_sub)); } else Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, - "not a Sub (%Ss)", SELF->vtable->whoami); + "not a Sub (%Ss)", sub->vtable->whoami); } /* diff --git a/src/pmc/luanumber.pmc b/src/pmc/luanumber.pmc index 42823f1..6e7372e 100644 --- a/src/pmc/luanumber.pmc +++ b/src/pmc/luanumber.pmc @@ -46,8 +46,8 @@ Initializes the number to zero. VTABLE void init() { Parrot_LuaNumber_attributes *fattr = mem_allocate_typed(Parrot_LuaNumber_attributes); - fattr->fv = 0.0; PMC_data(SELF) = fattr; + SET_ATTR_fv(INTERP, SELF, 0.0); } /* @@ -61,6 +61,7 @@ Destroy this PMC. */ VTABLE void destroy() { mem_sys_free(PMC_data(SELF)); + PMC_data(SELF) = NULL; } /* diff --git a/src/pmc/luastring.pmc b/src/pmc/luastring.pmc index 9cca95c..8d74019 100644 --- a/src/pmc/luastring.pmc +++ b/src/pmc/luastring.pmc @@ -50,8 +50,9 @@ Initializes the string. VTABLE void init() { Parrot_LuaString_attributes *attrs = mem_allocate_typed(Parrot_LuaString_attributes); - attrs->str_val = Parrot_str_new_noinit(INTERP, enum_stringrep_one, 0); + STRING *_str = Parrot_str_new_noinit(INTERP, enum_stringrep_one, 0); PMC_data(SELF) = attrs; + SET_ATTR_str_val(INTERP, SELF, _str); PObj_custom_mark_destroy_SETALL(SELF); } @@ -66,6 +67,7 @@ Destroys this String PMC. */ VTABLE void destroy() { mem_sys_free(PMC_data(SELF)); + PMC_data(SELF) = NULL; } /* diff --git a/src/pmc/luatable.pmc b/src/pmc/luatable.pmc index ef74f72..1532f90 100644 --- a/src/pmc/luatable.pmc +++ b/src/pmc/luatable.pmc @@ -388,8 +388,8 @@ Initializes the instance. VTABLE void init() { Parrot_LuaTable_attributes *t = mem_allocate_zeroed_typed(Parrot_LuaTable_attributes); PMC_data(SELF) = t; - PObj_custom_mark_destroy_SETALL(SELF); lua_new_table(INTERP, SELF); + PObj_custom_mark_destroy_SETALL(SELF); } /* diff --git a/src/pmc/luathread.pmc b/src/pmc/luathread.pmc index 920e6d4..94e7dd7 100644 --- a/src/pmc/luathread.pmc +++ b/src/pmc/luathread.pmc @@ -115,11 +115,8 @@ Call finalizer and free the thread. */ VTABLE void destroy() { - Parrot_LuaThread_attributes *u = PARROT_LUATHREAD(SELF); - if (u) { - mem_sys_free(u); - PMC_data(SELF) = NULL; - } + mem_sys_free(PMC_data(SELF)); + PMC_data(SELF) = NULL; } /* diff --git a/src/pmc/luauserdata.pmc b/src/pmc/luauserdata.pmc index 7140b68..c581833 100644 --- a/src/pmc/luauserdata.pmc +++ b/src/pmc/luauserdata.pmc @@ -110,7 +110,6 @@ Call finalizer and free the userdata. */ VTABLE void destroy() { - Parrot_LuaUserdata_attributes *u = PARROT_LUAUSERDATA(SELF); #if 0 PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__gc"); @@ -118,10 +117,8 @@ Call finalizer and free the userdata. (void)Parrot_runops_fromc_args(INTERP, meth, "vP", SELF); #endif - if (u) { - mem_sys_free(u); - PMC_data(SELF) = NULL; - } + mem_sys_free(PMC_data(SELF)); + PMC_data(SELF) = NULL; } /*