# New Ticket Created by "Alek Storm" # Please include the string: [perl #42547] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42547 >
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. 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. -- Alek Storm
Index: src/pmc/object.pmc =================================================================== --- src/pmc/object.pmc (revision 18231) +++ src/pmc/object.pmc (working copy) @@ -31,6 +31,21 @@ /* +=item C<void init()> + +Allocates an empty, anonymous class to initialize the object. + +=cut + +*/ + + void init() { + PMC *class = pmc_new(interp, enum_class_Class); + VTABLE_init_pmc(interp, SELF, class); + } + +/* + =item C<void init_pmc(PMC *class)> Instantiates an object of the given class.
Index: src/pmc/object.pmc =================================================================== --- src/pmc/object.pmc (revision 18231) +++ src/pmc/object.pmc (working copy) @@ -31,6 +31,21 @@ /* +=item C<void init()> + +Raises an exception to make sure that objects are initialized with a class. + +=cut + +*/ + + void init() { + real_exception(interp, NULL, E_NotImplementedError, + "Cannot create Object without a class"); + } + +/* + =item C<void init_pmc(PMC *class)> Instantiates an object of the given class.