Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
clean up PMC (see TT #895)
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Aug 4, 2009
1 parent 705f084 commit f9c9ea7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/pmc/luaboolean.pmc
Expand Up @@ -46,8 +46,8 @@ Initializes the Boolean with a default value of C<false>.
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);
}

Expand All @@ -62,6 +62,7 @@ Destroy this PMC.
*/
VTABLE void destroy() {
mem_sys_free(PMC_data(SELF));
PMC_data(SELF) = NULL;
}

/*
Expand Down
22 changes: 12 additions & 10 deletions src/pmc/luafunction.pmc
Expand Up @@ -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);
}

Expand All @@ -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);
}

/*
Expand Down
3 changes: 2 additions & 1 deletion src/pmc/luanumber.pmc
Expand Up @@ -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);
}

/*
Expand All @@ -61,6 +61,7 @@ Destroy this PMC.
*/
VTABLE void destroy() {
mem_sys_free(PMC_data(SELF));
PMC_data(SELF) = NULL;
}

/*
Expand Down
4 changes: 3 additions & 1 deletion src/pmc/luastring.pmc
Expand Up @@ -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);
}

Expand All @@ -66,6 +67,7 @@ Destroys this String PMC.
*/
VTABLE void destroy() {
mem_sys_free(PMC_data(SELF));
PMC_data(SELF) = NULL;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/pmc/luatable.pmc
Expand Up @@ -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);
}

/*
Expand Down
7 changes: 2 additions & 5 deletions src/pmc/luathread.pmc
Expand Up @@ -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;
}

/*
Expand Down
7 changes: 2 additions & 5 deletions src/pmc/luauserdata.pmc
Expand Up @@ -110,18 +110,15 @@ 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");

if (meth)
(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;
}

/*
Expand Down

0 comments on commit f9c9ea7

Please sign in to comment.