Ticket #1286 (new bug)

Opened 5 years ago

Last modified 4 years ago

method overload in pir subclass of pmc pccmethod leaves object undefined

Reported by: particle Owned by:
Priority: normal Milestone:
Component: library Version: trunk
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description

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

Change History

Changed 5 years ago by coke

Followup comments:

coke says:

> The PIR code in this ticket now causes a Bus error on osx/386 (r25175)

Also segfaults in linux/386 for me.

I added an assertion that catch the fault in r30859

-- 
Salu2

Changed 5 years ago by coke

Changed 4 years ago by jkeenan

Is there any test we could add to t/pmc/exporter.t that we could mark as TODO that would enable us to track the issues in this ticket.

Other Exporter-related tickets: TT #1233; TT #1205.

Thank you very much.

kid51

Changed 4 years ago by jkeenan

  • component changed from none to library
Note: See TracTickets for help on using tickets.