This has nothing to do with throwing or catching, only accessing the attributes of instances.
Attached is a small PIR example of the behavior I'm having trouble with
and its output.
The current API for accessing attributes of an Exception instance is
through keyed access with strings. Exception.pmc's get_pmc_keyed just
calls get_attr_str.
VTABLE PMC *get_pmc_keyed(PMC *key) {
STRING *s = VTABLE_get_string(INTERP, key);
return SELF.get_attr_str(s);
}
get_attr_str just uses the ATTR macros to fetch the value.
else if (Parrot_str_equal(INTERP, name, CONST_STRING(INTERP,
"resume"))) {
GET_ATTR_resume(interp, SELF, value);
}
The problem I'm seeing is that while that works fine for Exception
instances, it looks like the keyed access and access using
{get,set}attribute are going to different places in subclasses of
Exception.
If I store data with keyed access, getattribute gives back a Null PMC.
If I store data with setattribute (or VTABLE_set_attr_str, which throw
uses), keyed access gives back a Null PMC.
I *could* just change the throw op to use set_pmc_keyed_str instead, I
guess, but that seems suboptimal.
Anyone have any ideas?
For completeness, here is the definition of GET_ATTR_resume:
#define GETATTR_Exception_resume(interp, pmc, dest) \
do { \
if (PObj_is_object_TEST(pmc)) { \
(dest) = VTABLE_get_attr_str(interp, \
pmc, Parrot_str_new_constant(interp,
"resume")); \
} \
else \
(dest) = ((Parrot_Exception_attributes
*)PMC_data(pmc))->resume; \
} while (0)
.sub main :main
.local pmc cl, my
.local pmc ex, res
load_bytecode 'dumper.pbc'
cl = get_class 'Exception'
my = subclass cl, 'MyEx'
res = new 'String'
res = "lol"
ex = new cl
ex['resume'] = res
'insp'(ex, 'base set with keyed')
ex = new cl
setattribute ex, 'resume', res
'insp'(ex, 'base set with setattribute')
ex = new my
ex['resume'] = res
'insp'(ex, 'subclass set with keyed')
ex = new my
setattribute ex, 'resume', res
'insp'(ex, 'subclass set with setattribute')
.end
.sub 'insp'
.param pmc ex
.param string msg
.local pmc res
.local string type
type = typeof ex
print 'inspecting: "'
print msg
say '"'
print 'type: '
say type
res = ex['resume']
'_dumper'(res, 'keyed')
res = getattribute ex, 'resume'
'_dumper'(res, 'getattribute')
say "---------\n"
.end
inspecting: "base set with keyed" type: Exception "keyed" => "lol" "getattribute" => "lol" --------- inspecting: "base set with setattribute" type: Exception "keyed" => "lol" "getattribute" => "lol" --------- inspecting: "subclass set with keyed" type: MyEx "keyed" => "lol" "getattribute" => null --------- inspecting: "subclass set with setattribute" type: MyEx "keyed" => null "getattribute" => "lol" ---------
signature.asc
Description: This is a digitally signed message part
_______________________________________________ http://lists.parrot.org/mailman/listinfo/parrot-dev
