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

Commit

Permalink
Browse files Browse the repository at this point in the history
check type in VTABLE set_pmc,
throws an exception if not equal
  • Loading branch information
fperrad committed Sep 26, 2009
1 parent 8d6f9e7 commit c6c1703
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/pmc/luaboolean.pmc
Expand Up @@ -174,7 +174,7 @@ Sets the value of the boolean to the value in C<*value>.

*/
VTABLE void set_pmc(PMC *value) {
SELF.set_integer_native(VTABLE_get_bool(INTERP, value));
SET_ATTR_iv(INTERP, SELF, VTABLE_get_bool(INTERP, value));
}

/*
Expand Down
10 changes: 8 additions & 2 deletions src/pmc/luafunction.pmc
Expand Up @@ -134,8 +134,14 @@ Return the string "function".

*/
VTABLE void set_pmc(PMC *value) {
SUPER(value);
f_env(SELF) = f_env(value);
if (PMC_type(SELF) == PMC_type(value)) {
SUPER(value);
f_env(SELF) = f_env(value);
}
else
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_INVALID_OPERATION,
"Can't assign a non-LuaFunction type to a LuaFunction");
}

/*
Expand Down
8 changes: 7 additions & 1 deletion src/pmc/luatable.pmc
Expand Up @@ -476,7 +476,13 @@ therefore only clone the reference to themselves, not make a deep copy.

*/
VTABLE void set_pmc(PMC *other) {
memcpy(PMC_data(SELF), PMC_data(other), sizeof (Parrot_LuaTable_attributes));
if (PMC_type(SELF) == PMC_type(value))
memcpy(PMC_data(SELF), PMC_data(value),
sizeof (Parrot_LuaTable_attributes));
else
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_INVALID_OPERATION,
"Can't assign a non-LuaTable type to a LuaTable");
}

/*
Expand Down
9 changes: 7 additions & 2 deletions src/pmc/luathread.pmc
Expand Up @@ -151,8 +151,13 @@ Return the string "thread".

*/
VTABLE void set_pmc(PMC *value) {
t_val(SELF) = t_val(value);
t_env(SELF) = t_env(value);
if (PMC_type(SELF) == PMC_type(value))
memcpy(PMC_data(SELF), PMC_data(value),
sizeof (Parrot_LuaThread_attributes));
else
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_INVALID_OPERATION,
"Can't assign a non-LuaThread type to a LuaThread");
}

/*
Expand Down
11 changes: 7 additions & 4 deletions src/pmc/luauserdata.pmc
Expand Up @@ -160,10 +160,13 @@ Return the string "userdata".

*/
VTABLE void set_pmc(PMC *value) {
/* TODO: should be get_attr_str() and getfenv() */
u_val(SELF) = u_val(value);
u_env(SELF) = u_env(value);
u_mt(SELF) = u_mt(value);
if (PMC_type(SELF) == PMC_type(value))
memcpy(PMC_data(SELF), PMC_data(value),
sizeof (Parrot_LuaUserdata_attributes));
else
Parrot_ex_throw_from_c_args(INTERP, NULL,
EXCEPTION_INVALID_OPERATION,
"Can't assign a non-LuaUserdata type to a LuaUserdata");
}

/*
Expand Down

0 comments on commit c6c1703

Please sign in to comment.