develooper Front page | perl.perl5.porters | Postings from December 2017

Re: [perl #132638] I've discovered a segfault

Thread Previous
Slaven Rezic
December 23, 2017 14:35
Re: [perl #132638] I've discovered a segfault
Message ID:
"James E Keenan via RT" <> writes:

> On Sat, 23 Dec 2017 07:56:23 GMT, wrote:
>> Danijel Tasov wrote:
>> >use overload
>> >'eq' => \&equals_to,
>> ...
>> >sub equals_to{ $_[0] eq $_[1] }
>> Here's your problem you've defined the "eq" overload to apply "eq" to
>> its operands, which invokes the "eq" overload in an infinite recursion.
>> The segv is just C stack overflow.  You probably want to write the "eq"
>> overload as
>>     sub equals_to{ "$_[0]" eq $_[1] }
>> or just remove that overload and enable overload fallback, so that Perl
>> will synthesise that "eq" overload for you.
>> There is no Perl bug here.
>> -zefram
> There may not be a bug in perl here -- but there's certainly a
> deficiency in our documentation.
> I've been writing Perl for a long time but have never had occasion to
> 'use overload'. I stared at the original poster's code and couldn't
> see anything obviously wrong. I then went and read the documentation.
> Again, I couldn't find anything that would lead me to guess that the
> OP's code would segfault.
> So we have to improve the documentation. Otherwise, people will
> repeatedly stumble into this problem. How should we change the docs?

With "use warnings" the script emits

    Useless use of string eq in void context at ...
    Deep recursion on subroutine "Clock::equals_to" at ...

At least the "deep recursion" warning should be a note to the
experienced programmer that something's going wrong here, and out of
memory errors and stack overflows are to be expected.

But maybe a sentence in perldiag.pod could be added.


Slaven Rezic - slaven <at> rezic <dot> de

    Berlin Perl Mongers -

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About