[svn:parrot] r46092 - in trunk: src src/pmc t/oo

allison at svn.parrot.org allison at svn.parrot.org
Wed Apr 28 02:10:08 UTC 2010


Author: allison
Date: Wed Apr 28 02:10:07 2010
New Revision: 46092
URL: https://trac.parrot.org/parrot/changeset/46092

Log:
[oo] Fix method lookup on low-level PMCs so they find methods in the
method cache and in the class/proxy object. See TT #1596.

Modified:
   trunk/src/oo.c
   trunk/src/pmc/namespace.pmc
   trunk/t/oo/methods.t

Modified: trunk/src/oo.c
==============================================================================
--- trunk/src/oo.c	Wed Apr 28 01:40:30 2010	(r46091)
+++ trunk/src/oo.c	Wed Apr 28 02:10:07 2010	(r46092)
@@ -1041,13 +1041,30 @@
 
     PMC * const  mro = _class->vtable->mro;
     const INTVAL n   = VTABLE_elements(interp, mro);
+    STRING * const methods_str = CONST_STRING(interp, "methods");
+    STRING * const class_str = CONST_STRING(interp, "class");
 
     for (i = 0; i < n; ++i) {
-        PMC *method, *ns;
+        PMC *ns, *class_obj, *_class, *method_hash;
+        PMC *method = PMCNULL;
 
         _class = VTABLE_get_pmc_keyed_int(interp, mro, i);
         ns     = VTABLE_get_namespace(interp, _class);
-        method = VTABLE_get_pmc_keyed_str(interp, ns, method_name);
+
+	class_obj = VTABLE_inspect_str(interp, ns, class_str);
+	if (PMC_IS_NULL(class_obj))
+	    method_hash = VTABLE_inspect_str(interp, ns,
+		    methods_str);
+	else
+	    method_hash = VTABLE_inspect_str(interp, class_obj,
+		    methods_str);
+
+	if (!PMC_IS_NULL(method_hash))
+            method = VTABLE_get_pmc_keyed_str(interp, method_hash,
+			method_name);
+
+	if (PMC_IS_NULL(method))
+            method = VTABLE_get_pmc_keyed_str(interp, ns, method_name);
 
         TRACE_FM(interp, _class, method_name, method);
 

Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc	Wed Apr 28 01:40:30 2010	(r46091)
+++ trunk/src/pmc/namespace.pmc	Wed Apr 28 02:10:07 2010	(r46092)
@@ -299,8 +299,9 @@
 */
 
     VTABLE void init() {
-        PARROT_NAMESPACE(SELF)->vtable = PMCNULL;
-        PARROT_NAMESPACE(SELF)->_class = PMCNULL;
+        PARROT_NAMESPACE(SELF)->vtable  = PMCNULL;
+        PARROT_NAMESPACE(SELF)->methods = PMCNULL;
+        PARROT_NAMESPACE(SELF)->_class  = PMCNULL;
         SELF.set_pointer(parrot_new_hash(INTERP));
         PObj_custom_mark_destroy_SETALL(SELF);
     }
@@ -651,6 +652,61 @@
 
 /*
 
+=item C<PMC *inspect_str(STRING *what)>
+
+Provides introspection of a specific piece of information about the
+namespace. The available information is:
+
+=over 8
+
+=item class
+
+The class object associated with the namespace, if any.
+
+=item methods
+
+A temporary cache of methods (destroyed when class object is created).
+Hash keyed on method name, value is an invokable PMC. Includes methods
+composed in from roles.
+
+=item vtable_overrides
+
+A temporary cache of vtable overrides (destroyed when class object is
+created). Hash keyed on vtable name, value is an invokable PMC.
+Includes vtable overrides composed in from roles.
+
+=back
+
+=cut
+
+*/
+
+    VTABLE PMC *inspect_str(STRING *what) {
+        const Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(SELF);
+        PMC *found;
+
+        if (Parrot_str_equal(interp, what, CONST_STRING(interp, "methods"))) {
+            found = nsinfo->methods;
+        }
+        else if (Parrot_str_equal(interp, what, CONST_STRING(interp, "vtable_overrides"))) {
+            found = nsinfo->vtable;
+        }
+        else if (Parrot_str_equal(interp, what, CONST_STRING(interp, "class"))) {
+            found = nsinfo->_class;
+        }
+        else
+            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+                "Unknown introspection value '%S'", what);
+
+        /* return found value */
+        if (PMC_IS_NULL(found))
+            return PMCNULL;
+
+	return found;
+    }
+
+/*
+
 =back
 
 =head2 Methods

Modified: trunk/t/oo/methods.t
==============================================================================
--- trunk/t/oo/methods.t	Wed Apr 28 01:40:30 2010	(r46091)
+++ trunk/t/oo/methods.t	Wed Apr 28 02:10:07 2010	(r46092)
@@ -132,15 +132,9 @@
     .local string msg
     msg = "able to invoke overridden method on core PMC (TT #1596)"
     $P0 = new 'ResizablePMCArray'
-    push_eh jic
-        $I0 = $P0.'foo'()
-        is($I0, 1, msg)
-        .return()
-  jic:
-    pop_eh
-    # remove the exception handler and the todo when this test passes
-    # so that future regressions are noisy.
-    todo('','cannot find method', msg)
+    $I0 = $P0.'foo'()
+    is($I0, 1, msg)
+    .return()
 .end
 
 .namespace ['ResizablePMCArray']


More information about the parrot-commits mailing list