Perl linked list segfault

2009-11-04 Thread Andy Wardley

I've got some code that's making Perl segfault.

I'm creating a linked list using array references as nodes.  The first element
in the array ref contains some data, the second item contains a reference to
the next item.  Think cons lists.

while (++$n  $max) {
$token = [token $n];
$last-[1] = $token if $last;
$last = $token;
}

Using the above code I can create a linked list of 100 million nodes and
everything works just fine (assuming you don't mind twiddling your thumbs
for a few minutes).

However, if I also stuff the nodes into a container list then Perl segfaults
at cleanup time, either when the tokens go out of scope or during global
cleanup.

while (++$n  $max) {
$token = [token $n];
$last-[1] = $token if $last;
$last = $token;
push(@tokens, $token);# add this line - BOOM!
}

In this case Perl will reliably segfault with a mere 30,000 nodes.

If I just push them onto @tokens and don't create the linked list then it
also works fine.  It's the combination of linked list + container list that
farks things up.

I've tested this on my Macbook using versions 5.8, 5.10.0, 5.10.1 and 5.11.1,
and 5.10 on Linux.   They all fail somewhere between the 25k and 40k mark.

Now that I'm convinced it's a real bug, I'm at a bit of a loss as to how to
debug it.  The -D flags that I've tried (most of them, in various different 
combinations) don't offer much in the way of help and I've got no core dump

to analyse (can anyone explain why this doesn't dump core?).  The only thing
that I'm sure of is that the SEGV is happening during memory cleanup.

I'll perlbug it when I get a moment, but I was hoping to be able to
investigate it further myself.

Any suggestions gratefully received.

A







Re: [ANNOUNCE] London.pm November social 2009-11-05, The Victoria, Bayswater W2 2NH

2009-11-04 Thread Léon Brocard
2009/10/17 Dagfinn Ilmari Mannsåker ilm...@ilmari.org:

Please remember that the November London Perl Mongers social meeting
is this week, and in fact tomorrow:

 As James mentioned in his last e-mail, I am your new pub tsar, and as my
 first deed I have booked the Theatre Bar (aka. upstairs) at The
 Victoria¹ in Bayswater for the November social. Not only that, but my
 employer, PhotoBox (who are hiring²), has been kind enough to put £250
 behind the bar. Also, the pub is installing an extra hand pump for us,
 so we can get both London Pride and ESB without having to go downstairs
 (where they have Chiswick Bitter and Discovery as well).

 See you all there!

 [1] http://london.randomness.org.uk/wiki.cgi?Victoria,_W2_2NH
 [2] http://london.pm.org/pipermail/jobs/2009-October/000218.html

It will also be Guy Fawkes Night, but please do not attempt to blow up
the Houses of Parliament.

See you there! Léon



Re: Perl linked list segfault

2009-11-04 Thread Andy Wardley

On 04/11/2009 07:55, Andy Wardley wrote:

I've got some code that's making Perl segfault.


Here's the complete script in case anyone wants to play along at
home:

   http://wardley.org/perl/linked_list_segfault.pl

A


Re: Perl linked list segfault

2009-11-04 Thread Dirk Koopman

Andy Wardley wrote:

On 04/11/2009 07:55, Andy Wardley wrote:

I've got some code that's making Perl segfault.


Here's the complete script in case anyone wants to play along at
home:

   http://wardley.org/perl/linked_list_segfault.pl


shifting out all the @tokens works; undefing or emptying @tokens segfaults.

Is this an ordering thing?


Re: Perl linked list segfault

2009-11-04 Thread Matthew Boyle

Dirk Koopman wrote:

Andy Wardley wrote:

On 04/11/2009 07:55, Andy Wardley wrote:

I've got some code that's making Perl segfault.


Here's the complete script in case anyone wants to play along at
home:

   http://wardley.org/perl/linked_list_segfault.pl


shifting out all the @tokens works; undefing or emptying @tokens segfaults.

Is this an ordering thing?


mine seems to be running out of stack space:

[chemn...@10:36 ~]$ gdb perl
GNU gdb Fedora (6.8-32.fc10)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
http://gnu.org/licenses/gpl.html

This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type show copying
and show warranty for details.
This GDB was configured as i386-redhat-linux-gnu...
(no debugging symbols found)
Missing separate debuginfos, use: debuginfo-install perl-5.10.0-73.fc10.i386
(gdb) run downloads/linked_list_segfault.pl
Starting program: /usr/bin/perl downloads/linked_list_segfault.pl

[snip]

starting
creating linked list of 4 tokens
created 4 tokens
creating linked list of 4 tokens in container
created 4 tokens
[New Thread 0xb7fe26c0 (LWP 9178)]

Program received signal SIGSEGV, Segmentation fault.
0x026e6105 in Perl_sv_free2 () from 
/usr/lib/perl5/5.10.0/i386-linux-thread-multi/CORE/libperl.so

(gdb) bt -1
#229310 0x08048a2e in main ()
(gdb)

quarter of a million frames is quite a lot :-)

--matt


--
Matthew Boyle, Systems Administrator, CoreFiling Limited
Telephone: +44-1865-203192  Website: http://www.corefiling.com


Re: Perl linked list segfault

2009-11-04 Thread Paul LeoNerd Evans
On Wed, 04 Nov 2009 07:55:26 +
Andy Wardley a...@wardley.org wrote:

 They all fail somewhere between the 25k and 40k mark.

That's highly suspect.

Can you try approaching 32k (i.e. 32,768), and see what limits either
side of that will work or fail? Perhaps a 15-bit (or 16-bit signed)
counter is getting overflowed somewhere?

-- 
Paul LeoNerd Evans

leon...@leonerd.org.uk
ICQ# 4135350   |  Registered Linux# 179460
http://www.leonerd.org.uk/


signature.asc
Description: PGP signature


Re: Perl linked list segfault

2009-11-04 Thread Dagfinn Ilmari Mannsåker
Dirk Koopman d...@tobit.co.uk writes:

 Andy Wardley wrote:
 On 04/11/2009 07:55, Andy Wardley wrote:
 I've got some code that's making Perl segfault.

 Here's the complete script in case anyone wants to play along at
 home:

http://wardley.org/perl/linked_list_segfault.pl

 shifting out all the @tokens works; undefing or emptying @tokens segfaults.

 Is this an ordering thing?

It seems to be recursing when freeing @tokens, I'm see the following stacktrace:

[fuckloads of reapeating calls snipped]
#192663 0x00492bcc in Perl_sv_clear (my_perl=0x78a010, sv=0x7b5a80) at 
sv.c:5236
#192664 0x004931a1 in Perl_sv_free2 (my_perl=0x78a010, sv=0x7b5a80) at 
sv.c:5368
#192665 0x004719e8 in Perl_av_undef (my_perl=0x78a010, av=0x78ee88) at 
av.c:485
#192666 0x00492c38 in Perl_sv_clear (my_perl=0x78a010, sv=0x78ee88) at 
sv.c:5193
#192667 0x004931a1 in Perl_sv_free2 (my_perl=0x78a010, sv=0x78ee88) at 
sv.c:5368
#192668 0x00492bcc in Perl_sv_clear (my_perl=0x78a010, sv=0x78ecd8) at 
sv.c:5236
#192669 0x004931a1 in Perl_sv_free2 (my_perl=0x78a010, sv=0x78ecd8) at 
sv.c:5368
#192670 0x004700e8 in Perl_av_clear (my_perl=0x78a010, av=0x7d65b8) at 
av.c:453
#192671 0x004b5ca6 in Perl_leave_scope (my_perl=0x78a010, base=5) at 
scope.c:799
#192672 0x0047e199 in Perl_pp_leavesub (my_perl=0x78a010) at 
pp_hot.c:2475
#192673 0x00454ce4 in Perl_runops_debug (my_perl=0x78a010) at 
dump.c:1931
#192674 0x00478aa4 in S_run_body (my_perl=value optimised out) at 
perl.c:2391
#192675 perl_run (my_perl=value optimised out) at perl.c:2309
#192676 0x0042177c in main (argc=2, argv=0x7fffe198, 
env=0x7fffe1b0) at perlmain.c:113

I think it's time to take this to p5p.

-- 
ilmari
A disappointingly low fraction of the human race is,
 at any given time, on fire. - Stig Sandbeck Mathisen


Re: Perl linked list segfault

2009-11-04 Thread Andy Wardley

On 04/11/2009 10:46, Paul LeoNerd Evans wrote:

That's highly suspect.


That was my first thought.  But no, it's not specifically 32,768.
It depends on the platform/perl version.  In once case, ~25k was
enough, and in other it was a shade over 39k.

A



Re: Perl linked list segfault

2009-11-04 Thread Andy Wardley

On 04/11/2009 10:45, Matthew Boyle wrote:

mine seems to be running out of stack space:

[chemn...@10:36 ~]$ gdb perl

[...]

(gdb) run downloads/linked_list_segfault.pl
Starting program: /usr/bin/perl downloads/linked_list_segfault.pl


Ah!  That's the magic incantation I needed.  I was trying these:

  $ gdb linked_list_segfault.pl
  $ gdb perl linked_list_segfault.pl

And of course, gdb complained that linked_list_segfault.pl wasn't a
core file.


quarter of a million frames is quite a lot :-)


Indeed.  I'll try not to be so greedy in future :-)

 looks like it is a stack issue:

 [chemn...@10:52 ~]$ ulimit -s
 10240

That's another useful tip to remember.  Thank you.

A


Re: Perl linked list segfault

2009-11-04 Thread Andy Wardley

On 04/11/2009 10:46, Dagfinn Ilmari Mannsåker wrote:

It seems to be recursing when freeing @tokens, I'm see the following stacktrace:


Aha, that would explain it.


I think it's time to take this to p5p.


I will.  Thanks everyone.

A



Re: Perl linked list segfault

2009-11-04 Thread Gianni Ceccarelli
On 2009-11-04 Andy Wardley a...@wardley.org wrote:
 Ah!  That's the magic incantation I needed.  I was trying these:
 
$ gdb linked_list_segfault.pl
$ gdb perl linked_list_segfault.pl

The other way is:

  gdb --args perl linked_list_segfault.pl

-- 
Dakkar - Mobilis in mobile
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88

To converse at the distance of the Indes by means of sympathetic
contrivances may be as natural to future times as to us is a literary
correspondence. -- Joseph Glanvill, 1661


signature.asc
Description: PGP signature


Effective adveristing

2009-11-04 Thread Dermot
I just noticed this in my goolgemail.

Learn Perl in London - mag-sol.com/train/public - Beginner,
Intermediate, Advanced Taught by Dave Cross

I guessing he paid for this. Considering how many Perl(ish) emails I
have inbox, I'm surprised with this form of context-sensitive
adverting that it's not permanently fixed at the top of my page.
Dp.


Re: Effective adveristing

2009-11-04 Thread Ovid
- Original Message 

 From: Dermot paik...@googlemail.com
 
 I just noticed this in my goolgemail.
 
 Learn Perl in London - mag-sol.com/train/public - Beginner,
 Intermediate, Advanced Taught by Dave Cross
 
 I guessing he paid for this. Considering how many Perl(ish) emails I
 have inbox, I'm surprised with this form of context-sensitive
 adverting that it's not permanently fixed at the top of my page.


Assuming Dave did pay for this, I'm quite curious to know how effective it is.  
Hopefully it gets more trained Perl programmers out there.  I'm tired of 
hearing the old we can't find Perl programmers lament.
 
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog- http://use.perl.org/~Ovid/journal/
Twitter  - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6




Re: Effective adveristing

2009-11-04 Thread Matt Follett
I wonder if it would be prudent for him to filter out advertising for people
who have the word 'mongers' in the same email as 'perl'.

~Matt

On Wed, Nov 4, 2009 at 4:11 PM, Ovid publiustemp-londo...@yahoo.com wrote:

 - Original Message 

  From: Dermot paik...@googlemail.com
 
  I just noticed this in my goolgemail.
 
  Learn Perl in London - mag-sol.com/train/public - Beginner,
  Intermediate, Advanced Taught by Dave Cross
 
  I guessing he paid for this. Considering how many Perl(ish) emails I
  have inbox, I'm surprised with this form of context-sensitive
  adverting that it's not permanently fixed at the top of my page.


 Assuming Dave did pay for this, I'm quite curious to know how effective it
 is.  Hopefully it gets more trained Perl programmers out there.  I'm tired
 of hearing the old we can't find Perl programmers lament.

 Cheers,
 Ovid
 --
 Buy the book - http://www.oreilly.com/catalog/perlhks/
 Tech blog- 
 http://use.perl.org/~Ovid/journal/http://use.perl.org/%7EOvid/journal/
 Twitter  - http://twitter.com/OvidPerl
 Official Perl 6 Wiki - http://www.perlfoundation.org/perl6





Re: Effective adveristing

2009-11-04 Thread Dermot
2009/11/4 Ovid publiustemp-londo...@yahoo.com:

 Assuming Dave did pay for this, I'm quite curious to know how effective it is.

I think there is also a cost for each click it gets so when he gets
his bill, he can tell us how many clicks it got.

Dp.


Re: Effective adveristing

2009-11-04 Thread Paul Makepeace
On Wed, Nov 4, 2009 at 2:27 PM, Matt Follett matt.foll...@gmail.com wrote:

 I wonder if it would be prudent for him to filter out advertising for
 people
 who have the word 'mongers' in the same email as 'perl'.


Not really because advertisers aren't charged unless the person clicks on
their ad (i.e. no impression cost). I'm sure there are plenty of mongers
that would appreciate becoming better perl programmers through Dave's
training.

Paul