Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anomaly in caller() returned values #860

Closed
p5pRT opened this issue Nov 17, 1999 · 3 comments
Closed

Anomaly in caller() returned values #860

p5pRT opened this issue Nov 17, 1999 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 17, 1999

Migrated from rt.perl.org#1790 (status was 'resolved')

Searchable as RT1790$

@p5pRT
Copy link
Author

p5pRT commented Nov 17, 1999

From Raphael.Manfredi@st.com


There is an anomaly in the way caller() returns its arguments.
Watch​:

  1 sub a {
  2 b();
  3 }
  4
  5 sub b {
  6 my ($pack, $file, $line, $sub) = caller(1);
  7 print "b() called from $sub/$line\n";
  8 }
  9
  10 a();

which produces​:

  b() called from main​::a/10

If caller(0) is used instead in line 6, I get​:

  b() called from main​::b/2

The anomaly is that $sub refers to the calling routine, but
not the line number. To get it, one must re-use caller()
with an (offset-1) with respect to the targetted call frame.

Raphael



Site configuration information for perl 5.00503​:

Configured by manfredi at Mon Aug 9 12​:37​:05 MET DST 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:
  Platform​:
  osname=solaris, osvers=2.5.1, archname=sun4-solaris
  uname='sunos lod23 5.5.1 generic_103640-27 sun4u sparc sunw,ultra-60 '
  hint=previous, useposix=true, d_sigaction=define
  usethreads=undef useperlio=define d_sfio=undef
  Compiler​:
  cc='/apa/SUNWspro/bin/cc', optimize='-O', gccversion=
  cppflags='-I/home/manfredi/usr/BerkeleyDB/include'
  ccflags ='-I/home/manfredi/usr/BerkeleyDB/include'
  stdchar='unsigned char', d_stdstdio=define, usevfork=true
  intsize=4, longsize=4, ptrsize=4, doublesize=8
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries​:
  ld='/apa/SUNWspro/bin/cc', ldflags ='-L/home/manfredi/usr/BerkeleyDB/lib'
  libpth=/lib /usr/lib /usr/ccs/lib /home/manfredi/usr/BerkeleyDB/lib
  libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
  libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
  cccdlflags='-KPIC', lddlflags='-G -L/home/manfredi/usr/BerkeleyDB/lib'

Locally applied patches​:
 


@​INC for perl 5.00503​:
  /home/manfredi/usr/lib/perl
  /home/manfredi/usr/lib/perl5/5.00503/sun4-solaris
  /home/manfredi/usr/lib/perl5/5.00503
  /home/manfredi/usr/lib/perl5/site_perl/5.005/sun4-solaris
  /home/manfredi/usr/lib/perl5/site_perl/5.005
  .


Environment for perl 5.00503​:
  HOME=/home/manfredi
  LANG=fr
  LANGUAGE (unset)
  LC_MESSAGES=C
  LC_MONETARY=C
  LC_NUMERIC=C
  LC_TIME=C
  LD_LIBRARY_PATH=/home/manfredi/usr/lib/X11​:/usr/openwin/lib
  LOGDIR (unset)
  PATH=/home/manfredi/bin/scripts​:/home/manfredi/bin/sun​:/home/manfredi/bin/sun/mh​:/home/manfredi/bin/scripts/mh​:/home/manfredi/bin/sun/fm2html​:/home/manfredi/bin/scripts/rdb​:/apa/gnu/SunOS5/bin​:/bin​:/usr/bin​:/sbin​:/usr/sbin​:/apa/SUNWspro/bin​:/usr/ccs/bin​:/usr/ucb​:/usr/contrib/bin​:/apa/comp/SunOS5/bin​:/apa/acroread/3.02/bin​:/apa/ddts/bin​:/apa/util/bin​:/etc​:/usr/bin/X11​:/usr/games​:/home/bruel/local/SunOS5/bin​:/home/manfredi​:.​:/home/manfredi/bin/acri
  PERL_BADLANG (unset)
  SHELL=/home/manfredi/bin/sun/ksh

@p5pRT
Copy link
Author

p5pRT commented Nov 17, 1999

From @gsar

On Wed, 17 Nov 1999 16​:31​:55 +0100, Raphael Manfredi wrote​:

There is an anomaly in the way caller() returns its arguments.
Watch​:

1  sub a \{
2      b\(\);
3  \}
4  
5  sub b \{
6      my \($pack\, $file\,  $line\, $sub\) = caller\(1\);
7      print "b\(\) called from $sub/$line\\n";
8  \}
9  

10 a();

which produces​:

b() called from main​::a/10

If caller(0) is used instead in line 6, I get​:

b() called from main​::b/2

The anomaly is that $sub refers to the calling routine, but
not the line number. To get it, one must re-use caller()
with an (offset-1) with respect to the targetted call frame.

FWIW, I don't think there's a bug here. What's probably
misleading is the way the message is written. caller() simply
reports the attributes of the executing context "frame", and
they look correct in the above. Try a message more like​:

  print "executing $sub() at $line\n";

and you'll see what I mean.

Sarathy
gsar@​ActiveState.com

@p5pRT
Copy link
Author

p5pRT commented Nov 18, 1999

From [Unknown Contact. See original ticket]

Quoting gsar@​activestate.com​:
:>The anomaly is that $sub refers to the calling routine, but
:>not the line number. To get it, one must re-use caller()
:>with an (offset-1) with respect to the targetted call frame.
:
:FWIW, I don't think there's a bug here. What's probably
:misleading is the way the message is written. caller() simply
:reports the attributes of the executing context "frame", and
:they look correct in the above. Try a message more like​:

I did not say it was a bug, I said it was an "anomaly". ;-)

Seriously, I was astonished by the behaviour, but you're right.
I had the "wording" wrong in my head, hence the interpretation
was also wrong.

Perhaps the example you gave me should go in the documentation?
Somehow, I thought caller(0) would give MY OWN stack frame, since
$subroutine is set to my name, but no, it's giving the name of
the subroutine called, which is mine!

Hence my confusion.

Raphael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant