SPUG: Strange code effect

Joseph Werner telcodev at gmail.com
Wed Dec 23 14:21:12 PST 2009

Hey Ben,

Thanks for the feedback!

First, let me bring you up to current status. I attempted to
construct, by building up to, the problem. This attempt failed to
reproduce the central first issue: why was I unable to shift the
object off of the array? However, it did answer the second question:
The object failed to respond in a boolean context because one
overloaded operator had been declared, but neither bool nor stringify
had been declared. STRANGER still,  fixing the second problem [bool
overload] made the first [shift from array]  problem disappear. I
STILL cannot connect the two. Anyhow, problem solved, but the central
question remains unanswered.

No, we are not using Apache. Wish we were. I tread a tightrope of my
nondisclosure commitments, but I can say: we use thin servers, what I
have com to call 'campstove' servers [all the expectations of Apache
in 2,000 lines of code or less] and due to the environment in which
the server runs, either the crashes produce output to a log file, or
we never see it.

See additional comments below.

On Wed, Dec 23, 2009 at 12:36 PM, BenRifkah Bergsten-Buret
<mail.spammagnet at gmail.com> wrote:
> See comments below.
> On Tue, Dec 22, 2009 at 8:49 PM, Joseph Werner <telcodev at gmail.com> wrote:
>> Hey guys [and gals],
>> I encountered a strange Perl code phenomenon dealing with some object
>> references, and and array of object references. Specifically, I could
>> not shift a reference to an object off of an array of object
>> references. More troubling, I also was unable to use the object
>> references in a boolean context. I have written code very similar to
>> this dozens if not hundreds of times and never encountered this type
>> of problem...
>> The code is all proprietary,  and the powers that be frown on release
>> of any sort, so I will pseudo code what I am talking about. We are
>> running Active State Perl 5.10 on a Win32 platform, if that matters
>> my $some_parms = shift;
>> my $objhref = get_objects($some_parms);
>> # $objhref = {
>> #           '01' => bless( {}, 'ASpecialObject' ),
>> #           '03' => bless( {}, 'ASpecialObject' ),
>> #           '02' => bless( {}, 'ASpecialObject' )
>> #         };
> Have you tried assigning anything from $objhref directly at this point?  For
> example, do you get an error if you try to do $myobj = $objhref->{01}?

Yes, the hash ref is fully loaded and performs these type of operations.

>> # ASpecialObject class does have the <=> overloaded
>> # But I cannot see the making a difference...
>> # Sorting works fine:
>> my @arrayoforefs;
>> eval {
>>   @arrayoforefs = sort { $a <=> $b } values %{$objhref};
>> }
>> # Error checks ignored
> Since you've wrapped this in an eval it seems like you're expecting
> exceptions to be thrown.  Why ignore them?  See if there is an exception
> that might lead you in the right direction.

My BAD. Ignoring exceptions was only pseudocode. In production, we do
trap the exceptions. But it is a sunny day scenario [from the point of
view of the evaled statement] that is producing the problem, so I
omitted any checking to keep the waters clear.

> Also, are you able to access anything within @arrayoforefs without using an
> assignment?  For example what happens when you do warn "arrayofrefs[0]:
> @arrayofrefs[0]"?  Do the server crash?

Not certian if what @arrayofrefs[0] is what you mean? A slice of one
element? I will try and get back to you.

>> # Server dies silently at the following statement:
>> my $chosenO = shift @arrayoforefs;
>> # If I do this instead:
>> my $chosenO = $arrayoforefs[0];
>> # Then this causes the server to silently crash:
>> return unless $chosenO;
> You've said "server dies silently" and "silently crash" but I'm not clear
> what you mean.  Is this two different things or the same?  By "crash" do you
> mean that the server process exits with a core dump?  Is this an Apache
> server?  Mod_perl?  When perl "dies" it generates a message.  Also, in my
> experience when Apache dumps core it puts a message in the log but you've
> said "silently" so perhaps something else is going on.

Yes, silently. No core. Frustrating, nothing prints to the log at all,
just the server is no longer running.

> My suggestion is to code up the simplest case you can where the problem is
> encountered.  Strip out as much code as possible that doesn't directly
> relate to what you're doing.  For example, the following script can be run
> outside of your web server and outside of your Mason environment:

Unfortunately my attempts to reproduce the array shift issue outside
of the server have failed.

Hey Thanks again for the feedback

> #!/usr/bin/perl
> use strict;
> use warnings;
> use lib "/my/code/path";
> use ASpecialObject;
> my $objects = {
>  01 => ASpecialObject->new(),
>  02 => ASpecialObject->new(),
> };
> my @sorted = sort {$a <=> $b} values %{$objects};
> #Does this result in the same problems you're having?
> my $chosen0 = shift @sorted;
> print "If you see this then the script is done\n";
> __END__
> You'll probably have to include some object initialization code but if you
> still have problems with this then you know the problem is somewhere in
> ASpecialObject.pm.  Then you can start stripping out the code from there to
> find the minimum amount of code that causes the problem.
> --
> Ben

More information about the spug-list mailing list