Discussion:
[perl #57764] docs/art/ppp02-pmc.pod -- example 9 segfault
(too old to reply)
Pavlo Korzhyk
2008-08-10 09:18:27 UTC
Permalink
# New Ticket Created by "Pavlo Korzhyk"
# Please include the string: [perl #57764]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=57764 >


To reproduce simply copy-paste example 9 from docs/art/ppp02-pmc.pod
and run it:

======================================================
.include "timer.pasm" # for the timer constants

.sub expired
print "Timer has expired!\n"
.end

.sub _ :main
$P0 = new 'Timer'
$P1 = global "expired"

$P0[.PARROT_TIMER_HANDLER] = $P1 # call sub in $P1 when timer goes off
$P0[.PARROT_TIMER_SEC] = 2 # trigger every 2 seconds
$P0[.PARROT_TIMER_REPEAT] = -1 # repeat indefinitely
$P0[.PARROT_TIMER_RUNNING] = 1 # start timer immediately
global "timer" = $P0 # keep the timer around

$I0 = 0
loop:
print $I0
print ": running...\n"
inc $I0
sleep 1 # wait a second
goto loop
.end
======================================================

The output under Ubuntu is:
(0.6.4 on Ubuntu and WinXP, 0.6.3 on Ubuntu produce the similar bad result)
======================================================
0: running...
1: running...
maximum recursion depth exceeded
current instr.: 'expired' pc 0 (timertest.pir:4)
called from Sub 'expired' pc 0 (timertest.pir:4)
called from Sub 'expired' pc 0 (timertest.pir:4)
... repeated approx 2000 times ...
called from Sub 'expired' pc 0 (timertest.pir:4)
called from Sub 'expired' pc 0 (timertest.pir:4)
called from Sub '_' pc 41 (timertest.pir:22)
Segmentation fault
======================================================

If "-1"(indefinitely) is replaced with "5" - you'll get 6 messages
"Timer has expired!"
all at once:
======================================================
0: running...
1: running...
Timer has expired!
Timer has expired!
Timer has expired!
Timer has expired!
Timer has expired!
Timer has expired!
2: running...
3: running...
4: running...
5: running...
(pressed Ctrl+C here)
======================================================

For N repeats you will get N+1 executions of the handler.
Chromatic
2009-02-12 21:29:16 UTC
Permalink
Here's a shorter example that still generates a bus error for me on
darwin/x86
Oh look, it's an order of destruction problem.
#0 0x00000001 in ?? ()
#1 0x0107f318 in Parrot_exit (interp=0x600cb0, status=1) at
src/exit.c:91
#2 0x0107e462 in die_from_exception (interp=0x600cb0,
exception=0x2fa9f0) at src/exceptions.c:159
#3 0x0107e521 in Parrot_ex_throw_from_c (interp=0x600cb0,
exception=0x2fa9f0) at src/exceptions.c:308
#4 0x0107ec7f in Parrot_ex_throw_from_c_args (interp=0x600cb0,
ret_addr_unused=0x0, exitcode=62, format=0x1314724 "maximum recursion
depth exceeded") at src/exceptions.c:409
#5 0x0119f660 in Parrot_Sub_invoke (interp=0x600cb0, pmc=0x2c19c0,
next=0x0) at ./src/pmc/sub.pmc:268
...
#11 0x0109a292 in Parrot_really_destroy (interp=0x600cb0,
exit_code_unused=1, arg_unused=0x0) at src/inter_create.c:324
-- c

Loading...