Permalink
Browse files

fix MMD wrapping for __is_equal

* check for NULL NCI function
* fix segv in backtrace of NCI methods
* install MMD wrapper for __is_equal



git-svn-id: https://svn.parrot.org/parrot/trunk@8253 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 5d7f0f0 commit b9b6c039ac2abd798622b27f1a728244b8c613bf Leopold Toetsch committed Jun 2, 2005
Showing with 75 additions and 48 deletions.
  1. +4 −0 classes/nci.pmc
  2. +63 −40 src/mmd.c
  3. +4 −7 src/objects.c
  4. +4 −1 src/sub.c
View
@@ -126,6 +126,10 @@ shifted down.
Parrot_csub_t func = (Parrot_csub_t)D2FPTR(PMC_data(SELF));
PMC *obj;
UINTVAL flags;
+
+ if (!func)
+ real_exception(INTERP, NULL, INVALID_OPERATION,
+ "attempt to call NULL function");
/*
* If the invocant is a class or there is no invocant
* shift down arguments.
View
@@ -91,6 +91,18 @@ dump_mmd(Interp *interpreter, INTVAL function)
}
#endif
+/*
+ * isa_str contains for real objects and for deleg_pmc objects
+ * both the string "delegate" - so compare a vtable slot
+ */
+
+extern void Parrot_deleg_pmc_mark(Interp*, PMC* pmc);
+
+static int
+isa_deleg_pmc(Interp *interpreter, PMC *p)
+{
+ return p->vtable->mark == Parrot_deleg_pmc_mark;
+}
funcptr_t
get_mmd_dispatch_type(Interp *interpreter, INTVAL func_nr, INTVAL left_type,
@@ -125,19 +137,17 @@ get_mmd_dispatch_type(Interp *interpreter, INTVAL func_nr, INTVAL left_type,
real_exception(interpreter, 0, 1, "MMD function %s not found"
"for types (%d, %d)", meth_c, left_type, r);
if (method->vtable->base_type == enum_class_NCI) {
- STRING *_isa;
PMC *nci;
/* C function is at struct_val */
func = D2FPTR(PMC_struct_val(method));
/*
* if one of the arguments isa deleg_pmc
* install the mmd_wrapper as real function
*/
- _isa = const_string(interpreter, "delegate");
- if (string_str_index(interpreter,
- Parrot_base_vtables[left_type]->isa_str, _isa, 0) >= 0
- || (r > 0 && string_str_index(interpreter,
- Parrot_base_vtables[r]->isa_str, _isa, 0) >= 0)) {
+ if (isa_deleg_pmc(interpreter,
+ Parrot_base_vtables[left_type]->class)
+ || (r > 0 && isa_deleg_pmc(interpreter,
+ Parrot_base_vtables[r]->class))) {
/* TODO check dest too */
nci = pmc_new(interpreter, enum_class_Bound_NCI);
dod_register_pmc(interpreter, nci); /* XXX */
@@ -237,29 +247,26 @@ Inplace dispatch functions for C<< left <op=> right >>.
static PMC*
mmd_wrap_p_ppp(Interp *interpreter, PMC *nci, PMC *right, PMC *dest) {
- STRING *_isa;
PMC *left = PMC_pmc_val(nci);
PMC *l, *r, *d, *n = NULL;
mmd_f_p_ppp real_function;
SLOTTYPE *attrib_array;
- _isa = const_string(interpreter, "delegate");
- if (string_str_index(interpreter, left->vtable->isa_str, _isa, 0) >= 0) {
+ if (isa_deleg_pmc(interpreter, left)) {
attrib_array = PMC_data(left);
l = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
n = left;
}
else
l = left;
- if (string_str_index(interpreter, right->vtable->isa_str, _isa, 0) >= 0) {
+ if (isa_deleg_pmc(interpreter, right)) {
attrib_array = PMC_data(right);
r = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
n = right;
}
else
r = right;
- if (dest && string_str_index(interpreter,
- dest->vtable->isa_str, _isa, 0) >= 0) {
+ if (dest && isa_deleg_pmc(interpreter, dest)) {
attrib_array = PMC_data(dest);
d = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
}
@@ -325,22 +332,19 @@ mmd_dispatch_p_ppp(Interp *interpreter,
static PMC*
mmd_wrap_p_pip(Interp *interpreter, PMC *nci, INTVAL right, PMC *dest) {
- STRING *_isa;
PMC *left = PMC_pmc_val(nci);
PMC *l, *d, *n = NULL;
mmd_f_p_pip real_function;
SLOTTYPE *attrib_array;
- _isa = const_string(interpreter, "delegate");
- if (string_str_index(interpreter, left->vtable->isa_str, _isa, 0) >= 0) {
+ if (isa_deleg_pmc(interpreter, left)) {
attrib_array = PMC_data(left);
l = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
n = left;
}
else
l = left;
- if (dest && string_str_index(interpreter,
- dest->vtable->isa_str, _isa, 0) >= 0) {
+ if (dest && isa_deleg_pmc(interpreter, dest)) {
attrib_array = PMC_data(dest);
d = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
}
@@ -402,22 +406,19 @@ mmd_dispatch_p_pip(Interp *interpreter,
static PMC*
mmd_wrap_p_pnp(Interp *interpreter, PMC *nci, FLOATVAL right, PMC *dest) {
- STRING *_isa;
PMC *left = PMC_pmc_val(nci);
PMC *l, *d, *n = NULL;
mmd_f_p_pnp real_function;
SLOTTYPE *attrib_array;
- _isa = const_string(interpreter, "delegate");
- if (string_str_index(interpreter, left->vtable->isa_str, _isa, 0) >= 0) {
+ if (isa_deleg_pmc(interpreter, left)) {
attrib_array = PMC_data(left);
l = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
n = left;
}
else
l = left;
- if (dest && string_str_index(interpreter,
- dest->vtable->isa_str, _isa, 0) >= 0) {
+ if (dest && isa_deleg_pmc(interpreter, dest)) {
attrib_array = PMC_data(dest);
d = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
}
@@ -479,22 +480,19 @@ mmd_dispatch_p_pnp(Interp *interpreter,
static PMC*
mmd_wrap_p_psp(Interp *interpreter, PMC *nci, STRING *right, PMC *dest) {
- STRING *_isa;
PMC *left = PMC_pmc_val(nci);
PMC *l, *d, *n = NULL;
mmd_f_p_psp real_function;
SLOTTYPE *attrib_array;
- _isa = const_string(interpreter, "delegate");
- if (string_str_index(interpreter, left->vtable->isa_str, _isa, 0) >= 0) {
+ if (isa_deleg_pmc(interpreter, left)) {
attrib_array = PMC_data(left);
l = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
n = left;
}
else
l = left;
- if (dest && string_str_index(interpreter,
- dest->vtable->isa_str, _isa, 0) >= 0) {
+ if (dest && isa_deleg_pmc(interpreter, dest)) {
attrib_array = PMC_data(dest);
d = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
}
@@ -555,20 +553,18 @@ mmd_dispatch_p_psp(Interp *interpreter,
static void
mmd_wrap_v_pp(Interp *interpreter, PMC *nci, PMC *right) {
- STRING *_isa;
PMC *left = PMC_pmc_val(nci);
PMC *l, *r;
mmd_f_v_pp real_function;
SLOTTYPE *attrib_array;
- _isa = const_string(interpreter, "delegate");
- if (string_str_index(interpreter, left->vtable->isa_str, _isa, 0) >= 0) {
+ if (isa_deleg_pmc(interpreter, left)) {
attrib_array = PMC_data(left);
l = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
}
else
l = left;
- if (string_str_index(interpreter, right->vtable->isa_str, _isa, 0) >= 0) {
+ if (isa_deleg_pmc(interpreter, right)) {
attrib_array = PMC_data(right);
r = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
}
@@ -615,14 +611,12 @@ mmd_dispatch_v_pp(Interp *interpreter,
static void
mmd_wrap_v_pi(Interp *interpreter, PMC *nci, INTVAL right) {
- STRING *_isa;
PMC *left = PMC_pmc_val(nci);
PMC *l;
mmd_f_v_pi real_function;
SLOTTYPE *attrib_array;
- _isa = const_string(interpreter, "delegate");
- if (string_str_index(interpreter, left->vtable->isa_str, _isa, 0) >= 0) {
+ if (isa_deleg_pmc(interpreter, left)) {
attrib_array = PMC_data(left);
l = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
}
@@ -668,14 +662,12 @@ mmd_dispatch_v_pi(Interp *interpreter,
static void
mmd_wrap_v_pn(Interp *interpreter, PMC *nci, FLOATVAL right) {
- STRING *_isa;
PMC *left = PMC_pmc_val(nci);
PMC *l;
mmd_f_v_pn real_function;
SLOTTYPE *attrib_array;
- _isa = const_string(interpreter, "delegate");
- if (string_str_index(interpreter, left->vtable->isa_str, _isa, 0) >= 0) {
+ if (isa_deleg_pmc(interpreter, left)) {
attrib_array = PMC_data(left);
l = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
}
@@ -721,14 +713,12 @@ mmd_dispatch_v_pn(Interp *interpreter,
static void
mmd_wrap_v_ps(Interp *interpreter, PMC *nci, STRING* right) {
- STRING *_isa;
PMC *left = PMC_pmc_val(nci);
PMC *l;
mmd_f_v_ps real_function;
SLOTTYPE *attrib_array;
- _isa = const_string(interpreter, "delegate");
- if (string_str_index(interpreter, left->vtable->isa_str, _isa, 0) >= 0) {
+ if (isa_deleg_pmc(interpreter, left)) {
attrib_array = PMC_data(left);
l = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
}
@@ -771,6 +761,28 @@ mmd_dispatch_v_ps(Interp *interpreter,
}
}
+static INTVAL
+mmd_wrap_i_pp(Interp *interpreter, PMC *nci, PMC *right) {
+ PMC *left = PMC_pmc_val(nci);
+ PMC *l, *r;
+ mmd_f_i_pp real_function;
+ SLOTTYPE *attrib_array;
+
+ if (isa_deleg_pmc(interpreter, left)) {
+ attrib_array = PMC_data(left);
+ l = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
+ }
+ else
+ l = left;
+ if (isa_deleg_pmc(interpreter, right)) {
+ attrib_array = PMC_data(right);
+ r = get_attrib_num(attrib_array, POD_FIRST_ATTRIB);
+ }
+ else
+ r = right;
+ real_function = (mmd_f_i_pp)D2FPTR(PMC_struct_val(nci));
+ return (real_function)(interpreter, l, r);
+}
/*
=item C<INTVAL
@@ -798,6 +810,17 @@ mmd_dispatch_i_pp(Interp *interpreter,
if (is_pmc) {
sub = (PMC*)real_function;
+ if (is_pmc == 2) {
+ /* mmd_register the wrapper */
+ mmd_register(interpreter, func_nr, left->vtable->base_type,
+ right->vtable->base_type,
+ D2FPTR((UINTVAL) sub | 3));
+ is_pmc = 3;
+ }
+ if (is_pmc == 3) {
+ PMC_pmc_val(sub) = left;
+ return mmd_wrap_i_pp(interpreter, sub, right);
+ }
ret = Parrot_runops_fromc_args_reti(interpreter, sub, "IPP",
left, right);
}
View
@@ -201,14 +201,10 @@ create_deleg_pmc_vtable(Interp *interpreter, PMC *class, STRING *class_name)
}
}
/*
- * TODO create a MMD name mapping and call mmd_register
- */
-
- /*
- * finally if the methods are changed dynamically
- * this vtable must be changed too
- * s. src/global.c:Parrot_store_global()
+ * a cruel hash to disceren a delegate from a deleg_pmc vtable
+ * see also src/mmd.c:isa_deleg_pmc
*/
+ class->vtable->mark = vtable->mark;
}
/*
@@ -503,6 +499,7 @@ parrot_class_register(Interp* interpreter, STRING *class_name,
new_vtable = Parrot_clone_vtable(interpreter, parent_vtable);
new_vtable->base_type = new_type;
new_vtable->mro = mro;
+ new_vtable->class = new_class;
set_attrib_num(new_class, (SLOTTYPE*)PMC_data(new_class), PCD_OBJECT_VTABLE,
vtable_pmc = constant_pmc_new(interpreter, enum_class_VtableCache));
PMC_struct_val(vtable_pmc) = new_vtable;
View
@@ -587,8 +587,11 @@ Parrot_Context_info(Interp *interpreter, struct Parrot_Context *ctx,
}
/* fetch struct Parrot_sub of the current sub in the given context */
- sub = PMC_sub(ctx->current_sub);
+ if (!VTABLE_isa(interpreter, ctx->current_sub,
+ const_string(interpreter, "Sub")))
+ return 1;
+ sub = PMC_sub(ctx->current_sub);
/* set the sub name */
info->subname = sub->name;

0 comments on commit b9b6c03

Please sign in to comment.