Alek Storm (via RT) wrote:
The following code causes a segfault:
.sub main :main
$P0 = new "Object"
$P0.'foo'()
.end
This is because the vtable methods in Object assume a valid pointer to
the object's internal representation, which is only initialized in
init_pmc.
That probably has to change too, otherwise people can do:
obj = new Object, class
Which is bad, because class.new() never gets called in the process and
(provided it hasn't been instantiated before) you don't end up with a
valid class (nor one with the instantiated flag set), so it'll only
cause breakage further down the line.
I've attached two patches solving the problem by implementing init(), the first
of which creates an empty, anonymous Class for the Object; the second throws an
exception when init() is called. I prefer the former, because it follows the
programmer's instinct of what should happen: a completely empty Object is
created.
The second was what I had in mind; the patch to do the first of these
isn't going to work out too well (for the reasons I stated with init_pmc).
What should happen: Class manufactures an object and init and init_pmc
of Object both throw exceptions. That means creating a new Object PMC in
the new method of Class using pmc_new_noinit (IIRC) and setting up its
guts from within Class.
As part of this, the structs, typedefs and macros for Parrot_Object and
Parrot_Class need to go in a header file pulled in by Class and Object
PMCs (but *only* by those two - it's fine for Class and Object to know
about each others guts, but everything else should use the external
interface, so it can work with other, HLL specific classes and object).
Thanks,
Jonathan