# New Ticket Created by  Jerry Gay 
# Please include the string:  [perl #42693]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42693 >


while creating a subclass of Exporter to test inter-language exports,
i stumbled across a bug that i can't seem to fix.

i've created a subclass of Exporter called MyExporter. MyExporter has
an overridden 'add_global' method, which adds a '&' sigil to each
global specified by the user and calls the method in the superclass.

i've also created a high-level language that uses the '&' sigil on
subs, and i import and aim to call the hll sub. however, the code
never finishes 'add_method', as it segfaults inside the supermethod
with an undefined 'exp' object. that is, from src/pmc/exporter.pmc,
line 260:

        Parrot_Exporter *exp = PARROT_EXPORTER(SELF);

after this line, 'exp' is NULL, but 'SELF' (or after macro expansion
'pmc') is not. this is not the case when 'add_method' has not been
overridden. here's the pir code that exposes the bug:

.sub 'main' :main
    .local pmc exp, ns

    exp = new 'MyExporter'

    ns = get_root_namespace ['foo']
    exp.'source'( ns )

    exp.'add_global'('bar')

say "NEVER REACHES HERE"

    exp.'import'()

    '&bar'() ## THIS WILL SUCCEED!
     'bar'() ## THIS WILL FAIL!
             ## THAT'S NOT WHAT I WANT!!!
.end


## create a subclass of Exporter that overrides 'add_global'
## it adds a '&' sigil to each requested global
.namespace ['MyExporter']
.sub 'onload' :load :init :anon
    .local pmc class
    class = subclass 'Exporter', 'MyExporter'
    .return ()
.end


.sub 'add_global' :method
    .param string glb      :optional
    .param int    has_glb  :opt_flag

    .local pmc args, super
    args = new .Hash
    super = new .Super, self

    unless has_glb goto no_global
    glb = concat '&', glb
    .return super.'add_global'( glb )
  no_global:
    .return super.'add_global'()
.end


# create a high-level language that uses '&' sigil for sub names
.HLL 'foo', ''
.sub '&bar'
    say 'hello, world!'
.end


note that switching from a tail method call to a regular method call
has no effect.

also note that my code also exposes a problem with the current
Exporter implementation: the imported sub name does not match the
requested name. i have yet to address this as the current bug is
blocking progress.

~jerry

Reply via email to