Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #41614] Can't set non-core object attribs yet

0 views
Skip to first unread message

Will Coleda

unread,
Feb 25, 2007, 1:42:00 AM2/25/07
to bugs-bi...@rt.perl.org
# New Ticket Created by Will Coleda
# Please include the string: [perl #41614]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41614 >


In Tcl, I've tried to add an attribute to a TclProc PMC (a thin
wrapper around .Sub) in my sandbox.

First, I have to override several methods in TclProc (copying them from

=item C<PMC* get_attr(INTVAL idx)>
=item C<PMC* get_attr_str(STRING *name)>
=item C<void set_attr(INTVAL idx, PMC *val)>
=item C<void set_attr_str(STRING *name, PMC *val)>

to avoid errors like:

set_attr_str() not implemented in class 'TclProc'

Once these are implemented, code like:

setattribute $P1, 'source', $P9

generates the exception:

Can't set non-core object attribs

If I try to add the attribute before setting, it's worse:

$P8 = getclass "TclProc"
addattribute $P8, 'source'

src/objects.c:1452: failed assertion `(class)->pmc_ext'

--
Will "Coke" Coleda
wi...@coleda.com


Alek Storm

unread,
Feb 25, 2007, 9:07:31 PM2/25/07
to perl6-i...@perl.org
The problem is that a Sub is not a ParrotObject, so it has nowhere to
store attributes. That's why attr_str_2_num throws "Can't set
non-core object attribs": it can't safely use PMC_data unless you've
passed a ParrotObject. I've attached a patch that implements a basic
attribute storage system for TclProc (just a hash). They're not
really attributes, though; they act like properties in ParrotObjects,
since TclProc has no corresponding class in which to store them
permanently (get_class returns the PMC itself). This should be all
that's necessary; a TclProc would probably only require a few
attributes, and you can set their default values in the init() vtable
method. Another solution is to have TclProc be an actual ParrotObject
wrapper around Sub, and redirect all vtable methods to the sub.
tclproc.patch

Will Coleda

unread,
Feb 26, 2007, 8:23:06 PM2/26/07
to Alek Storm, perl6-i...@perl.org
It is rather annoying that attributes don't JFW everywhere, yes. I do
wish, in general, that ParrotClass and PMC had more in common.

I'm not sure how I'm to access these via PIR: I get the same

src/objects.c:1452: failed assertion `(class)->pmc_ext'

error after applying this patch.

I'm going to go down the path of trying to implement TclProc as a
ParrotClass in PIR.

Thanks for the reply.

0 new messages