Re: who stole my returned list?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Quoted text here. Click to load it

I narrowed one step more, calling the original DESTROY:

use strict;
use ClearCase::Argv;

sub fun {
  my $thing = ClearCase::Argv->new;
  return qw(1 2 3);
print "Fun ", join(' ', fun), "\n";
exit 0 unless fun;
print "End\n";

But, this doesn't make it fail.
Now, what could I *add* to this if I wanted to reproduce the previous


Re: who stole my returned list?

I am sorry that my question didn't inspire anybody...
I continue my debugging:

  DB<14> $mod = $sync->_lsco

  DB<15> p $mod

  DB<16> x $sync->_lsco
0  '/view/emagiro_t7/vobs/atcctest/foo/d'

Er... funny, isn't it?
I go to the return statement of the _lsco function, set 'trace' on,
and do a 'r'.
I get a transcript of running the DESTROY members for two objects (and
I did fix something related since yesterday), and get now (end only):

855:        $? |= $ret;
list context return from ClearCase::SyncTree::_lsco:
0  '/view/emagiro_t7/vobs/atcctest/foo/d'
1218:        my %checkedout = map {$_ => 1} $self->_lsco;

So, now the function would return something, but the address returned
to is completely weird! That's not where I started from!
As it seems, a different place in the code, where the same function is

I have corrupted my stack, as it seems...

I'll run the same under an other perl...


Re: who stole my returned list?

I am back to my problem...

Quoted text here. Click to load it

I tried with perl 5.10.0 (until now, it was 5.8.8), and got a similar
behaviour, albeit as it seems, with destructors called later (?!).
In my case, this makes the trace simpler:

214:       return sort keys %co;
  DB<4> x %co
0  '/view/emagiro_86/vobs/atcctest/foo/d'
1  1
  DB<5> t
Trace = on
  DB<5> r
scalar context return from ClearCase::SyncTree::_lsco: undef
main::(blib/script/synctree:321):   exit $rc unless $mod;
  DB<5> x $mod
main::((eval 43)[/vobs/cello/cade_A_tools_perl/lib/5.10.0/
2:   $mod;
0  undef

This is the return from the _lsco member function, which gets assigned
to $mod.
I would expect a defined value of 1.
Am I wrong?


Re: who stole my returned list?

Quoted text here. Click to load it

Yes, but why?
I reproduced it:

$ cat foo
#!/usr/bin/perl -w

sub foo {
  my %co = (a=3D>1, b=3D>2);
  return sort keys %co;

my $mod = foo || foo || foo || foo;
print "$mod\n";
$ perl -d ./foo

Loading DB routines from version 1.3
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(./foo:8):        my $mod = foo || foo || foo || foo;
  DB<1> c 5
main::foo(./foo:5):       return sort keys %co;
  DB<2> r
scalar context return from main::foo: undef
main::foo(./foo:4):    my %co = (a=3D>1, b=3D>2);
  DB<2> q

This works without 'sort'...


Re: who stole my returned list?

Quoted text here. Click to load it

or like this:

sub foo {
  my %co = (a=3D>1, b=3D>2);
  my @ret = sort keys %co;
  return @ret;


Re: who stole my returned list?

I was pointed the documentation (which I had failed to read well
enough--embarrassing as this is the first paragraph):

   In list context, this sorts the LIST and returns the sorted list
   value. In scalar context, the behaviour of "sort()" is undefined.

OK. Now I know that 'undefined' may mean 'stack corruption'.
Cave canem... er, caveat emptor, I meant.

The fix is thus:

   return wantarray? sort keys %co : scalar keys %co;


Site Timeline