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

Sys::Hostname causes bogus "ambiguous system..." warning #686

Closed
p5pRT opened this issue Oct 5, 1999 · 6 comments
Closed

Sys::Hostname causes bogus "ambiguous system..." warning #686

p5pRT opened this issue Oct 5, 1999 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 5, 1999

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

Searchable as RT1582$

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From @jimav

The program​:

  use Sys​::Hostname ();
  BEGIN { $hn = Sys​::Hostname​::hostname(); }
  BEGIN { $^W=1; } # or perl -w
  system("/bin/date");

generates a warning "Ambiguous call resolved as CORE​::system()..."

In the real application the code is not as strange as the above example​:
&hostname is called in the main body of a module which is use'd by another.

This is a new problem with 5.005_03. _02 does not have it.

-Jim Avera (jima@​hal.com)



Site configuration information for perl 5.00503​:

Configured by avera at Tue Oct 5 15​:28​:43 PDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:
  Platform​:
  osname=solaris, osvers=2.6, archname=sun4-solaris
  uname='sunos membrane 5.6 generic_105181-11 sun4u sparc sunw,ultra-5_10 '
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef useperlio=undef d_sfio=undef
  Compiler​:
  cc='/sim/caetools_ssd1/VCS/cctools/sun4-solaris/cc', optimize='-O', gccversion=2.8.1
  cppflags=''
  ccflags =''
  stdchar='unsigned char', d_stdstdio=define, usevfork=false
  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='/sim/caetools_ssd1/VCS/cctools/sun4-solaris/cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib /usr/ccs/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='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches​:
 


@​INC for perl 5.00503​:
  /sim/vcsperl/perl/5.005_03/lib/5.00503/sun4-solaris
  /sim/vcsperl/perl/5.005_03/lib/5.00503
  /sim/vcsperl/perl/5.005_03/lib/site_perl/5.005/sun4-solaris
  /sim/vcsperl/perl/5.005_03/lib/site_perl/5.005
  .


Environment for perl 5.00503​:
  HOME=/u/avera
  LANG=en_US
  LANGUAGE (unset)
  LC_COLLATE=en_US
  LC_CTYPE=en_US
  LC_MESSAGES=C
  LC_MONETARY=en_US
  LC_NUMERIC=en_US
  LC_TIME=en_US
  LD_LIBRARY_PATH=/usr/is/lib​:/usr/lib​:/usr/openwin/lib​:/usr/ucblib
  LOGDIR (unset)
  PATH=/sim/vcsperl/perl/new/bin​:/u/avera/bin​:/u/avera/bin/misc​:/usr/is/bin​:/usr/ccs/bin​:/usr/is/gnu/bin​:/usr/bin​:/usr/sbin​:/sbin​:/opt/SUNWspro-5.1/bin​:/usr/ucb​:.​:/sim/avera/cvshome/bin​:/u/avera/bin/hal​:/sim/tools/current/bin​:/usr/dt/bin​:/usr/openwin/bin/.​:/usr/openwin/bin​:/sim/lb/current/bin​:/tools/all/qa/current/bin​:/tools/all/bin​:/u/avera/bin/ssdhosts​:/u/avera/bin/ws​:/distrib/SunOS__5.6__sun4m/frame-5.5.6/bin
  PERL_BADLANG (unset)
  SHELL=/usr/is/gnu/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From @gsar

On Tue, 05 Oct 1999 16​:08​:46 PDT, Jim Avera wrote​:

The program​:

use Sys​::Hostname ();
BEGIN { $hn = Sys​::Hostname​::hostname(); }
BEGIN { $^W=1; } # or perl -w
system("/bin/date");

generates a warning "Ambiguous call resolved as CORE​::system()..."

In the real application the code is not as strange as the above example​:
&hostname is called in the main body of a module which is use'd by another.

This is a new problem with 5.005_03. _02 does not have it.

Can't reproduce this on my copy of Solaris (see config below). Sounds
like you have a local syscall.ph with C<sub system { ... }> or similar
in it.

Sarathy
gsar@​activestate.com

---
Site configuration information for perl 5.00503​:

Configured by avera at Tue Oct 5 15​:28​:43 PDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:
Platform​:
osname=solaris, osvers=2.6, archname=sun4-solaris
uname='sunos membrane 5.6 generic_105181-11 sun4u sparc sunw,ultra-5_10 '
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef useperlio=undef d_sfio=undef
Compiler​:
cc='/sim/caetools_ssd1/VCS/cctools/sun4-solaris/cc', optimize='-O', gccversion=2.8.1
cppflags=''
ccflags =''
stdchar='unsigned char', d_stdstdio=define, usevfork=false
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='/sim/caetools_ssd1/VCS/cctools/sun4-solaris/cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib /usr/ccs/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='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches​:

---
@​INC for perl 5.00503​:
/sim/vcsperl/perl/5.005_03/lib/5.00503/sun4-solaris
/sim/vcsperl/perl/5.005_03/lib/5.00503
/sim/vcsperl/perl/5.005_03/lib/site_perl/5.005/sun4-solaris
/sim/vcsperl/perl/5.005_03/lib/site_perl/5.005
.

---
Environment for perl 5.00503​:
HOME=/u/avera
LANG=en_US
LANGUAGE (unset)
LC_COLLATE=en_US
LC_CTYPE=en_US
LC_MESSAGES=C
LC_MONETARY=en_US
LC_NUMERIC=en_US
LC_TIME=en_US
LD_LIBRARY_PATH=/usr/is/lib​:/usr/lib​:/usr/openwin/lib​:/usr/ucblib
LOGDIR (unset)
PATH=/sim/vcsperl/perl/new/bin​:/u/avera/bin​:/u/avera/bin/misc​:/usr/is/bin​:/usr/ccs/b
in​:/usr/is/gnu/bin​:/usr/bin​:/usr/sbin​:/sbin​:/opt/SUNWspro-5.1/bin​:/usr/ucb​:.​:/sim/avera/
cvshome/bin​:/u/avera/bin/hal​:/sim/tools/current/bin​:/usr/dt/bin​:/usr/openwin/bin/.​:/usr/
openwin/bin​:/sim/lb/current/bin​:/tools/all/qa/current/bin​:/tools/all/bin​:/u/avera/bin/ss
dhosts​:/u/avera/bin/ws​:/distrib/SunOS__5.6__sun4m/frame-5.5.6/bin
  PERL_BADLANG (unset)
SHELL=/usr/is/gnu/bin/bash

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:
  Platform​:
  osname=solaris, osvers=2.6, archname=sun4-solaris
  uname='sunos sparc26.activestate.com 5.6 generic sun4m sparc sunw,sparcstation-5 '
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef useperlio=undef d_sfio=undef
  Compiler​:
  cc='cc', optimize='-O', gccversion=2.7.2.3
  cppflags='-I/usr/local/include'
  ccflags ='-I/usr/local/include'
  stdchar='unsigned char', d_stdstdio=define, usevfork=false
  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='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib /usr/ccs/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='-fPIC', lddlflags='-G -L/usr/local/lib'

Characteristics of this binary (from libperl)​:
  Built under solaris
  Compiled at Apr 4 1999 16​:29​:37
  @​INC​:
  /usr/local/pdperl/lib/5.00503/sun4-solaris
  /usr/local/pdperl/lib/5.00503
  /usr/local/pdperl/lib/site_perl/5.005/sun4-solaris
  /usr/local/pdperl/lib/site_perl/5.005
  .

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 1999

From [Unknown Contact. See original ticket]

I was a little quick on the h2ph as possible solution as I ran it and was
still able to generate the error. However, the following does not generate
the error;

use Sys​::Hostname;
$host = hostname;
print "$host\n";
system("/bin/date");

and produces the output as expected.

use Sys​::Hostname ();
BEGIN { $hn = Sys​::Hostname​::hostname(); }
BEGIN { $^W=1; } # or perl -w
print "$hn\n";
system("/bin/date");

is the original example.

Now, if I change the original snippet to

#!/usr/local/bin/perl -w

use Sys​::Hostname ();
$hn = Sys​::Hostname​::hostname();
print "$hn\n";
system("/bin/date");

it works without the warning.

as does

#!/usr/local/bin/perl -w

use Sys​::Hostname();
BEGIN { $hn = Sys​::Hostname​::hostname();
  print "$hn\n";
  system("/bin/date");
  }

This strikes me as odd, but I imagine I'm missing something here.

e.

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 1999

From @tamias

On Wed, Oct 06, 1999 at 10​:57​:24AM -0500, Elaine -HFB- Ashton wrote​:

I was a little quick on the h2ph as possible solution as I ran it and was
still able to generate the error. However, the following does not generate
the error;

use Sys​::Hostname;
$host = hostname;
print "$host\n";
system("/bin/date");

and produces the output as expected.

use Sys​::Hostname ();
BEGIN { $hn = Sys​::Hostname​::hostname(); }
BEGIN { $^W=1; } # or perl -w
print "$hn\n";
system("/bin/date");

is the original example.

Now, if I change the original snippet to

#!/usr/local/bin/perl -w

use Sys​::Hostname ();
$hn = Sys​::Hostname​::hostname();
print "$hn\n";
system("/bin/date");

it works without the warning.

as does

#!/usr/local/bin/perl -w

use Sys​::Hostname();
BEGIN { $hn = Sys​::Hostname​::hostname();
print "$hn\n";
system("/bin/date");
}

This strikes me as odd, but I imagine I'm missing something here.

Sys​::Hostname​::hostname() requires syscall.ph. If syscall.ph is required
at compile-time with respect to the system() expression, as in the original
example, you have ambiguity. In the latter two examples above, syscall.ph
is required at run-time with respect to the system() expression.

(If syscall.ph doesn't work, it tries requiring sys/syscall.ph and
sys/sysinfo.ph. According to the comments, this is needed on systems like
Solaris.)

Ronald

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 1999

From @jimav

Elaine -HFB- Ashton <elaine@​chaos.wustl.edu> wrote​:
] I was a little quick on the h2ph as possible solution as I ran it and was
] still able to generate the error. However, the following does not generate
] the error;
]
] use Sys​::Hostname;
] $host = hostname;
] print "$host\n";
] system("/bin/date");

That's because &hostname is no longer called before the system("...") line
is compiled, as was the case when &hostname was called inside BEGIN {...}
or in another module which is use'd by the main module.

When hostname() is called it executes `` require "syscall.ph" '' in
package main; syscall.ph then require's "_h2ph_pre.ph", which defines
sub system() because 'system' is in Config{ccsymbols}.

--> h2ph "caused" the problem by creating a sub definition with the
  same name as a CORE function.

If the 'system' #define is never actually used then it can simply
be eliminated (not generated in_h2ph_pre.ph). The below patch does
this.

However, if it *is* ever needed, then it (and any other conflicting
symbols) could be put in a special H2ph package, and all references changed
to qualified references (e.g., H2ph​::system) in code extracted from the .h
files. You would not want to put all symbols in a special package,
because programs want to refer to constants in .h files with unqualified
names.

-Jim

P.S. This patch makes h2ph (5.005_03) omit functions from _h2ph_pre.ph
which have the same name as a Perl opcode.
This fixes the problem with 'system' being overloaded on Solaris 2.6.

*** h2ph Tue Oct 5 15​:33​:04 1999
--- h2ph.new Wed Oct 6 15​:14​:12 1999
***************
*** 6,11 ****
--- 6,17 ----
  use File​::Path qw(mkpath);
  use Getopt​::Std;
 
+ my %reserved_word;
+ use Opcode ();
+ BEGIN {
+ %reserved_word = map {($_,1)} Opcode​::opset_to_ops(Opcode​::full_opset);
+ }
+
  getopts('Dd​:rlhaQ');
  die "-r and -a options are mutually exclusive\n" if ($opt_r and $opt_a);
  @​inc_dirs = inc_dirs() if $opt_a;
***************
*** 494,500 ****
  sub build_preamble_if_necessary
  {
  # Increment $VERSION every time this function is modified​:
! my $VERSION = 1;
  my $preamble = "$Dest_dir/_h2ph_pre.ph";
 
  # Can we skip building the preamble file?
--- 500,506 ----
  sub build_preamble_if_necessary
  {
  # Increment $VERSION every time this function is modified​:
! my $VERSION = 2;
  my $preamble = "$Dest_dir/_h2ph_pre.ph";
 
  # Can we skip building the preamble file?
***************
*** 519,524 ****
--- 525,532 ----
  print PREAMBLE "# $_=$define{$_}\n";
  }
 
+ next if $reserved_word{$_};
+
  if ($define{$_} =~ /^\d+$/) {
  print PREAMBLE
  "unless (defined &$_) { sub $_() { $define{$_} } }\n\n";

@p5pRT
Copy link
Author

p5pRT commented Oct 7, 1999

From @gsar

On Wed, 06 Oct 1999 15​:22​:41 PDT, Jim Avera wrote​:

--> h2ph "caused" the problem by creating a sub definition with the
same name as a CORE function.

If the 'system' #define is never actually used then it can simply
be eliminated (not generated in_h2ph_pre.ph).

We don't know that for all keywords. But I guess removing them
doesn't hurt because they're useless as they are anyway.

                                          The below patch does

this.

However, if it *is* ever needed, then it (and any other conflicting
symbols) could be put in a special H2ph package, and all references changed
to qualified references (e.g., H2ph​::system) in code extracted from the .h
files. You would not want to put all symbols in a special package,
because programs want to refer to constants in .h files with unqualified
names.

-Jim

P.S. This patch makes h2ph (5.005_03) omit functions from _h2ph_pre.ph
which have the same name as a Perl opcode.
This fixes the problem with 'system' being overloaded on Solaris 2.6.

I think the better approach would be to rework h2ph to emit *.pm
files that can (selectively) @​EXPORT_OK their constants.

*** h2ph Tue Oct 5 15​:33​:04 1999
--- h2ph.new Wed Oct 6 15​:14​:12 1999
***************
*** 6,11 ****
--- 6,17 ----
use File​::Path qw(mkpath);
use Getopt​::Std;

+ my %reserved_word;
+ use Opcode ();
+ BEGIN {
+ %reserved_word = map {($_,1)} Opcode​::opset_to_ops(Opcode​::full_opset);

This won't do the correct thing. It reflects the names of the pp_*
functions, not Perl keywords. (gethostbyname() vs pp_ghbyname(),
for example.)

Sarathy
gsar@​activestate.com

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