Allison Randal wrote:
Christoph Otto via RT wrote:
I'm running into a snag trying to implement this. It turns out that
many lines which use the PMC_x_val macros use them on different types of
PMCs, especially parents and children (e.g. FixedPMCArray and
ResizablePMCArray). There are also some instances where the PMCs with a
related purpose but no inheritance (e.g. RetContinuation and
ExceptionHandler) have the unionval used in the same way on a line of
code.
What's the right way to fix these cases to use the GETATTR/SETATTR
macros?
Tough to answer without looking at the code, but... The
GET_ATTR/SET_ATTR macros will work on inherited attributes as well as
child attributes. (Actually, at the moment you're required to declare
all parent attributes in the ATTR list before the child attributes, so
inherited attributes *are* child attributes.)
If two unrelated PMCs are being called in the same line of code, that
probably means it should really be a vtable function call instead of
direct access into the data struct.
Allison
When I say "attributes", I mean the things that are declared in .pmc files
right after the pmclass line, e.g.
ATTR INTVAL foo_refs; /*foo refcount*/
These do not appear to be passed down to extending PMCs. This is a problem
for e.g UnManagedStruct/ManagedStruct, where PMC_int_val is used the same way
by both PMCs.
For example, say that I add ATTR INTVAL struct_size; to UnManagedStruct. It's
possible to replace some instances of PMC_int_val with VTABLE_get_integer in
these two PMCs, but I can't use GETATTR_UnManagedStruct_struct_size in
UnManagedStruct's get_integer VTABLE function because ManagedStruct uses
UnManagedStruct's get_integer, but doesn't have its ATTRs.
It would be possible to add the same ATTR to ManagedStruct and make sure that
it had its own get_integer VTABLE function. Unfortunately this would mean
more code duplication and would negate some of the benefits of allowing PMCs
to extend each other.
What I'd like is for the pmc2c code to be smart enough to make ATTRs from an
extended PMC accessible by an extending PMC through the GET_ATTR/SET_ATTR
macros. If I could get a description of how such a patch should behave from
our architect, I'd be glad to write one up and submit it for review.